X-Git-Url: https://gerrit.o-ran-sc.org/r/gitweb?a=blobdiff_plain;f=capifcore%2Fmain_test.go;h=7d77b92382134ce19a96eb76bb340c6ffc3b9ec0;hb=d500ede4df92a1c0ba4692df18a18982384ace90;hp=f3a5f1538feb086e54cc55d29b2345ddc42cb059;hpb=30931ba398fc7a3b9269af7120dce7bad027c79e;p=nonrtric%2Fplt%2Fsme.git diff --git a/capifcore/main_test.go b/capifcore/main_test.go index f3a5f15..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" @@ -189,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) +}