X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fxapp%2Fxapp_test.go;h=2c4c4fea9b0040c6ef02f1f2a2cd1f459ebcb438;hb=refs%2Fchanges%2F40%2F6340%2F1;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..2c4c4fe 100755 --- a/pkg/xapp/xapp_test.go +++ b/pkg/xapp/xapp_test.go @@ -20,16 +20,17 @@ package xapp import ( - "github.com/gorilla/mux" - "github.com/spf13/viper" + "bytes" "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 { @@ -46,6 +47,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 +121,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) @@ -332,14 +335,15 @@ 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) + + 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) { @@ -353,7 +357,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 +380,7 @@ func TestInjectStatusCb(t *testing.T) { return true } Resource.InjectStatusCb(f) + Resource.CheckStatus() } func TestSdlInterfaces(t *testing.T) { @@ -412,6 +417,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 +427,43 @@ 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 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 +472,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