X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fpublishservice%2Fpublishservice_test.go;h=7bb0152b0d8d133d45f1694155dc804b551e0a55;hb=f2b14d0af529fdb4a2258d025593f1f805c4e4ca;hp=9bb02b64c156c3d2d6bd395308cb565d2710ba0a;hpb=de80bd1d75e2f9c410a0c626e4d03fa250fcb183;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/publishservice/publishservice_test.go b/capifcore/internal/publishservice/publishservice_test.go index 9bb02b6..7bb0152 100644 --- a/capifcore/internal/publishservice/publishservice_test.go +++ b/capifcore/internal/publishservice/publishservice_test.go @@ -162,6 +162,54 @@ func TestGetServices(t *testing.T) { assert.Contains(t, resultServices, serviceDescription2) } +func TestGetPublishedServices(t *testing.T) { + serviceUnderTest := NewPublishService(nil, nil) + + profiles := make([]publishapi.AefProfile, 1) + serviceDescription := publishapi.ServiceAPIDescription{ + AefProfiles: &profiles, + } + serviceUnderTest.publishedServices["publisher1"] = []publishapi.ServiceAPIDescription{ + serviceDescription, + } + serviceUnderTest.publishedServices["publisher2"] = []publishapi.ServiceAPIDescription{ + serviceDescription, + } + result := serviceUnderTest.GetAllPublishedServices() + assert.Len(t, result, 2) +} + +func TestUpdateDescription(t *testing.T) { + apfId := "apfId" + serviceApiId := "serviceApiId" + aefId := "aefId" + apiName := "apiName" + description := "description" + serviceRegisterMock := serviceMocks.ServiceRegister{} + serviceRegisterMock.On("GetAefsForPublisher", apfId).Return([]string{aefId, "otherAefId"}) + helmManagerMock := helmMocks.HelmManager{} + helmManagerMock.On("InstallHelmChart", mock.Anything, mock.Anything, mock.Anything, mock.Anything).Return(nil) + serviceUnderTest, requestHandler := getEcho(&serviceRegisterMock, &helmManagerMock) + + serviceDescription := getServiceAPIDescription(aefId, apiName, description) + serviceDescription.ApiId = &serviceApiId + serviceUnderTest.publishedServices[apfId] = []publishapi.ServiceAPIDescription{serviceDescription} + + //Modify the service + updatedServiceDescription := getServiceAPIDescription(aefId, apiName, description) + updatedServiceDescription.ApiId = &description + newDescription := "new description" + updatedServiceDescription.Description = &newDescription + result := testutil.NewRequest().Put("/"+apfId+"/service-apis/"+serviceApiId).WithJsonBody(updatedServiceDescription).Go(t, requestHandler) + + var resultService publishapi.ServiceAPIDescription + assert.Equal(t, http.StatusOK, result.Code()) + err := result.UnmarshalBodyToObject(&resultService) + assert.NoError(t, err, "error unmarshaling response") + assert.Equal(t, resultService.Description, &newDescription) + +} + func getEcho(serviceRegister providermanagement.ServiceRegister, helmManager helmmanagement.HelmManager) (*PublishService, *echo.Echo) { swagger, err := publishapi.GetSwagger() if err != nil {