X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fpublishservice%2Fpublishservice_test.go;h=69ca77e47875aaa3d45163a6735c990c8a055ae7;hb=HEAD;hp=670f273eb13d1af1edadd6a04eeaa572a771ed94;hpb=d17ee019461493f52df06074ce95a6cb951ffdc4;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/publishservice/publishservice_test.go b/capifcore/internal/publishservice/publishservice_test.go index 670f273..69ca77e 100644 --- a/capifcore/internal/publishservice/publishservice_test.go +++ b/capifcore/internal/publishservice/publishservice_test.go @@ -68,7 +68,6 @@ func TestUnregisteredService(t *testing.T) { assert.Equal(t, http.StatusNotFound, *resultError.Status) } - func TestPublishUnpublishService(t *testing.T) { apfId := "apfId" @@ -259,6 +258,76 @@ func TestGetPublishedServices(t *testing.T) { assert.Len(t, result, 2) } +func TestGetAllowedServices(t *testing.T) { + serviceUnderTest := NewPublishService(nil, nil, nil) + + aefProfiles1 := []publishapi.AefProfile{} + apiName1 := "api Name 1" + aefProfiles2 := []publishapi.AefProfile{} + apiName2 := "api Name 2" + aefProfiles3 := []publishapi.AefProfile{} + apiName3 := "api Name 3" + aefProfiles4 := []publishapi.AefProfile{} + apiName4 := "api Name 4" + + serviceUnderTest.publishedServices["publisher1"] = []publishapi.ServiceAPIDescription{ + { + ApiName: apiName1, + AefProfiles: &aefProfiles1, + }, + { + ApiName: apiName2, + AefProfiles: &aefProfiles2, + }, + { + ApiName: apiName3, + AefProfiles: &aefProfiles3, + }, + { + ApiName: apiName4, + AefProfiles: &aefProfiles4, + }, + } + + serviceDescription := publishapi.ServiceAPIDescription{ + ApiName: apiName4, + AefProfiles: &aefProfiles4, + } + serviceUnderTest.publishedServices["publisher2"] = []publishapi.ServiceAPIDescription{ + serviceDescription, + } + + allowedApiList := []publishapi.ServiceAPIDescription{ + { + ApiName: apiName2, + AefProfiles: &aefProfiles2, + }, + { + ApiName: apiName3, + AefProfiles: &aefProfiles3, + }, + } + + result := serviceUnderTest.GetAllowedPublishedServices(allowedApiList) + assert.Len(t, result, 2) + + result = serviceUnderTest.GetAllowedPublishedServices(nil) + assert.Len(t, result, 0) + + result = serviceUnderTest.GetAllowedPublishedServices([]publishapi.ServiceAPIDescription{}) + assert.Len(t, result, 0) + + // Create a list with no ApiNames + badApiList := []publishapi.ServiceAPIDescription{ + { + }, + { + }, + } + result = serviceUnderTest.GetAllowedPublishedServices(badApiList) + assert.Len(t, result, 0) +} + func TestUpdateDescription(t *testing.T) { apfId := "apfId" serviceApiId := "serviceApiId"