X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Finternal%2Finvokermanagement%2Finvokermanagement_test.go;h=365a7d0d7c2905b2b82e5b52d29824f43e104570;hb=b4da1f981ba6717f5ec52e15ad1db257b5d6b7f3;hp=4aae429ad9425556e16e94f71ac35125c1dea1ad;hpb=a3a54cad38108ae4f753eae6bc90ca1357defe4f;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/internal/invokermanagement/invokermanagement_test.go b/capifcore/internal/invokermanagement/invokermanagement_test.go index 4aae429..365a7d0 100644 --- a/capifcore/internal/invokermanagement/invokermanagement_test.go +++ b/capifcore/internal/invokermanagement/invokermanagement_test.go @@ -24,6 +24,7 @@ import ( "net/http" "os" "path" + "strings" "testing" "oransc.org/nonrtric/capifcore/internal/invokermanagementapi" @@ -44,9 +45,9 @@ import ( ) func TestOnboardInvoker(t *testing.T) { - apiRegisterMock := publishmocks.APIRegister{} - apiRegisterMock.On("AreAPIsRegistered", mock.Anything).Return(true) - invokerUnderTest, requestHandler := getEcho(&apiRegisterMock) + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("AreAPIsPublished", mock.Anything).Return(true) + invokerUnderTest, requestHandler := getEcho(&publishRegisterMock) aefProfiles := []publishserviceapi.AefProfile{ getAefProfile("aefId"), @@ -58,7 +59,8 @@ func TestOnboardInvoker(t *testing.T) { AefProfiles: &aefProfiles, }, } - newInvoker := getInvoker("invoker a", apiList) + invokerInfo := "invoker a" + newInvoker := getInvoker(invokerInfo, apiList) // Onboard a valid invoker result := testutil.NewRequest().Post("/onboardedInvokers").WithJsonBody(newInvoker).Go(t, requestHandler) @@ -67,14 +69,16 @@ func TestOnboardInvoker(t *testing.T) { var resultInvoker invokermanagementapi.APIInvokerEnrolmentDetails err := result.UnmarshalBodyToObject(&resultInvoker) assert.NoError(t, err, "error unmarshaling response") - assert.Equal(t, "api_invoker_id_invoker_a", *resultInvoker.ApiInvokerId) + wantedInvokerId := "api_invoker_id_" + strings.Replace(invokerInfo, " ", "_", 1) + assert.Equal(t, wantedInvokerId, *resultInvoker.ApiInvokerId) assert.Equal(t, newInvoker.NotificationDestination, resultInvoker.NotificationDestination) assert.Equal(t, newInvoker.OnboardingInformation.ApiInvokerPublicKey, resultInvoker.OnboardingInformation.ApiInvokerPublicKey) - assert.Equal(t, "onboarding_secret_invoker_a", *resultInvoker.OnboardingInformation.OnboardingSecret) + wantedInvokerSecret := "onboarding_secret_" + strings.Replace(invokerInfo, " ", "_", 1) + assert.Equal(t, wantedInvokerSecret, *resultInvoker.OnboardingInformation.OnboardingSecret) assert.Equal(t, "http://example.com/onboardedInvokers/"+*resultInvoker.ApiInvokerId, result.Recorder.Header().Get(echo.HeaderLocation)) - assert.True(t, invokerUnderTest.IsInvokerRegistered("api_invoker_id_invoker_a")) - assert.True(t, invokerUnderTest.VerifyInvokerSecret("api_invoker_id_invoker_a", "onboarding_secret_invoker_a")) - apiRegisterMock.AssertCalled(t, "AreAPIsRegistered", mock.Anything) + assert.True(t, invokerUnderTest.IsInvokerRegistered(wantedInvokerId)) + assert.True(t, invokerUnderTest.VerifyInvokerSecret(wantedInvokerId, wantedInvokerSecret)) + publishRegisterMock.AssertCalled(t, "AreAPIsPublished", mock.Anything) // Onboard an invoker missing required NotificationDestination, should get 400 with problem details invalidInvoker := invokermanagementapi.APIInvokerEnrolmentDetails{ @@ -90,8 +94,8 @@ func TestOnboardInvoker(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") badRequest := http.StatusBadRequest assert.Equal(t, &badRequest, problemDetails.Status) - errMsg := "Invoker missing required NotificationDestination" - assert.Equal(t, &errMsg, problemDetails.Cause) + assert.Contains(t, *problemDetails.Cause, "missing") + assert.Contains(t, *problemDetails.Cause, "NotificationDestination") // Onboard an invoker missing required OnboardingInformation.ApiInvokerPublicKey, should get 400 with problem details invalidInvoker = invokermanagementapi.APIInvokerEnrolmentDetails{ @@ -104,8 +108,8 @@ func TestOnboardInvoker(t *testing.T) { err = result.UnmarshalBodyToObject(&problemDetails) assert.NoError(t, err, "error unmarshaling response") assert.Equal(t, &badRequest, problemDetails.Status) - errMsg = "Invoker missing required OnboardingInformation.ApiInvokerPublicKey" - assert.Equal(t, &errMsg, problemDetails.Cause) + assert.Contains(t, *problemDetails.Cause, "missing") + assert.Contains(t, *problemDetails.Cause, "OnboardingInformation.ApiInvokerPublicKey") } func TestDeleteInvoker(t *testing.T) { @@ -175,8 +179,8 @@ func TestUpdateInvoker(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") badRequest := http.StatusBadRequest assert.Equal(t, &badRequest, problemDetails.Status) - errMsg := "Invoker missing required NotificationDestination" - assert.Equal(t, &errMsg, problemDetails.Cause) + assert.Contains(t, *problemDetails.Cause, "missing") + assert.Contains(t, *problemDetails.Cause, "NotificationDestination") // Update with an invoker missing required OnboardingInformation.ApiInvokerPublicKey, should get 400 with problem details invalidInvoker.NotificationDestination = "url" @@ -187,8 +191,8 @@ func TestUpdateInvoker(t *testing.T) { err = result.UnmarshalBodyToObject(&problemDetails) assert.NoError(t, err, "error unmarshaling response") assert.Equal(t, &badRequest, problemDetails.Status) - errMsg = "Invoker missing required OnboardingInformation.ApiInvokerPublicKey" - assert.Equal(t, &errMsg, problemDetails.Cause) + assert.Contains(t, *problemDetails.Cause, "missing") + assert.Contains(t, *problemDetails.Cause, "OnboardingInformation.ApiInvokerPublicKey") // Update with an invoker with other ApiInvokerId than the one provided in the URL, should get 400 with problem details invalidId := "1" @@ -200,8 +204,8 @@ func TestUpdateInvoker(t *testing.T) { err = result.UnmarshalBodyToObject(&problemDetails) assert.NoError(t, err, "error unmarshaling response") assert.Equal(t, &badRequest, problemDetails.Status) - errMsg = "Invoker ApiInvokerId not matching" - assert.Equal(t, &errMsg, problemDetails.Cause) + assert.Contains(t, *problemDetails.Cause, "not matching") + assert.Contains(t, *problemDetails.Cause, "ApiInvokerId") // Update an invoker that has not been onboarded, shold get 404 with problem details missingId := "1" @@ -213,14 +217,14 @@ func TestUpdateInvoker(t *testing.T) { assert.NoError(t, err, "error unmarshaling response") notFound := http.StatusNotFound assert.Equal(t, ¬Found, problemDetails.Status) - errMsg = "The invoker to update has not been onboarded" - assert.Equal(t, &errMsg, problemDetails.Cause) + assert.Contains(t, *problemDetails.Cause, "not been onboarded") + assert.Contains(t, *problemDetails.Cause, "invoker") } func TestGetInvokerApiList(t *testing.T) { - apiRegisterMock := publishmocks.APIRegister{} - apiRegisterMock.On("AreAPIsRegistered", mock.Anything).Return(true) - invokerUnderTest, requestHandler := getEcho(&apiRegisterMock) + publishRegisterMock := publishmocks.PublishRegister{} + publishRegisterMock.On("AreAPIsPublished", mock.Anything).Return(true) + invokerUnderTest, requestHandler := getEcho(&publishRegisterMock) // Onboard two invokers aefProfiles := []publishserviceapi.AefProfile{ @@ -233,7 +237,8 @@ func TestGetInvokerApiList(t *testing.T) { AefProfiles: &aefProfiles, }, } - newInvoker := getInvoker("invoker a", apiList) + invokerInfo := "invoker a" + newInvoker := getInvoker(invokerInfo, apiList) testutil.NewRequest().Post("/onboardedInvokers").WithJsonBody(newInvoker).Go(t, requestHandler) aefProfiles = []publishserviceapi.AefProfile{ getAefProfile("aefId2"), @@ -248,12 +253,12 @@ func TestGetInvokerApiList(t *testing.T) { newInvoker = getInvoker("invoker b", apiList) testutil.NewRequest().Post("/onboardedInvokers").WithJsonBody(newInvoker).Go(t, requestHandler) - wantedApiList := invokerUnderTest.GetInvokerApiList("api_invoker_id_invoker_a") + wantedApiList := invokerUnderTest.GetInvokerApiList("api_invoker_id_" + strings.Replace(invokerInfo, " ", "_", 1)) assert.NotNil(t, wantedApiList) assert.Equal(t, apiId, *(*wantedApiList)[0].ApiId) } -func getEcho(apiRegister publishservice.APIRegister) (*InvokerManager, *echo.Echo) { +func getEcho(publishRegister publishservice.PublishRegister) (*InvokerManager, *echo.Echo) { swagger, err := invokermanagementapi.GetSwagger() if err != nil { fmt.Fprintf(os.Stderr, "Error loading swagger spec\n: %s", err) @@ -262,7 +267,7 @@ func getEcho(apiRegister publishservice.APIRegister) (*InvokerManager, *echo.Ech swagger.Servers = nil - im := NewInvokerManager(apiRegister) + im := NewInvokerManager(publishRegister) e := echo.New() e.Use(echomiddleware.Logger())