-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
41 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"]) | ||
}) | ||
} |