From: DenisGNoonan Date: Tue, 5 Mar 2024 09:51:04 +0000 (+0000) Subject: NONRTRIC-946: Capifcore - join on ApiName X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=commitdiff_plain;h=8ff4d0377ccd9b3c10bc9fb247b7136bba3eb6d7;p=nonrtric%2Fplt%2Fsme.git NONRTRIC-946: Capifcore - join on ApiName Change-Id: I6d88a3f279109f90a47143dd14f3687446b6676d Signed-off-by: DenisGNoonan --- diff --git a/capifcore/internal/publishservice/publishservice.go b/capifcore/internal/publishservice/publishservice.go index 670d2ed..09c4ef7 100644 --- a/capifcore/internal/publishservice/publishservice.go +++ b/capifcore/internal/publishservice/publishservice.go @@ -97,11 +97,11 @@ func (ps *PublishService) GetAllPublishedServices() []publishapi.ServiceAPIDescr func (ps *PublishService) GetAllowedPublishedServices(apiListRequestedServices []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription { apiListAllPublished := ps.GetAllPublishedServices() - allowedPublishedServices := intersection(apiListAllPublished, apiListRequestedServices) + allowedPublishedServices := join(apiListAllPublished, apiListRequestedServices) return allowedPublishedServices } -func intersection(a, b []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription { +func join(a, b []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription { var result []publishapi.ServiceAPIDescription if (a == nil) || (b == nil) || (len(a) == 0) || (len(b) == 0) { @@ -110,7 +110,7 @@ func intersection(a, b []publishapi.ServiceAPIDescription) []publishapi.ServiceA for _, itemA := range a { for _, itemB := range b { - if (itemA.ApiId != nil) && (itemB.ApiId != nil) && (*itemA.ApiId == *itemB.ApiId) { + if itemA.ApiName == itemB.ApiName { result = append(result, itemA) break } diff --git a/capifcore/internal/publishservice/publishservice_test.go b/capifcore/internal/publishservice/publishservice_test.go index 3f1a71f..69ca77e 100644 --- a/capifcore/internal/publishservice/publishservice_test.go +++ b/capifcore/internal/publishservice/publishservice_test.go @@ -262,35 +262,35 @@ func TestGetAllowedServices(t *testing.T) { serviceUnderTest := NewPublishService(nil, nil, nil) aefProfiles1 := []publishapi.AefProfile{} - apiId1 := "apiId1" + apiName1 := "api Name 1" aefProfiles2 := []publishapi.AefProfile{} - apiId2 := "apiId2" + apiName2 := "api Name 2" aefProfiles3 := []publishapi.AefProfile{} - apiId3 := "apiId3" + apiName3 := "api Name 3" aefProfiles4 := []publishapi.AefProfile{} - apiId4 := "apiId4" + apiName4 := "api Name 4" serviceUnderTest.publishedServices["publisher1"] = []publishapi.ServiceAPIDescription{ { - ApiId: &apiId1, + ApiName: apiName1, AefProfiles: &aefProfiles1, }, { - ApiId: &apiId2, + ApiName: apiName2, AefProfiles: &aefProfiles2, }, { - ApiId: &apiId3, + ApiName: apiName3, AefProfiles: &aefProfiles3, }, { - ApiId: &apiId4, + ApiName: apiName4, AefProfiles: &aefProfiles4, }, } serviceDescription := publishapi.ServiceAPIDescription{ - ApiId: &apiId4, + ApiName: apiName4, AefProfiles: &aefProfiles4, } serviceUnderTest.publishedServices["publisher2"] = []publishapi.ServiceAPIDescription{ @@ -299,11 +299,11 @@ func TestGetAllowedServices(t *testing.T) { allowedApiList := []publishapi.ServiceAPIDescription{ { - ApiId: &apiId2, + ApiName: apiName2, AefProfiles: &aefProfiles2, }, { - ApiId: &apiId3, + ApiName: apiName3, AefProfiles: &aefProfiles3, }, } @@ -317,7 +317,7 @@ func TestGetAllowedServices(t *testing.T) { result = serviceUnderTest.GetAllowedPublishedServices([]publishapi.ServiceAPIDescription{}) assert.Len(t, result, 0) - // Create a list with no ApiIds + // Create a list with no ApiNames badApiList := []publishapi.ServiceAPIDescription{ { },