mirror of
https://github.com/juanfont/headscale.git
synced 2026-07-17 16:36:02 +00:00
Pin every endpoint's behaviour with golden fixtures captured from the retiring grpc-gateway (timestamps and secrets neutralised). Error cases assert their HTTP status independently of the golden via assertStatus, so a blind regenerate cannot re-pin a wrong code; HEADSCALE_UPDATE_GOLDEN rewrites the fixtures. A unit test exercises the API-key auth middleware on the real server router. Exclude the emitted spec and goldens from pre-commit checks.
24 lines
571 B
Go
24 lines
571 B
Go
package hscontrol
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestAPIV1Health(t *testing.T) {
|
|
h := newAPIV1Harness(t)
|
|
|
|
t.Run("huma returns healthy with database connectivity", func(t *testing.T) {
|
|
res := h.callHuma(http.MethodGet, "/api/v1/health", nil)
|
|
|
|
assert.Equal(t, http.StatusOK, res.status)
|
|
require.JSONEq(t, `{"databaseConnectivity":true}`, string(res.body))
|
|
})
|
|
|
|
t.Run("parity with gateway", func(t *testing.T) {
|
|
h.assertParity(t, http.MethodGet, "/api/v1/health", nil)
|
|
})
|
|
}
|