Skip to content

Commit

Permalink
add server blackbox test
Browse files Browse the repository at this point in the history
  • Loading branch information
juancwu committed Dec 16, 2024
1 parent 5a7f62d commit a49ea82
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions backend/internal/tests/server_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package tests

import (
"KonferCA/SPUR/internal/server"
"encoding/json"
"io"
"net/http"
"net/http/httptest"
"testing"

"github.com/stretchr/testify/assert"
)

/*
This file contains blackbox testing for the server package which includes
all routes that are exposed by the server. The main objective is to test
that all routes are behaving how they should be from the perspective of
a client that doesn't know the inner implementation details.
*/
func TestServer(t *testing.T) {
setupEnv()

s, err := server.New()
assert.Nil(t, err)

t.Run("Test API V1 Health Check Route", func(t *testing.T) {
req := httptest.NewRequest(http.MethodGet, "/api/v1/health", nil)
rec := httptest.NewRecorder()
s.GetEcho().ServeHTTP(rec, req)
assert.Equal(t, rec.Code, http.StatusOK)
resBytes, err := io.ReadAll(rec.Body)
assert.Nil(t, err)
var resBody map[string]any
err = json.Unmarshal(resBytes, &resBody)
assert.Nil(t, err)
assert.Equal(t, resBody["status"], "healthy")
assert.NotEmpty(t, resBody["timestamp"])
assert.NotEmpty(t, resBody["database"])
assert.NotEmpty(t, resBody["system"])
})
}

0 comments on commit a49ea82

Please sign in to comment.