From 76af597f4d47148a3c540c441b663a00ddade3ba Mon Sep 17 00:00:00 2001 From: mkelvers Date: Thu, 11 Jun 2026 13:03:19 +0200 Subject: [PATCH] refactor: shorten TestBuildSourceReferences below funlen threshold --- integrations/playback/allanime/client_test.go | 58 +++++++++++-------- 1 file changed, 33 insertions(+), 25 deletions(-) diff --git a/integrations/playback/allanime/client_test.go b/integrations/playback/allanime/client_test.go index b184dea..bcfd831 100644 --- a/integrations/playback/allanime/client_test.go +++ b/integrations/playback/allanime/client_test.go @@ -26,6 +26,12 @@ type stringTransformTestCase struct { want string } +type sourceReferencesTestCase struct { + name string + rawURLs []any + wantRefs []sourceReference +} + func runStringTransformTests(t *testing.T, tests []stringTransformTestCase, fn func(string) string) { 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) { t.Parallel() @@ -191,11 +222,7 @@ func TestBuildStreamSource(t *testing.T) { func TestBuildSourceReferences(t *testing.T) { t.Parallel() - tests := []struct { - name string - rawURLs []any - wantRefs []sourceReference - }{ + tests := []sourceReferencesTestCase{ { name: "empty returns empty", rawURLs: nil, @@ -247,26 +274,7 @@ func TestBuildSourceReferences(t *testing.T) { }, } - 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) - } - } - }) - } + runSourceReferenceTests(t, tests) } func TestBuildSourceReferencesOrder(t *testing.T) {