NONRTRIC-946: Capifcore - remove comment
[nonrtric/plt/sme.git] / capifcore / main_test.go
index 12092c1..f174fe3 100644 (file)
@@ -2,7 +2,8 @@
 //   ========================LICENSE_START=================================
 //   O-RAN-SC
 //   %%
-//   Copyright (C) 2022: Nordix Foundation
+//   Copyright (C) 2022: Nordix Foundation. All rights reserved.
+//   Copyright (C) 2023 OpenInfra Foundation Europe. All rights reserved.
 //   %%
 //   Licensed under the Apache License, Version 2.0 (the "License");
 //   you may not use this file except in compliance with the License.
 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,11 +90,19 @@ 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{
                                url:          "/capif-security/v1/trustedInvokers/apiInvokerId",
-                               returnStatus: http.StatusNotImplemented,
+                               returnStatus: http.StatusNotFound,
                                method:       "GET",
                        },
                },
@@ -140,6 +153,13 @@ func TestGetSwagger(t *testing.T) {
                                apiName: "Invoker",
                        },
                },
+               {
+                       name: "Events api",
+                       args: args{
+                               apiPath: "events",
+                               apiName: "Events",
+                       },
+               },
                {
                        name: "Discover api",
                        args: args{
@@ -174,3 +194,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)
+}