Skip to content

Commit 8d97561

Browse files
authored
Merge pull request #1386 from EngineeringKiosk/test/go-check-player-urls
test: add unit tests for checkMissingPlayerURLs
2 parents 13e9832 + 32ec593 commit 8d97561

1 file changed

Lines changed: 90 additions & 0 deletions

File tree

Lines changed: 90 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,90 @@
1+
package cmd
2+
3+
import (
4+
"sort"
5+
"testing"
6+
7+
"github.com/EngineeringKiosk/website/website-admin/episode"
8+
)
9+
10+
func TestCheckMissingPlayerURLs(t *testing.T) {
11+
tests := []struct {
12+
name string
13+
fm episode.EpisodeFrontmatter
14+
expected []string
15+
}{
16+
{
17+
name: "all URLs present",
18+
fm: episode.EpisodeFrontmatter{
19+
Spotify: "https://spotify.com/ep1",
20+
ApplePodcasts: "https://apple.com/ep1",
21+
AmazonMusic: "https://amazon.com/ep1",
22+
Deezer: "https://deezer.com/ep1",
23+
YouTube: "https://youtube.com/ep1",
24+
},
25+
expected: nil,
26+
},
27+
{
28+
name: "all URLs missing",
29+
fm: episode.EpisodeFrontmatter{},
30+
expected: []string{
31+
"amazon_music",
32+
"apple_podcasts",
33+
"deezer",
34+
"spotify",
35+
"youtube",
36+
},
37+
},
38+
{
39+
name: "only spotify missing",
40+
fm: episode.EpisodeFrontmatter{
41+
ApplePodcasts: "https://apple.com/ep1",
42+
AmazonMusic: "https://amazon.com/ep1",
43+
Deezer: "https://deezer.com/ep1",
44+
YouTube: "https://youtube.com/ep1",
45+
},
46+
expected: []string{"spotify"},
47+
},
48+
{
49+
name: "only deezer missing",
50+
fm: episode.EpisodeFrontmatter{
51+
Spotify: "https://spotify.com/ep1",
52+
ApplePodcasts: "https://apple.com/ep1",
53+
AmazonMusic: "https://amazon.com/ep1",
54+
YouTube: "https://youtube.com/ep1",
55+
},
56+
expected: []string{"deezer"},
57+
},
58+
{
59+
name: "multiple missing",
60+
fm: episode.EpisodeFrontmatter{
61+
Spotify: "https://spotify.com/ep1",
62+
YouTube: "https://youtube.com/ep1",
63+
},
64+
expected: []string{
65+
"amazon_music",
66+
"apple_podcasts",
67+
"deezer",
68+
},
69+
},
70+
}
71+
72+
for _, tt := range tests {
73+
t.Run(tt.name, func(t *testing.T) {
74+
got := checkMissingPlayerURLs(tt.fm)
75+
76+
// Sort both for stable comparison since map iteration is non-deterministic
77+
sort.Strings(got)
78+
sort.Strings(tt.expected)
79+
80+
if len(got) != len(tt.expected) {
81+
t.Fatalf("checkMissingPlayerURLs() returned %d items %v, want %d items %v", len(got), got, len(tt.expected), tt.expected)
82+
}
83+
for i, want := range tt.expected {
84+
if got[i] != want {
85+
t.Errorf("checkMissingPlayerURLs()[%d] = %q, want %q", i, got[i], want)
86+
}
87+
}
88+
})
89+
}
90+
}

0 commit comments

Comments
 (0)