aboutsummaryrefslogtreecommitdiffstats
path: root/internal/notify/config_test.go
diff options
context:
space:
mode:
authorDanilo M. <danix@danix.xyz>2026-10-19 09:15:38 +0200
committerDanilo M. <danix@danix.xyz>2026-10-19 09:15:38 +0200
commit75acc11af55b4efe0ea095a52a3916b13639c2cd (patch)
tree9e56593a3c6ef8aa7b6d03c9408d3239a1d8a582 /internal/notify/config_test.go
parenta8003f630728b8e4b5f2b163d9be2837da146b23 (diff)
downloadnotifyd-75acc11af55b4efe0ea095a52a3916b13639c2cd.tar.gz
notifyd-75acc11af55b4efe0ea095a52a3916b13639c2cd.zip
feat(notify): read timeouts and caps from config.json
A missing or broken file is the defaults, so a hand typo never stops the daemon; a key of the wrong type keeps its default while the rest applies. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Diffstat (limited to 'internal/notify/config_test.go')
-rw-r--r--internal/notify/config_test.go65
1 files changed, 65 insertions, 0 deletions
diff --git a/internal/notify/config_test.go b/internal/notify/config_test.go
new file mode 100644
index 0000000..46032ee
--- /dev/null
+++ b/internal/notify/config_test.go
@@ -0,0 +1,65 @@
+// Copyright (C) 2026 Danilo M. <danix@danix.xyz>
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License version 2 as
+// published by the Free Software Foundation.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+
+package notify
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+)
+
+func writeConfig(t *testing.T, body string) string {
+ t.Helper()
+ p := filepath.Join(t.TempDir(), "config.json")
+ if err := os.WriteFile(p, []byte(body), 0o600); err != nil {
+ t.Fatal(err)
+ }
+ return p
+}
+
+func TestLoadConfigMissingFileIsDefaults(t *testing.T) {
+ got := LoadConfig(filepath.Join(t.TempDir(), "absent.json"))
+ if got != DefaultConfig() {
+ t.Errorf("got %+v, want defaults", got)
+ }
+}
+
+func TestLoadConfigMalformedIsDefaults(t *testing.T) {
+ got := LoadConfig(writeConfig(t, `{"liveCap": 5,`))
+ if got != DefaultConfig() {
+ t.Errorf("got %+v, want defaults", got)
+ }
+}
+
+func TestLoadConfigPartialMergesOverDefaults(t *testing.T) {
+ got := LoadConfig(writeConfig(t, `{"timeouts": {"low": 3}, "historyCap": 50, "muted": ["x"]}`))
+ want := DefaultConfig()
+ want.Timeouts.Low = 3
+ want.HistoryCap = 50
+ if got != want {
+ t.Errorf("got %+v, want %+v", got, want)
+ }
+}
+
+func TestLoadConfigWrongTypeKeepsThatDefault(t *testing.T) {
+ got := LoadConfig(writeConfig(t, `{"liveCap": "many", "historyCap": 7}`))
+ if got.LiveCap != 20 || got.HistoryCap != 7 {
+ t.Errorf("got live %d history %d, want 20 and 7", got.LiveCap, got.HistoryCap)
+ }
+}
+
+func TestLoadConfigClamps(t *testing.T) {
+ got := LoadConfig(writeConfig(t, `{"liveCap": 0, "historyCap": 1000, "timeouts": {"normal": -4}}`))
+ if got.LiveCap != 1 || got.HistoryCap != 100 || got.Timeouts.Normal != 10 {
+ t.Errorf("got %+v", got)
+ }
+}