summaryrefslogtreecommitdiff
path: root/config/config_test.go
diff options
context:
space:
mode:
authorMartin Kagamino Lehoux <martin@lehoux.net>2026-08-05 14:17:59 +0200
committerMartin Kagamino Lehoux <martin@lehoux.net>2026-08-05 14:17:59 +0200
commit71c39ed9f8ce3563130cdfc5099e9d7df60845a9 (patch)
treee610b8360f6364e3ab7c5e817ac94bd51cc0dfd1 /config/config_test.go
parentbef31e1d35fe88f2698cf0e3191f26a79623f66f (diff)
refactor: Replace env config with atomic YAML
Diffstat (limited to 'config/config_test.go')
-rw-r--r--config/config_test.go38
1 files changed, 38 insertions, 0 deletions
diff --git a/config/config_test.go b/config/config_test.go
new file mode 100644
index 0000000..6b99030
--- /dev/null
+++ b/config/config_test.go
@@ -0,0 +1,38 @@
+package config
+
+import (
+ "os"
+ "path/filepath"
+ "testing"
+
+ "github.com/stretchr/testify/assert"
+ "github.com/stretchr/testify/require"
+)
+
+func TestSaveAndLoad(t *testing.T) {
+ filename := filepath.Join(t.TempDir(), "config.yaml")
+ want := Default()
+ want.Database.Path = "test.db"
+ want.Strava.ClientID = "123"
+ want.Strava.ExpiresAt = 1_700_000_000
+
+ require.NoError(t, Save(filename, want))
+ got, err := Load(filename)
+ require.NoError(t, err)
+ assert.Equal(t, want, got)
+ info, err := os.Stat(filename)
+ require.NoError(t, err)
+ assert.Equal(t, os.FileMode(0o600), info.Mode().Perm())
+}
+
+func TestSaveReplacesExistingConfigAtomically(t *testing.T) {
+ filename := filepath.Join(t.TempDir(), "config.yaml")
+ require.NoError(t, Save(filename, Default()))
+ updated := Default()
+ updated.Server.Address = "127.0.0.1:9090"
+ require.NoError(t, Save(filename, updated))
+
+ got, err := Load(filename)
+ require.NoError(t, err)
+ assert.Equal(t, "127.0.0.1:9090", got.Server.Address)
+}