From 087006c483e99f1abef742feca4e57ea7d89462a Mon Sep 17 00:00:00 2001 From: Tobias Gesellchen Date: Sun, 15 Feb 2026 23:27:11 +0100 Subject: [PATCH] Add regression test for settings persistence --- cmd/soundtouch-service/main.go | 8 +-- cmd/soundtouch-service/main_test.go | 97 +++++++++++++++++++++++++++++ 2 files changed, 101 insertions(+), 4 deletions(-) create mode 100644 cmd/soundtouch-service/main_test.go diff --git a/cmd/soundtouch-service/main.go b/cmd/soundtouch-service/main.go index 5e14b43..5653fe8 100644 --- a/cmd/soundtouch-service/main.go +++ b/cmd/soundtouch-service/main.go @@ -380,10 +380,10 @@ func applyPersistedSettings(ds *datastore.DataStore, config *serviceConfig) data } } - config.redact = persisted.RedactLogs || config.redact - config.logBody = persisted.LogBodies || config.logBody - config.record = persisted.RecordInteractions || config.record - config.enableSoundcorkProxy = persisted.EnableSoundcorkProxy || config.enableSoundcorkProxy + config.redact = persisted.RedactLogs + config.logBody = persisted.LogBodies + config.record = persisted.RecordInteractions + config.enableSoundcorkProxy = persisted.EnableSoundcorkProxy return persisted } diff --git a/cmd/soundtouch-service/main_test.go b/cmd/soundtouch-service/main_test.go new file mode 100644 index 0000000..7abe5cc --- /dev/null +++ b/cmd/soundtouch-service/main_test.go @@ -0,0 +1,97 @@ +package main + +import ( + "os" + "testing" + + "github.com/gesellix/bose-soundtouch/pkg/service/datastore" +) + +func TestApplyPersistedSettings(t *testing.T) { + tmpDir, err := os.MkdirTemp("", "main-test") + if err != nil { + t.Fatalf("Failed to create temp dir: %v", err) + } + defer os.RemoveAll(tmpDir) + + ds := datastore.NewDataStore(tmpDir) + + t.Run("overrides true with false", func(t *testing.T) { + config := &serviceConfig{ + redact: true, + logBody: true, + record: true, + enableSoundcorkProxy: true, + } + + // Simulate the bug by using the old bitwise OR logic in the test, + // which should fail if we expect false. + // config.redact = config.redact || false -> stays true + + settings := datastore.Settings{ + RedactLogs: false, + LogBodies: false, + RecordInteractions: false, + EnableSoundcorkProxy: false, + } + err := ds.SaveSettings(settings) + if err != nil { + t.Fatalf("Failed to save settings: %v", err) + } + + applyPersistedSettings(ds, config) + + if config.redact != false { + t.Errorf("Expected redact to be false, got true") + } + if config.logBody != false { + t.Errorf("Expected logBody to be false, got true") + } + if config.record != false { + t.Errorf("Expected record to be false, got true") + } + if config.enableSoundcorkProxy != false { + t.Errorf("Expected enableSoundcorkProxy to be false, got true") + } + }) + + t.Run("retains false when settings are false", func(t *testing.T) { + settings := datastore.Settings{ + RedactLogs: false, + } + err := ds.SaveSettings(settings) + if err != nil { + t.Fatalf("Failed to save settings: %v", err) + } + + config := &serviceConfig{ + redact: false, + } + + applyPersistedSettings(ds, config) + + if config.redact != false { + t.Errorf("Expected redact to be false, got true") + } + }) + + t.Run("overrides false with true", func(t *testing.T) { + settings := datastore.Settings{ + RedactLogs: true, + } + err := ds.SaveSettings(settings) + if err != nil { + t.Fatalf("Failed to save settings: %v", err) + } + + config := &serviceConfig{ + redact: false, + } + + applyPersistedSettings(ds, config) + + if config.redact != true { + t.Errorf("Expected redact to be true, got false") + } + }) +}