X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Fmain_test.go;h=7d77b92382134ce19a96eb76bb340c6ffc3b9ec0;hb=refs%2Ftags%2F1.0.1;hp=12092c1b28c795eaa5192ee0df478aeb5e7dcbfc;hpb=b4da1f981ba6717f5ec52e15ad1db257b5d6b7f3;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/main_test.go b/capifcore/main_test.go index 12092c1..7d77b92 100644 --- a/capifcore/main_test.go +++ b/capifcore/main_test.go @@ -21,8 +21,12 @@ package main import ( + "crypto/tls" + "fmt" + "io" "net/http" "testing" + "time" "github.com/deepmap/oapi-codegen/pkg/testutil" "github.com/getkin/kin-openapi/openapi3" @@ -85,6 +89,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{ @@ -140,6 +152,13 @@ func TestGetSwagger(t *testing.T) { apiName: "Invoker", }, }, + { + name: "Events api", + args: args{ + apiPath: "events", + apiName: "Events", + }, + }, { name: "Discover api", args: args{ @@ -174,3 +193,32 @@ func TestGetSwagger(t *testing.T) { assert.Contains(t, *errorResponse.Cause, "Invalid API") assert.Contains(t, *errorResponse.Cause, invalidApi) } + +func TestHTTPSServer(t *testing.T) { + e = getEcho() + var port = 44333 + go startHttpsWebServer(e, 44333, "certs/cert.pem", "certs/key.pem") //"certs/test/cert.pem", "certs/test/key.pem" + + time.Sleep(100 * time.Millisecond) + + tr := &http.Transport{ + TLSClientConfig: &tls.Config{InsecureSkipVerify: true}, + } + + client := &http.Client{Transport: tr} + res, err := client.Get(fmt.Sprintf("https://localhost:%d", port)) + if err != nil { + t.Fatal(err) + } + + defer res.Body.Close() + assert.Equal(t, res.StatusCode, res.StatusCode) + + body, err := io.ReadAll(res.Body) + if err != nil { + t.Fatal(err) + } + + expected := []byte("Hello, World!") + assert.Equal(t, expected, body) +}