test: report failures as got/want and use subtests for tables

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_017GpWAskjmYtZpuQ5JwYTX3
This commit is contained in:
Sebastian UnterschützandClaude Opus 5.5 committed 2026-11-22 00:18:02 +01:00
1 parent d20225982a
commit b6843330a8
8 files changed
+184 -175

No files matched your search

+17 -17
View File
@@ -2,24 +2,24 @@ package config
import "testing"
func TestValidateRedisModes(t *testing.T) {
base := Common{Edition: EditionSelfHosted, DatabaseURL: "postgres://x"}
cases := []struct {
name string
mod func(*Common)
ok bool
func TestCommonValidateRedisModes(t *testing.T) {
tests := []struct {
name string
modify func(*Common)
wantErr bool
}{
{"standalone", func(c *Common) { c.RedisURL = "redis://r" }, true},
{"nothing", func(c *Common) {}, false},
{"sentinel", func(c *Common) { c.RedisSentinel = Sentinel{Master: "m", Addrs: []string{"s:26379"}} }, true},
{"sentinel without addrs", func(c *Common) { c.RedisSentinel = Sentinel{Master: "m"} }, false},
{"standalone", func(c *Common) { c.RedisURL = "redis://r" }, false},
{"no redis", func(*Common) {}, true},
{"sentinel", func(c *Common) { c.RedisSentinel = Sentinel{Master: "m", Addrs: []string{"s:26379"}} }, false},
{"sentinel without addrs", func(c *Common) { c.RedisSentinel = Sentinel{Master: "m"} }, true},
}
for _, tc := range cases {
c := base
tc.mod(&c)
if err := c.Validate(); (err == nil) != tc.ok {
t.Errorf("%s: err=%v", tc.name, err)
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
c := Common{Edition: EditionSelfHosted, DatabaseURL: "postgres://x"}
tt.modify(&c)
if err := c.Validate(); (err != nil) != tt.wantErr {
t.Errorf("Validate() = %v, want error: %t", err, tt.wantErr)
}
})
}
}