Skip to content

Commit

Permalink
test: improve testing of server.go ✅
Browse files Browse the repository at this point in the history
  • Loading branch information
kareemmahlees committed Feb 16, 2024
1 parent f300c53 commit 405755c
Showing 1 changed file with 28 additions and 5 deletions.
33 changes: 28 additions & 5 deletions internal/server_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
package internal

import (
"fmt"
"log"
"meta-x/lib"
"meta-x/utils"
"net/http"
"testing"

"github.com/gofiber/fiber/v2"
Expand All @@ -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")

Expand All @@ -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)

}

0 comments on commit 405755c

Please sign in to comment.