check / check (push) Failing after 1s
These three packages had no tests. Add behavioural, external (package foo_test) tests that can each fail on a plausible break: - globals: setters and read-back through New, plus that New returns an independent snapshot. One sequential function with a disclosed paralleltest suppression, because it mutates shared package globals. - healthcheck: Check returns status "ok", the exact documented JSON field set, an RFC3339Nano timestamp, maintenanceMode mirroring the config in both states, and the version and appname from globals. - logger: New yields a usable *slog.Logger, debug is suppressed at the default level, and EnableDebugLogging turns it on. No production code changed. TTY-branch output format is not asserted. Model: opus-4-8
51 lines
1.4 KiB
Go
51 lines
1.4 KiB
Go
package globals_test
|
|
|
|
import (
|
|
"testing"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
|
|
"sneak.berlin/go/dnswatcher/internal/globals"
|
|
)
|
|
|
|
// TestGlobals exercises the package-level version and appname
|
|
// variables through their setters and read-back via New. These are
|
|
// shared package state, so the test mutates a global and must run
|
|
// sequentially; it cannot use t.Parallel().
|
|
//
|
|
//nolint:paralleltest // mutates shared package-level globals, must run sequentially
|
|
func TestGlobals(t *testing.T) {
|
|
versions := []string{"v1.2.3", "dev", "", "v1.2.3-4-gabcdef"}
|
|
for _, want := range versions {
|
|
globals.SetVersion(want)
|
|
|
|
g, err := globals.New(nil)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, want, g.Version,
|
|
"New must surface the version set by SetVersion")
|
|
}
|
|
|
|
names := []string{"dnswatcher", "other", ""}
|
|
for _, want := range names {
|
|
globals.SetAppname(want)
|
|
|
|
g, err := globals.New(nil)
|
|
require.NoError(t, err)
|
|
assert.Equal(t, want, g.Appname,
|
|
"New must surface the appname set by SetAppname")
|
|
}
|
|
|
|
// New returns a snapshot: a later SetVersion must not mutate a
|
|
// Globals handed out earlier.
|
|
globals.SetVersion("first")
|
|
|
|
g, err := globals.New(nil)
|
|
require.NoError(t, err)
|
|
|
|
globals.SetVersion("second")
|
|
assert.Equal(t, "first", g.Version,
|
|
"a Globals returned by New must not change when the "+
|
|
"package variable is set again")
|
|
}
|