X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=pkg%2Fxapp%2Fxapp_test.go;h=c4aec60664df7c7201cd1a250366e81a6ac3d3a4;hb=79f0680fd7bbf1c8a8c6e2a842cb18020e387a47;hp=43614918c6406ee4f556bcccb38dd7b146205ac7;hpb=ed11919144ea45905aef41a5062144013d0db9c0;p=ric-plt%2Fxapp-frame.git diff --git a/pkg/xapp/xapp_test.go b/pkg/xapp/xapp_test.go index 4361491..c4aec60 100755 --- a/pkg/xapp/xapp_test.go +++ b/pkg/xapp/xapp_test.go @@ -20,22 +20,24 @@ package xapp import ( - "github.com/gorilla/mux" - "github.com/spf13/viper" + "bytes" + "io/ioutil" "net/http" "net/http/httptest" - "github.com/stretchr/testify/assert" "os" "strings" "testing" "time" - "bytes" + + "github.com/gorilla/mux" + "github.com/spf13/viper" + "github.com/stretchr/testify/assert" ) -//var _ = func() bool { -// testing.Init() -// return true -//}() +var _ = func() bool { + testing.Init() + return true +}() type Consumer struct{} @@ -46,6 +48,8 @@ func (m Consumer) Consume(params *RMRParams) (err error) { // Test cases func TestMain(m *testing.M) { + os.Setenv("SERVICE_RICXAPP_UEEC_HTTP_PORT", "tcp://localhost:8080") + os.Setenv("SERVICE_RICXAPP_UEEC_RMR_PORT", "tcp://localhost:4561") go RunWithParams(Consumer{}, viper.GetBool("controls.waitForSdl")) time.Sleep(time.Duration(5) * time.Second) code := m.Run() @@ -118,8 +122,8 @@ func TestMessagesReceivedSuccessfully(t *testing.T) { params.Payload = []byte{1, 2, 3, 4, 5, 6} params.Meid = &RMRMeid{PlmnID: "1234", EnbID: "7788", RanName: "RanName-1234"} params.Xid = "TestXID" - - if i % 2 == 0 { + + if i%2 == 0 { Rmr.SendMsg(params) } else { Rmr.SendWithRetry(params, false, 1) @@ -331,20 +335,22 @@ func TestAddConfigChangeListener(t *testing.T) { } func TestConfigAccess(t *testing.T) { - Logger.Info("CASE: AddConfigChangeListener") - - assert.Equal(t, Config.GetString("name"), "xapp") - assert.Equal(t, Config.GetInt("controls.logger.level"), 3) - assert.Equal(t, Config.GetUint32("controls.logger.level"), uint32(3)) - assert.Equal(t, Config.GetBool("controls.waitForSdl"), false) + Logger.Info("CASE: TestConfigAccess") + + assert.Equal(t, Config.GetString("name"), "xapp") + assert.Equal(t, Config.GetInt("controls.logger.level"), 3) + assert.Equal(t, Config.GetUint32("controls.logger.level"), uint32(3)) + assert.Equal(t, Config.GetBool("controls.waitForSdl"), false) Config.Get("controls") Config.GetStringSlice("messaging.ports") Config.GetStringMap("messaging.ports") + Config.IsSet("messaging") } func TestPublishConfigChange(t *testing.T) { - Logger.Info("CASE: AddConfigChangeListener") + Logger.Info("CASE: TestPublishConfigChange") PublishConfigChange("testApp", "values") + ReadConfig("testApp") } func TestNewSubscriber(t *testing.T) { @@ -353,7 +359,7 @@ func TestNewSubscriber(t *testing.T) { } func TestNewRMRClient(t *testing.T) { - c := map[string]interface{} {"protPort": "tcp:4560"} + c := map[string]interface{}{"protPort": "tcp:4560"} viper.Set("rmr", c) assert.NotNil(t, NewRMRClient(), "NewRMRClient failed") @@ -376,6 +382,7 @@ func TestInjectStatusCb(t *testing.T) { return true } Resource.InjectStatusCb(f) + Resource.CheckStatus() } func TestSdlInterfaces(t *testing.T) { @@ -385,11 +392,13 @@ func TestSdlInterfaces(t *testing.T) { Sdl.Store("myKey", "Values") Sdl.MStore("myKey", "Values") Sdl.RegisterMetrics() + Sdl.UpdateStatCounter("Stored") // Misc. var NotificationCb = func(ch string, events ...string) {} Sdl.Subscribe(NotificationCb, "channel1") Sdl.MSubscribe(NotificationCb, "channel1", "channel2") + Sdl.StoreAndPublish("channel1", "event", "key1", "data1") Sdl.MStoreAndPublish([]string{"channel1"}, "event", "key1", "data1") } @@ -412,6 +421,7 @@ func TestRnibInterfaces(t *testing.T) { func TestLogger(t *testing.T) { Logger.Error("CASE: TestNewSubscriber") Logger.Warn("CASE: TestNewSubscriber") + Logger.GetLevel() } func TestConfigHandler(t *testing.T) { @@ -421,13 +431,53 @@ func TestConfigHandler(t *testing.T) { executeRequest(req, handleFunc) } +func TestappconfigHandler(t *testing.T) { + Logger.Error("CASE: TestappconfigHandler") + req, _ := http.NewRequest("POST", "/ric/v1/config", bytes.NewBuffer([]byte{})) + handleFunc := http.HandlerFunc(appconfigHandler) + executeRequest(req, handleFunc) +} + +func TestConfigChange(t *testing.T) { + Logger.Error("CASE: TestConfigChange: %s", os.Getenv("CFG_FILE")) + + input, err := ioutil.ReadFile(os.Getenv("CFG_FILE")) + assert.Equal(t, err, nil) + + err = ioutil.WriteFile(os.Getenv("CFG_FILE"), input, 0644) + assert.Equal(t, err, nil) +} + +func TestRegisterXapp(t *testing.T) { + Logger.Error("CASE: TestRegisterXapp") + doRegister() +} + +func TestDeregisterXapp(t *testing.T) { + Logger.Error("CASE: TestDeregisterXapp") + doDeregister() +} + func TestMisc(t *testing.T) { Logger.Info("CASE: TestMisc") - + var cb = func() {} IsReady() SetReadyCB(func(interface{}) {}, "") XappReadyCb("") - SetShutdownCB(func() {}) + SetShutdownCB(cb) + XappShutdownCb() + getService("ueec", SERVICE_HTTP) + + Logger.SetFormat(1) + Logger.SetLevel(0) + Logger.Error("...") + Logger.Warn("...") + Logger.Info("...") + + mb := Rmr.Allocate(100) + Rmr.ReAllocate(mb, 200) + + NewMetrics("", "", Resource.router) } func TestTeardown(t *testing.T) { @@ -436,6 +486,10 @@ func TestTeardown(t *testing.T) { Sdl.Clear() Sdl.IsReady() Sdl.GetStat() + Rnib.GetNodebByGlobalNbId(1, &RNIBGlobalNbId{}) + Rnib.SaveNodeb(&RNIBNbIdentity{}, &RNIBNodebInfo{}) + go Sdl.TestConnection() + time.Sleep(time.Duration(2) * time.Second) } // Helper functions