refactor: shorten TestBuildSourceReferences below funlen threshold

This commit is contained in:
2026-06-11 13:03:19 +02:00
parent 0227c8688b
commit 76af597f4d

View File

@@ -26,6 +26,12 @@ type stringTransformTestCase struct {
want string want string
} }
type sourceReferencesTestCase struct {
name string
rawURLs []any
wantRefs []sourceReference
}
func runStringTransformTests(t *testing.T, tests []stringTransformTestCase, fn func(string) string) { func runStringTransformTests(t *testing.T, tests []stringTransformTestCase, fn func(string) string) {
t.Helper() t.Helper()
@@ -40,6 +46,31 @@ func runStringTransformTests(t *testing.T, tests []stringTransformTestCase, fn f
} }
} }
func runSourceReferenceTests(t *testing.T, tests []sourceReferencesTestCase) {
t.Helper()
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := buildSourceReferences(tt.rawURLs)
if len(got) != len(tt.wantRefs) {
t.Errorf("got %d refs, want %d", len(got), len(tt.wantRefs))
return
}
for i, want := range tt.wantRefs {
if got[i].URL != want.URL {
t.Errorf("ref[%d].URL = %q, want %q", i, got[i].URL, want.URL)
}
if got[i].Name != want.Name {
t.Errorf("ref[%d].Name = %q, want %q", i, got[i].Name, want.Name)
}
}
})
}
}
func TestDecodeSourceURL(t *testing.T) { func TestDecodeSourceURL(t *testing.T) {
t.Parallel() t.Parallel()
@@ -191,11 +222,7 @@ func TestBuildStreamSource(t *testing.T) {
func TestBuildSourceReferences(t *testing.T) { func TestBuildSourceReferences(t *testing.T) {
t.Parallel() t.Parallel()
tests := []struct { tests := []sourceReferencesTestCase{
name string
rawURLs []any
wantRefs []sourceReference
}{
{ {
name: "empty returns empty", name: "empty returns empty",
rawURLs: nil, rawURLs: nil,
@@ -247,26 +274,7 @@ func TestBuildSourceReferences(t *testing.T) {
}, },
} }
for _, tt := range tests { runSourceReferenceTests(t, tests)
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
got := buildSourceReferences(tt.rawURLs)
if len(got) != len(tt.wantRefs) {
t.Errorf("got %d refs, want %d", len(got), len(tt.wantRefs))
return
}
for i, want := range tt.wantRefs {
if got[i].URL != want.URL {
t.Errorf("ref[%d].URL = %q, want %q", i, got[i].URL, want.URL)
}
if got[i].Name != want.Name {
t.Errorf("ref[%d].Name = %q, want %q", i, got[i].Name, want.Name)
}
}
})
}
} }
func TestBuildSourceReferencesOrder(t *testing.T) { func TestBuildSourceReferencesOrder(t *testing.T) {