X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Fpublishservice%2Fpublishservice_test.go;h=b69b956ec5bff990a6f283afedadb723c92b637e;hb=refs%2Fchanges%2F98%2F10398%2F4;hp=8b35f55ea5a326e91cb096ba57760cfb078854d2;hpb=6245ef94c3d8d2b016b8c47881dae2fcccbf054a;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/publishservice/publishservice_test.go b/capifcore/internal/publishservice/publishservice_test.go index 8b35f55..b69b956 100644 --- a/capifcore/internal/publishservice/publishservice_test.go +++ b/capifcore/internal/publishservice/publishservice_test.go @@ -77,11 +77,9 @@ func TestPublishUnpublishService(t *testing.T) { err := result.UnmarshalBodyToObject(&resultService) assert.NoError(t, err, "error unmarshaling response") newApiId := "api_id_" + apiName - assert.Equal(t, *resultService.ApiId, newApiId) + assert.Equal(t, newApiId, *resultService.ApiId) assert.Equal(t, "http://example.com/"+apfId+"/service-apis/"+*resultService.ApiId, result.Recorder.Header().Get(echo.HeaderLocation)) newServiceDescription.ApiId = &newApiId - wantedAPILIst := []publishapi.ServiceAPIDescription{newServiceDescription} - assert.True(t, serviceUnderTest.AreAPIsPublished(&wantedAPILIst)) assert.True(t, serviceUnderTest.IsAPIPublished(aefId, apiName)) serviceRegisterMock.AssertCalled(t, "GetAefsForPublisher", apfId) helmManagerMock.AssertCalled(t, "InstallHelmChart", namespace, repoName, chartName, releaseName) @@ -101,6 +99,16 @@ func TestPublishUnpublishService(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") assert.Equal(t, *resultService.ApiId, newApiId) + // Publish the same service again should result in Forbidden + result = testutil.NewRequest().Post("/"+apfId+"/service-apis").WithJsonBody(newServiceDescription).Go(t, requestHandler) + + assert.Equal(t, http.StatusForbidden, result.Code()) + var resultError common29122.ProblemDetails + err = result.UnmarshalBodyToObject(&resultError) + assert.NoError(t, err, "error unmarshaling response") + assert.Contains(t, *resultError.Cause, "already published") + assert.Equal(t, http.StatusForbidden, *resultError.Status) + // Delete the service helmManagerMock.On("UninstallHelmChart", mock.Anything, mock.Anything).Return(nil) @@ -141,8 +149,7 @@ func TestPostUnpublishedServiceWithUnregisteredFunction(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") assert.Contains(t, *resultError.Cause, aefId) assert.Contains(t, *resultError.Cause, "not registered") - notFound := http.StatusNotFound - assert.Equal(t, ¬Found, resultError.Status) + assert.Equal(t, http.StatusNotFound, *resultError.Status) } func TestGetServices(t *testing.T) { @@ -357,6 +364,23 @@ func TestUpdateValidServiceWithDeletedFunction(t *testing.T) { assert.Len(t, (*resultService.AefProfiles), 1) assert.False(t, serviceUnderTest.IsAPIPublished("aefId", "path")) +} + +func TestPublishInvalidService(t *testing.T) { + _, _, requestHandler := getEcho(nil, nil) + newServiceDescription := getServiceAPIDescription("aefId", " ", "description") + + // Publish a service + result := testutil.NewRequest().Post("/apfId/service-apis").WithJsonBody(newServiceDescription).Go(t, requestHandler) + + assert.Equal(t, http.StatusBadRequest, result.Code()) + var resultError common29122.ProblemDetails + err := result.UnmarshalBodyToObject(&resultError) + assert.NoError(t, err, "error unmarshaling response") + assert.Contains(t, *resultError.Cause, "missing") + assert.Contains(t, *resultError.Cause, "apiName") + assert.Equal(t, http.StatusBadRequest, *resultError.Status) + } func getEcho(serviceRegister providermanagement.ServiceRegister, helmManager helmmanagement.HelmManager) (*PublishService, chan eventsapi.EventNotification, *echo.Echo) { swagger, err := publishapi.GetSwagger()