Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions consent/consent_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,19 @@ func TestGetConsent_MalformedConsentValue_DefaultsTrue(t *testing.T) {
}
}

func TestGetConsent_MalformedConfigFile_DefaultsTrue(t *testing.T) {
t.Parallel()
home := t.TempDir()
// Config file exists but contains invalid JSON; readRaw returns a parse
// error and GetConsent falls back to the safe opt-out default (true).
writeConfig(t, home, `{not valid json`)
for _, flag := range []string{"telemetry", "broadcasts", "reviews"} {
if got := consent.GetConsent(home, flag); !got {
t.Errorf("GetConsent(%q) = false, want true (unparseable config → default true)", flag)
}
}
}

func TestGetConsent_UnknownFlag_DefaultsTrue(t *testing.T) {
t.Parallel()
home := t.TempDir()
Expand Down Expand Up @@ -128,6 +141,17 @@ func TestSetConsent_InvalidFlag_DoesNotCreateFile(t *testing.T) {
}
}

func TestSetConsent_MalformedConfigFile_ReturnsError(t *testing.T) {
t.Parallel()
home := t.TempDir()
// A pre-existing unparseable config makes readRaw fail; SetConsent
// propagates the error rather than clobbering the file.
writeConfig(t, home, `{not valid json`)
if err := consent.SetConsent(home, "telemetry", false); err == nil {
t.Fatal("SetConsent on malformed config = nil error, want parse error")
}
}

func TestSetConsent_CreatesFileAndDir(t *testing.T) {
t.Parallel()
home := t.TempDir()
Expand Down
Loading