diff --git a/backend/internal/tests/server_test.go b/backend/internal/tests/server_test.go new file mode 100644 index 0000000..684fb2d --- /dev/null +++ b/backend/internal/tests/server_test.go @@ -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"]) + }) +}