mirror of
https://github.com/coder/coder.git
synced 2025-07-03 16:13:58 +00:00
feat(coderd): add simple healthcheck formatting option (#9864)
This commit is contained in:
@ -12,6 +12,7 @@ import (
|
||||
|
||||
"github.com/coder/coder/v2/coderd/coderdtest"
|
||||
"github.com/coder/coder/v2/coderd/healthcheck"
|
||||
"github.com/coder/coder/v2/coderd/healthcheck/derphealth"
|
||||
"github.com/coder/coder/v2/testutil"
|
||||
)
|
||||
|
||||
@ -34,7 +35,7 @@ func TestDebugHealth(t *testing.T) {
|
||||
defer cancel()
|
||||
|
||||
sessionToken = client.SessionToken()
|
||||
res, err := client.Request(ctx, "GET", "/debug/health", nil)
|
||||
res, err := client.Request(ctx, "GET", "/api/v2/debug/health", nil)
|
||||
require.NoError(t, err)
|
||||
defer res.Body.Close()
|
||||
_, _ = io.ReadAll(res.Body)
|
||||
@ -106,6 +107,41 @@ func TestDebugHealth(t *testing.T) {
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
require.Equal(t, 1, calls)
|
||||
})
|
||||
|
||||
t.Run("Text", func(t *testing.T) {
|
||||
t.Parallel()
|
||||
|
||||
var (
|
||||
ctx, cancel = context.WithTimeout(context.Background(), testutil.WaitShort)
|
||||
sessionToken string
|
||||
client = coderdtest.New(t, &coderdtest.Options{
|
||||
HealthcheckFunc: func(_ context.Context, apiKey string) *healthcheck.Report {
|
||||
assert.Equal(t, sessionToken, apiKey)
|
||||
return &healthcheck.Report{
|
||||
Time: time.Now(),
|
||||
Healthy: true,
|
||||
DERP: derphealth.Report{Healthy: true},
|
||||
}
|
||||
},
|
||||
})
|
||||
_ = coderdtest.CreateFirstUser(t, client)
|
||||
)
|
||||
defer cancel()
|
||||
|
||||
sessionToken = client.SessionToken()
|
||||
res, err := client.Request(ctx, "GET", "/api/v2/debug/health?format=text", nil)
|
||||
require.NoError(t, err)
|
||||
defer res.Body.Close()
|
||||
resB, _ := io.ReadAll(res.Body)
|
||||
require.Equal(t, http.StatusOK, res.StatusCode)
|
||||
|
||||
resStr := string(resB)
|
||||
assert.Contains(t, resStr, "healthy: true")
|
||||
assert.Contains(t, resStr, "derp: true")
|
||||
assert.Contains(t, resStr, "access_url: false")
|
||||
assert.Contains(t, resStr, "websocket: false")
|
||||
assert.Contains(t, resStr, "database: false")
|
||||
})
|
||||
}
|
||||
|
||||
func TestDebugWebsocket(t *testing.T) {
|
||||
|
Reference in New Issue
Block a user