Skip to content

Commit a765540

Browse files
Refacto igdb/game_test using test tables
1 parent b64f7ba commit a765540

File tree

1 file changed

+45
-83
lines changed

1 file changed

+45
-83
lines changed

igdb/game_test.go

Lines changed: 45 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -8,109 +8,71 @@ import (
88
)
99

1010
func TestCoverURL(t *testing.T) {
11-
game := createFullfilledGame()
11+
game := Game{Cover: Cover{Id: 1, ImageID: "lich_king"}}
1212
result := game.CoverURL()
13-
expected := "https://images.igdb.com/igdb/image/upload/t_cover_big/thisIsACoverID.png"
13+
expected := "https://images.igdb.com/igdb/image/upload/t_cover_big/lich_king.png"
1414

1515
if result != expected {
16-
t.Errorf("Unexpected coverUrl: expected:%s, got:%s", expected, result)
16+
t.Errorf("Unexpected CoverUrl(): expected:%s, got:%s", expected, result)
1717
}
1818
}
1919

20-
func TestNotionPlatformsFullfilled(t *testing.T) {
21-
game := createFullfilledGame()
22-
result := game.NotionPlatforms()
23-
expected := []notionapi.Option{
24-
{Name: "Wii"},
25-
{Name: "PC"},
20+
func TestNotionPlatforms(t *testing.T) {
21+
var game Game = Game{}
22+
var tests = []struct {
23+
platforms Platforms
24+
expected []notionapi.Option
25+
}{
26+
{platforms: Platforms{}, expected: []notionapi.Option{}},
27+
{platforms: Platforms{{Id: 1, Name: "Wii"}, {Id: 2, Name: "PC"}}, expected: []notionapi.Option{{Name: "Wii"}, {Name: "PC"}}},
2628
}
2729

28-
if !reflect.DeepEqual(result, expected) {
29-
t.Errorf("Unexpected notionPlatforms: expected:%s, got:%s", expected, result)
30-
}
31-
}
32-
33-
func TestNotionPlatformsEmpty(t *testing.T) {
34-
game := createFullfilledGame()
35-
game.Platforms = nil
36-
37-
result := game.NotionPlatforms()
38-
expected := []notionapi.Option{}
30+
for _, tt := range tests {
31+
game.Platforms = tt.platforms
32+
result := game.NotionPlatforms()
3933

40-
if !reflect.DeepEqual(result, expected) {
41-
t.Errorf("Unexpected notionPlatforms: expected:%s, got:%s", expected, result)
34+
if !reflect.DeepEqual(result, tt.expected) {
35+
t.Errorf("Unexpected NotionPlatforms(): expected:%s, got:%s", tt.expected, result)
36+
}
4237
}
4338
}
4439

45-
func TestNotionGenresFullfilled(t *testing.T) {
46-
game := createFullfilledGame()
47-
result := game.NotionGenres()
48-
expected := []notionapi.Option{
49-
{Name: "Roleplay"},
50-
{Name: "Shooter"},
40+
func TestNotionGenres(t *testing.T) {
41+
var game Game = Game{}
42+
var tests = []struct {
43+
genres Genres
44+
expected []notionapi.Option
45+
}{
46+
{genres: Genres{}, expected: []notionapi.Option{}},
47+
{genres: Genres{{Id: 5, Name: "Roleplay"}, {Id: 6, Name: "Shooter"}}, expected: []notionapi.Option{{Name: "Roleplay"}, {Name: "Shooter"}}},
5148
}
5249

53-
if !reflect.DeepEqual(result, expected) {
54-
t.Errorf("Unexpected notionGenres: expected:%s, got:%s", expected, result)
55-
}
56-
}
57-
58-
func TestNotionGenresEmpty(t *testing.T) {
59-
game := createFullfilledGame()
60-
game.Genres = nil
50+
for _, tt := range tests {
51+
game.Genres = tt.genres
52+
result := game.NotionGenres()
6153

62-
result := game.NotionGenres()
63-
expected := []notionapi.Option{}
64-
65-
if !reflect.DeepEqual(result, expected) {
66-
t.Errorf("Unexpected notionGenres: expected:%s, got:%s", expected, result)
54+
if !reflect.DeepEqual(result, tt.expected) {
55+
t.Errorf("Unexpected NotionGenres(): expected:%s, got:%s", tt.expected, result)
56+
}
6757
}
6858
}
6959

70-
func TestNotionFranchisesFullfilled(t *testing.T) {
71-
game := createFullfilledGame()
72-
result := game.NotionFranchises()
73-
expected := []notionapi.Option{
74-
{Name: "An awesome franchise"},
75-
{Name: "Another awesome franchise"},
76-
}
77-
78-
if !reflect.DeepEqual(result, expected) {
79-
t.Errorf("Unexpected notionFranchises: expected:%s, got:%s", expected, result)
60+
func TestNotionFranchises(t *testing.T) {
61+
var game Game = Game{}
62+
var tests = []struct {
63+
franchises Franchises
64+
expected []notionapi.Option
65+
}{
66+
{franchises: Franchises{}, expected: []notionapi.Option{}},
67+
{franchises: Franchises{{Id: 3, Name: "An awesome franchise"}, {Id: 4, Name: "Another awesome franchise"}}, expected: []notionapi.Option{{Name: "An awesome franchise"}, {Name: "Another awesome franchise"}}},
8068
}
81-
}
8269

83-
func TestNotionFranchisesEmpty(t *testing.T) {
84-
game := createFullfilledGame()
85-
game.Franchises = nil
70+
for _, tt := range tests {
71+
game.Franchises = tt.franchises
72+
result := game.NotionFranchises()
8673

87-
result := game.NotionFranchises()
88-
expected := []notionapi.Option{}
89-
90-
if !reflect.DeepEqual(result, expected) {
91-
t.Errorf("Unexpected notionFranchises: expected:%s, got:%s", expected, result)
92-
}
93-
}
94-
func createFullfilledGame() Game {
95-
return Game{
96-
Id: 1,
97-
Name: "This is a fullfilled game",
98-
ReleaseDate: 861199200,
99-
Platforms: Platforms{
100-
{Id: 1, Name: "Wii"},
101-
{Id: 2, Name: "PC"},
102-
},
103-
Franchises: Franchises{
104-
{Id: 3, Name: "An awesome franchise"},
105-
{Id: 4, Name: "Another awesome franchise"},
106-
},
107-
Genres: Genres{
108-
{Id: 5, Name: "Roleplay"},
109-
{Id: 6, Name: "Shooter"},
110-
},
111-
Cover: Cover{
112-
Id: 7,
113-
ImageID: "thisIsACoverID",
114-
},
74+
if !reflect.DeepEqual(result, tt.expected) {
75+
t.Errorf("Unexpected NotionFranchises(): expected:%s, got:%s", tt.expected, result)
76+
}
11577
}
11678
}

0 commit comments

Comments
 (0)