48 lines
2.0 KiB
Go
48 lines
2.0 KiB
Go
package store
|
|||
|
|
|
||
|
|
import "testing"
|
||
|
|
|
||
|
|
// Normalisation is what stands between a hand-edited row (or a console built against an
|
||
|
|
// older vocabulary) and a gateway that cannot decide what day it is.
|
||
|
|
func TestNormalizeGatewaySettingsRefusesWhatItCannotUse(t *testing.T) {
|
||
|
|
settings := normalizeGatewaySettings(GatewaySettings{
|
||
|
|
Timezone: " Not/AZone ", LogLevel: "LOUD", SessionIdleDays: -4,
|
||
|
|
})
|
||
|
|
if settings.Timezone != "" {
|
||
|
|
t.Fatalf("an unloadable timezone should be dropped, got %q", settings.Timezone)
|
||
|
|
}
|
||
|
|
if settings.LogLevel != "" {
|
||
|
|
t.Fatalf("an unknown level should be dropped, got %q", settings.LogLevel)
|
||
|
|
}
|
||
|
|
// Session expiry cannot be switched off — a household with no expiry at all is a
|
||
|
|
// database full of live Emby tokens — so a negative reads as "leave it alone".
|
||
|
|
if settings.SessionIdleDays != 0 {
|
||
|
|
t.Fatalf("session expiry should not be switchable off, got %d", settings.SessionIdleDays)
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func TestNormalizeGatewaySettingsKeepsTheThreeMeanings(t *testing.T) {
|
||
|
|
settings := normalizeGatewaySettings(GatewaySettings{
|
||
|
|
Timezone: "Pacific/Auckland", LogLevel: " Debug ",
|
||
|
|
SonarrAlertMinutes: -9, RadarrAlertMinutes: 0, EmbyHealthSeconds: 5,
|
||
|
|
})
|
||
|
|
if settings.Timezone != "Pacific/Auckland" {
|
||
|
|
t.Fatalf("a real zone should survive, got %q", settings.Timezone)
|
||
|
|
}
|
||
|
|
if settings.LogLevel != "debug" {
|
||
|
|
t.Fatalf("a level should be trimmed and folded, got %q", settings.LogLevel)
|
||
|
|
}
|
||
|
|
if settings.SonarrAlertMinutes != GatewaySettingsOff {
|
||
|
|
t.Fatalf("every negative should collapse to the one off value, got %d",
|
||
|
|
settings.SonarrAlertMinutes)
|
||
|
|
}
|
||
|
|
if settings.RadarrAlertMinutes != 0 {
|
||
|
|
t.Fatalf("zero must keep meaning deployed, got %d", settings.RadarrAlertMinutes)
|
||
|
|
}
|
||
|
|
// Below the floor rather than refused: an operator asking for a five-second probe has
|
||
|
|
// said "as often as possible", and the answer to that is the fastest allowed.
|
||
|
|
if settings.EmbyHealthSeconds != 10 {
|
||
|
|
t.Fatalf("a value under the floor should clamp to it, got %d", settings.EmbyHealthSeconds)
|
||
|
|
}
|
||
|
|
}
|