refactor: update test, configuration deployment examples

This commit is contained in:
Jonas Kaninda
2024-11-10 21:05:19 +01:00
parent 410879748d
commit e25bc218b5
4 changed files with 169 additions and 45 deletions

View File

@@ -1,6 +1,8 @@
package pkg
import (
"context"
"log"
"net/http"
"net/http/httptest"
"os"
@@ -19,6 +21,16 @@ func TestInit(t *testing.T) {
}
}
func TestCheckConfig(t *testing.T) {
TestInit(t)
initConfig(configFile)
err := CheckConfig(configFile)
if err != nil {
t.Error(err)
}
log.Println("Goma Gateway configuration file checked successfully")
}
func TestStart(t *testing.T) {
TestInit(t)
initConfig(configFile)
@@ -28,7 +40,8 @@ func TestStart(t *testing.T) {
t.Error(err)
}
route := gatewayServer.Initialize()
route.HandleFunc("/", func(rw http.ResponseWriter, r *http.Request) {
route.HandleFunc("/test", func(rw http.ResponseWriter, r *http.Request) {
_, err := rw.Write([]byte("Hello Goma Proxy"))
if err != nil {
t.Fatalf("Failed writing HTTP response: %v", err)
@@ -43,10 +56,19 @@ func TestStart(t *testing.T) {
t.Fatalf("expected a status code of 200, got %v", resp.StatusCode)
}
}
ctx := context.Background()
go func() {
err = gatewayServer.Start(ctx)
if err != nil {
t.Error(err)
return
}
}()
t.Run("httpServer", func(t *testing.T) {
s := httptest.NewServer(route)
defer s.Close()
assertResponseBody(t, s, "Hello Goma Proxy")
})
ctx.Done()
}