X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=pkg%2Fcontrol%2Fsdl_restSubsDb_test.go;h=5e1db6025b4e786e5ba9d96b6c0de2d65ec0a009;hb=483bd162c10ee2f0ef348b5c25c2987aea80b7c8;hp=12bf1eb449ae0ab2a1ce52c035890c895c547b5e;hpb=42723e2593926f1cfa144b503bf043a0fe36e657;p=ric-plt%2Fsubmgr.git diff --git a/pkg/control/sdl_restSubsDb_test.go b/pkg/control/sdl_restSubsDb_test.go index 12bf1eb..5e1db60 100644 --- a/pkg/control/sdl_restSubsDb_test.go +++ b/pkg/control/sdl_restSubsDb_test.go @@ -89,6 +89,7 @@ func CreateRESTSubscription(t *testing.T) *RESTSubscription { t.Log("TEST: Creating REST subscription") restSubscription := &RESTSubscription{} + restSubscription.xAppServiceName = "localhost" restSubscription.xAppRmrEndPoint = "localhost:13560" restSubscription.Meid = "RAN_NAME_1" restSubscription.SubReqOngoing = true @@ -100,6 +101,7 @@ func CreateRESTSubscription(t *testing.T) *RESTSubscription { func PrintRESTSubscriptionData(t *testing.T, restSubs *RESTSubscription) { t.Log("TEST: RESTSubscription data") + t.Logf("TEST: restSubs.xAppServiceName = %v", restSubs.xAppServiceName) t.Logf("TEST: restSubs.xAppRmrEndPoint = %v", restSubs.xAppRmrEndPoint) t.Logf("TEST: restSubs.Meid = %v", restSubs.Meid) t.Logf("TEST: restSubs.InstanceIds = %v", restSubs.InstanceIds) @@ -120,6 +122,17 @@ func TestWriteRESTSubscriptionToSdl(t *testing.T) { t.Errorf("TEST: %s", err.Error()) } restSubsDbMock.AddRestSubIdsInDb(restSubId) + verifyRESTKeyCount(t, 1) +} + +func verifyRESTKeyCount(t *testing.T, expectedCount int) { + + count, err := mainCtrl.c.GetRESTKeyCount() + if err != nil { + t.Errorf("TEST: %s", err.Error()) + } else { + assert.Equal(t, expectedCount, count) + } } func TestReadRESTSubscriptionFromSdl(t *testing.T) { @@ -369,13 +382,17 @@ func TestRemoveAllRESTSubscriptionsFromSdlFail(t *testing.T) { t.Log("TEST: All subscription removed from db") } -func (m *RestSubsDbMock) Set(pairs ...interface{}) error { +func (m *RestSubsDbMock) Set(ns string, pairs ...interface{}) error { var key string var val string m.marshalLock.Lock() defer m.marshalLock.Unlock() + if ns != restSubSdlNs { + return fmt.Errorf("Unexpected namespace '%s' error\n", ns) + } + if sdlRestShouldReturnError == true { return GetSdlRestError() } @@ -412,8 +429,13 @@ func (m *RestSubsDbMock) Set(pairs ...interface{}) error { return nil } -func (m *RestSubsDbMock) Get(keys []string) (map[string]interface{}, error) { +func (m *RestSubsDbMock) Get(ns string, keys []string) (map[string]interface{}, error) { retMap := make(map[string]interface{}) + + if ns != restSubSdlNs { + return nil, fmt.Errorf("Unexpected namespace '%s' error\n", ns) + } + if len(keys) == 0 { return nil, fmt.Errorf("Get() error: len(key) == 0\n") } @@ -432,7 +454,11 @@ func (m *RestSubsDbMock) Get(keys []string) (map[string]interface{}, error) { return retMap, nil } -func (m *RestSubsDbMock) GetAll() ([]string, error) { +func (m *RestSubsDbMock) GetAll(ns string) ([]string, error) { + + if ns != restSubSdlNs { + return nil, fmt.Errorf("Unexpected namespace '%s' error\n", ns) + } if sdlRestShouldReturnError == true { return nil, GetSdlRestError() @@ -445,7 +471,12 @@ func (m *RestSubsDbMock) GetAll() ([]string, error) { return keys, nil } -func (m *RestSubsDbMock) Remove(keys []string) error { +func (m *RestSubsDbMock) Remove(ns string, keys []string) error { + + if ns != restSubSdlNs { + return fmt.Errorf("Unexpected namespace '%s' error\n", ns) + } + if len(keys) == 0 { return fmt.Errorf("Remove() error: len(key) == 0\n") } @@ -460,7 +491,11 @@ func (m *RestSubsDbMock) Remove(keys []string) error { return nil } -func (m *RestSubsDbMock) RemoveAll() error { +func (m *RestSubsDbMock) RemoveAll(ns string) error { + + if ns != restSubSdlNs { + return fmt.Errorf("Unexpected namespace '%s' error\n", ns) + } for key := range m.restSubsDb {