0.1.52 Gateway
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
package api
|
||||
|
||||
import (
|
||||
"log/slog"
|
||||
"testing"
|
||||
"time"
|
||||
|
||||
"github.com/ponzischeme89/memby/server/internal/logging"
|
||||
"github.com/ponzischeme89/memby/server/internal/store"
|
||||
)
|
||||
|
||||
// The three meanings a duration-like override carries. Zero is not "off" — that is the
|
||||
// whole point of the -1, and reading it as off would silently disable an alert window an
|
||||
// operator had merely left alone.
|
||||
func TestOverrideWindowSeparatesOffFromDeployed(t *testing.T) {
|
||||
deployed := 15 * time.Minute
|
||||
if got := overrideWindow(0, time.Minute, deployed); got != deployed {
|
||||
t.Fatalf("zero should fall back to the deployed value, got %s", got)
|
||||
}
|
||||
if got := overrideWindow(store.GatewaySettingsOff, time.Minute, deployed); got != 0 {
|
||||
t.Fatalf("a negative override should switch the window off, got %s", got)
|
||||
}
|
||||
if got := overrideWindow(45, time.Minute, deployed); got != 45*time.Minute {
|
||||
t.Fatalf("a positive override should be taken in the given unit, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
// The probe loop must keep ticking while it is switched off, or turning it back on would
|
||||
// need a restart of the gateway — which is the thing the setting exists to avoid.
|
||||
func TestEmbyProbeDelayKeepsTickingWhileOff(t *testing.T) {
|
||||
if got := embyProbeDelay(0); got != time.Minute {
|
||||
t.Fatalf("a switched-off probe should still wake up, got %s", got)
|
||||
}
|
||||
if got := embyProbeDelay(30 * time.Second); got != 30*time.Second {
|
||||
t.Fatalf("a live probe should wait its interval, got %s", got)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGatewaySettingsChangesReportsOnlyWhatMoved(t *testing.T) {
|
||||
before := store.GatewaySettings{Timezone: "Pacific/Auckland", SessionIdleDays: 30}
|
||||
if summary := gatewaySettingsChanges(before, before); summary != "" {
|
||||
t.Fatalf("an unchanged save must not be news, got %q", summary)
|
||||
}
|
||||
one := before
|
||||
one.LogLevel = "debug"
|
||||
if summary := gatewaySettingsChanges(before, one); summary != "The gateway's log level was changed" {
|
||||
t.Fatalf("one change reads wrong: %q", summary)
|
||||
}
|
||||
two := one
|
||||
two.SessionIdleDays = 60
|
||||
summary := gatewaySettingsChanges(before, two)
|
||||
if summary != "The gateway's log level and session expiry were changed" {
|
||||
t.Fatalf("two changes read wrong: %q", summary)
|
||||
}
|
||||
}
|
||||
|
||||
func TestLevelNameCoversTheVocabulary(t *testing.T) {
|
||||
for _, level := range store.GatewayLogLevels {
|
||||
if got := levelName(parseTestLevel(t, level)); got != level {
|
||||
t.Fatalf("%s round-tripped as %s", level, got)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
func parseTestLevel(t *testing.T, name string) slog.Level {
|
||||
t.Helper()
|
||||
return logging.ParseLevel(name)
|
||||
}
|
||||
Reference in New Issue
Block a user