- The README keeps the JWT secret in a file that is passed every time, so an upgrade does not make a new one and sign everybody out. - A health check that succeeds is logged at debug level, so a container does not write thousands of lines a day; any other answer, and every other request, still goes at info. - .dockerignore patterns match in every folder, as .gitignore does. - compose.yaml waits 15 seconds for Sonda to stop (it allows itself 10) and requires MUSIC_DIR instead of creating an empty folder. - The README says that the library path is the one inside the container, that the health check follows SONDA_LISTEN, and that a sonda.toml in /data works as a secrets file.
41 lines
1.3 KiB
Go
41 lines
1.3 KiB
Go
package httpapi
|
|
|
|
import (
|
|
"net/http"
|
|
"testing"
|
|
|
|
"github.com/uptrace/bun"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
"go.uber.org/zap/zaptest/observer"
|
|
)
|
|
|
|
// A container's health check asks every thirty seconds: that must not fill the log at the level
|
|
// people read, while every other request is still logged there.
|
|
func TestAHealthCheckThatSucceedsIsLoggedAtDebugAndOtherRequestsAtInfo(t *testing.T) {
|
|
core, logs := observer.New(zap.DebugLevel)
|
|
h, _ := newTestEnvDB(t, func(d *Deps, _ *bun.DB) { d.Logger = zap.New(core) })
|
|
|
|
for i := 0; i < 3; i++ {
|
|
if r := do(t, h, "GET", "/api/v1/health", "", nil); r.Code != http.StatusOK {
|
|
t.Fatalf("health: %d", r.Code)
|
|
}
|
|
}
|
|
do(t, h, "GET", "/api/v1/artists", "", nil) // refused, but a request like any other
|
|
|
|
var healthInfo, healthDebug, otherInfo int
|
|
for _, e := range logs.All() {
|
|
path, _ := e.ContextMap()["path"].(string)
|
|
switch {
|
|
case path == "/api/v1/health" && e.Level == zapcore.InfoLevel:
|
|
healthInfo++
|
|
case path == "/api/v1/health" && e.Level == zapcore.DebugLevel:
|
|
healthDebug++
|
|
case path == "/api/v1/artists" && e.Level == zapcore.InfoLevel:
|
|
otherInfo++
|
|
}
|
|
}
|
|
if healthInfo != 0 || healthDebug != 3 || otherInfo != 1 {
|
|
t.Errorf("health at info %d, at debug %d, other requests at info %d; want 0, 3 and 1", healthInfo, healthDebug, otherInfo)
|
|
}
|
|
}
|