Change-Id: I6d88a3f279109f90a47143dd14f3687446b6676d
Signed-off-by: DenisGNoonan <denis.noonan@est.tech>
func (ps *PublishService) GetAllowedPublishedServices(apiListRequestedServices []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription {
apiListAllPublished := ps.GetAllPublishedServices()
func (ps *PublishService) GetAllowedPublishedServices(apiListRequestedServices []publishapi.ServiceAPIDescription) []publishapi.ServiceAPIDescription {
apiListAllPublished := ps.GetAllPublishedServices()
- allowedPublishedServices := intersection(apiListAllPublished, apiListRequestedServices)
+ allowedPublishedServices := join(apiListAllPublished, apiListRequestedServices)
return allowedPublishedServices
}
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) {
var result []publishapi.ServiceAPIDescription
if (a == nil) || (b == nil) || (len(a) == 0) || (len(b) == 0) {
for _, itemA := range a {
for _, itemB := range b {
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
}
result = append(result, itemA)
break
}
serviceUnderTest := NewPublishService(nil, nil, nil)
aefProfiles1 := []publishapi.AefProfile{}
serviceUnderTest := NewPublishService(nil, nil, nil)
aefProfiles1 := []publishapi.AefProfile{}
+ apiName1 := "api Name 1"
aefProfiles2 := []publishapi.AefProfile{}
aefProfiles2 := []publishapi.AefProfile{}
+ apiName2 := "api Name 2"
aefProfiles3 := []publishapi.AefProfile{}
aefProfiles3 := []publishapi.AefProfile{}
+ apiName3 := "api Name 3"
aefProfiles4 := []publishapi.AefProfile{}
aefProfiles4 := []publishapi.AefProfile{}
+ apiName4 := "api Name 4"
serviceUnderTest.publishedServices["publisher1"] = []publishapi.ServiceAPIDescription{
{
serviceUnderTest.publishedServices["publisher1"] = []publishapi.ServiceAPIDescription{
{
AefProfiles: &aefProfiles1,
},
{
AefProfiles: &aefProfiles1,
},
{
AefProfiles: &aefProfiles2,
},
{
AefProfiles: &aefProfiles2,
},
{
AefProfiles: &aefProfiles3,
},
{
AefProfiles: &aefProfiles3,
},
{
AefProfiles: &aefProfiles4,
},
}
serviceDescription := publishapi.ServiceAPIDescription{
AefProfiles: &aefProfiles4,
},
}
serviceDescription := publishapi.ServiceAPIDescription{
AefProfiles: &aefProfiles4,
}
serviceUnderTest.publishedServices["publisher2"] = []publishapi.ServiceAPIDescription{
AefProfiles: &aefProfiles4,
}
serviceUnderTest.publishedServices["publisher2"] = []publishapi.ServiceAPIDescription{
allowedApiList := []publishapi.ServiceAPIDescription{
{
allowedApiList := []publishapi.ServiceAPIDescription{
{
AefProfiles: &aefProfiles2,
},
{
AefProfiles: &aefProfiles2,
},
{
AefProfiles: &aefProfiles3,
},
}
AefProfiles: &aefProfiles3,
},
}
result = serviceUnderTest.GetAllowedPublishedServices([]publishapi.ServiceAPIDescription{})
assert.Len(t, result, 0)
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{
{
},
badApiList := []publishapi.ServiceAPIDescription{
{
},