diff --git a/internal/server_test.go b/internal/server_test.go index 04107c4..6341fe6 100644 --- a/internal/server_test.go +++ b/internal/server_test.go @@ -1,8 +1,11 @@ package internal import ( + "fmt" "log" "meta-x/lib" + "meta-x/utils" + "net/http" "testing" "github.com/gofiber/fiber/v2" @@ -13,12 +16,14 @@ func TestInitDBAndServer(t *testing.T) { listenCh := make(chan bool) app := fiber.New(fiber.Config{DisableStartupMessage: true}) - err := app.Shutdown() - if err != nil { - log.Fatal(err) - } + defer func() { + err := app.Shutdown() + if err != nil { + log.Fatal(err) + } + }() - err = InitDBAndServer(app, "anything", "mallformed", 5522, listenCh) + err := InitDBAndServer(app, "anything", "mallformed", 5522, listenCh) assert.NotNil(t, err) assert.ErrorContains(t, err, "unknown driver") @@ -37,5 +42,23 @@ func TestInitDBAndServer(t *testing.T) { for _, route := range testRoutes { foundRoute := app.GetRoute(route) assert.NotEmpty(t, foundRoute) + + request := utils.RequestTesting[any]{ + ReqMethod: http.MethodGet, + ReqUrl: fmt.Sprintf("/%s", route), + } + _, res := request.RunRequest(app) + + assert.NotEqual(t, http.StatusNotFound, res.StatusCode) + } + + go func(app *fiber.App) { + err = InitDBAndServer(app, lib.SQLITE3, ":memory:", 100000, listenCh) + assert.NotNil(t, err) + }(app) + + listenting = <-listenCh + assert.False(t, listenting) + }