blob: 383c5aa021d5fe735a06f0aa21654a7d9e9ea807 [file] [log] [blame]
elinuxhenrik498e5c42022-04-28 09:54:05 +02001// -
2// ========================LICENSE_START=================================
3// O-RAN-SC
4// %%
5// Copyright (C) 2022: Nordix Foundation
6// %%
7// Licensed under the Apache License, Version 2.0 (the "License");
8// you may not use this file except in compliance with the License.
9// You may obtain a copy of the License at
10//
11// http://www.apache.org/licenses/LICENSE-2.0
12//
13// Unless required by applicable law or agreed to in writing, software
14// distributed under the License is distributed on an "AS IS" BASIS,
15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16// See the License for the specific language governing permissions and
17// limitations under the License.
18// ========================LICENSE_END===================================
19//
20
21package main
22
23import (
24 "net/http"
25 "testing"
26
27 "github.com/deepmap/oapi-codegen/pkg/testutil"
28 "github.com/labstack/echo/v4"
29 "github.com/stretchr/testify/assert"
30)
31
32var e *echo.Echo
33
elinuxhenrik0fabf172022-04-28 17:03:15 +020034func Test_routing(t *testing.T) {
elinuxhenrik498e5c42022-04-28 09:54:05 +020035 e = getEcho()
36
elinuxhenrik0fabf172022-04-28 17:03:15 +020037 type args struct {
38 url string
39 returnStatus int
40 method string
41 }
42 tests := []struct {
43 name string
44 args args
45 }{
46 {
47 name: "Default path",
48 args: args{
49 url: "/",
50 returnStatus: http.StatusOK,
51 method: "GET",
52 },
53 },
54 {
55 name: "Provider path",
56 args: args{
57 url: "/api-provider-management/v1/registrations/provider",
58 returnStatus: http.StatusNoContent,
59 method: "DELETE",
60 },
61 },
62 {
63 name: "Publish path",
64 args: args{
65 url: "/published-apis/v1/apfId/service-apis/serviceId",
66 returnStatus: http.StatusNotFound,
67 method: "GET",
68 },
69 },
70 {
71 name: "Discover path",
72 args: args{
73 url: "/service-apis/v1/allServiceAPIs?api-invoker-id=api_invoker_id",
74 returnStatus: http.StatusOK,
75 method: "GET",
76 },
77 },
78 {
79 name: "Invoker path",
80 args: args{
81 url: "/api-invoker-management/v1/onboardedInvokers/invoker",
82 returnStatus: http.StatusNoContent,
83 method: "DELETE",
84 },
85 },
86 {
87 name: "Security path",
88 args: args{
89 url: "/capif-security/v1/trustedInvokers/apiInvokerId",
90 returnStatus: http.StatusNotImplemented,
91 method: "GET",
92 },
93 },
94 }
95 for _, tt := range tests {
96 t.Run(tt.name, func(t *testing.T) {
97 var result *testutil.CompletedRequest
98 if tt.args.method == "GET" {
99 result = testutil.NewRequest().Get(tt.args.url).Go(t, e)
100 } else if tt.args.method == "DELETE" {
101 result = testutil.NewRequest().Delete(tt.args.url).Go(t, e)
102 }
elinuxhenrik498e5c42022-04-28 09:54:05 +0200103
elinuxhenrik0fabf172022-04-28 17:03:15 +0200104 assert.Equal(t, tt.args.returnStatus, result.Code(), tt.name)
105 })
106 }
elinuxhenrik498e5c42022-04-28 09:54:05 +0200107}