X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Fmain_test.go;h=f3a5f1538feb086e54cc55d29b2345ddc42cb059;hb=b8e717a8c264a8b3f73626fc28c81ae65283ae80;hp=1894516a0694f32f92cc94ec65c700a68607a8f9;hpb=d0199885b0bc379f22dbb7012545f0049f979bac;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/main_test.go b/capifcore/main_test.go index 1894516..f3a5f15 100644 --- a/capifcore/main_test.go +++ b/capifcore/main_test.go @@ -25,8 +25,10 @@ import ( "testing" "github.com/deepmap/oapi-codegen/pkg/testutil" + "github.com/getkin/kin-openapi/openapi3" "github.com/labstack/echo/v4" "github.com/stretchr/testify/assert" + "oransc.org/nonrtric/capifcore/internal/common29122" ) var e *echo.Echo @@ -83,6 +85,14 @@ func Test_routing(t *testing.T) { method: "DELETE", }, }, + { + name: "Event path", + args: args{ + url: "/capif-events/v1/subscriberId/subscriptions/subId", + returnStatus: http.StatusNoContent, + method: "DELETE", + }, + }, { name: "Security path", args: args{ @@ -105,3 +115,77 @@ func Test_routing(t *testing.T) { }) } } + +func TestGetSwagger(t *testing.T) { + e = getEcho() + + type args struct { + apiPath string + apiName string + } + tests := []struct { + name string + args args + }{ + { + name: "Provider api", + args: args{ + apiPath: "provider", + apiName: "Provider", + }, + }, + { + name: "Publish api", + args: args{ + apiPath: "publish", + apiName: "Publish", + }, + }, + { + name: "Invoker api", + args: args{ + apiPath: "invoker", + apiName: "Invoker", + }, + }, + { + name: "Events api", + args: args{ + apiPath: "events", + apiName: "Events", + }, + }, + { + name: "Discover api", + args: args{ + apiPath: "discover", + apiName: "Discover", + }, + }, + { + name: "Security api", + args: args{ + apiPath: "security", + apiName: "Security", + }, + }, + } + for _, tt := range tests { + t.Run(tt.name, func(t *testing.T) { + result := testutil.NewRequest().Get("/swagger/"+tt.args.apiPath).Go(t, e) + assert.Equal(t, http.StatusOK, result.Code()) + var swaggerResponse openapi3.T + err := result.UnmarshalJsonToObject(&swaggerResponse) + assert.Nil(t, err) + assert.Contains(t, swaggerResponse.Info.Title, tt.args.apiName) + }) + } + invalidApi := "foobar" + result := testutil.NewRequest().Get("/swagger/"+invalidApi).Go(t, e) + assert.Equal(t, http.StatusBadRequest, result.Code()) + var errorResponse common29122.ProblemDetails + err := result.UnmarshalJsonToObject(&errorResponse) + assert.Nil(t, err) + assert.Contains(t, *errorResponse.Cause, "Invalid API") + assert.Contains(t, *errorResponse.Cause, invalidApi) +}