-
Notifications
You must be signed in to change notification settings - Fork 35
Expand file tree
/
Copy pathTibiaBoostableBossesOverview_test.go
More file actions
114 lines (102 loc) · 2.87 KB
/
Copy pathTibiaBoostableBossesOverview_test.go
File metadata and controls
114 lines (102 loc) · 2.87 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package main
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
"github.com/tibiadata/tibiadata-api-go/src/static"
)
func TestBoostableBossesOverview(t *testing.T) {
file, err := static.TestFiles.Open("testdata/boostablebosses/boostablebosses.html")
if err != nil {
t.Fatalf("file opening error: %s", err)
}
defer file.Close()
data, err := io.ReadAll(file)
if err != nil {
t.Fatalf("File reading error: %s", err)
}
boostableBossesJson, _ := TibiaBoostableBossesOverviewImpl(string(data), "https://www.tibia.com/library/?subtopic=boostablebosses")
assert := assert.New(t)
boosted := boostableBossesJson.BoostableBosses.Boosted
bosses := boostableBossesJson.BoostableBosses.BoostableBosses
information := boostableBossesJson.Information
assert.Equal("https://www.tibia.com/library/?subtopic=boostablebosses", information.TibiaURLs[0])
assert.Equal(98, len(bosses))
assert.Equal("Ragiaz", boosted.Name)
assert.Equal(
"https://static.tibia.com/images/global/header/monsters/ragiaz.gif",
boosted.ImageURL,
)
for _, tc := range []struct {
idx int
name string
featured bool
imageURL string
}{
{
idx: 21,
name: "Gnomevil",
featured: false,
imageURL: "https://static.tibia.com/images/library/gnomehorticulist.gif",
},
{
idx: 26,
name: "Goshnar's Malice",
featured: false,
imageURL: "https://static.tibia.com/images/library/goshnarsmalice.gif",
},
{
idx: 49,
name: "Ragiaz",
featured: true,
imageURL: "https://static.tibia.com/images/library/ragiaz.gif",
},
{
idx: 57,
name: "Sharpclaw",
featured: false,
imageURL: "https://static.tibia.com/images/library/sharpclaw.gif",
},
{
idx: 80,
name: "The Pale Worm",
featured: false,
imageURL: "https://static.tibia.com/images/library/paleworm.gif",
},
} {
boss := bosses[tc.idx]
assert.Equal(
tc.name, boss.Name,
"Wrong name\nidx: %d (%s)\nwant: %s\ngot: %s",
tc.idx, tc.name, tc.name, boss.Name,
)
assert.Equal(
tc.featured, boss.Featured,
"Wrong featured status\nidx: %d (%s)\nwant: %v\ngot: %v",
tc.idx, tc.name, tc.featured, boss.Featured,
)
assert.Equal(
tc.imageURL, boss.ImageURL,
"Wrong image URL\nidx: %d (%s)\nwant: %s\ngot: %s",
tc.idx, tc.name, tc.imageURL, boss.ImageURL,
)
}
}
var bossSink BoostableBossesOverviewResponse
func BenchmarkTibiaBoostableBossesOverviewImpl(b *testing.B) {
file, err := static.TestFiles.Open("testdata/boostablebosses/boostablebosses.html")
if err != nil {
b.Fatalf("file opening error: %s", err)
}
defer file.Close()
rawData, err := io.ReadAll(file)
if err != nil {
b.Fatalf("File reading error: %s", err)
}
data := string(rawData)
b.ReportAllocs()
b.ResetTimer()
for i := 0; i < b.N; i++ {
bossSink, _ = TibiaBoostableBossesOverviewImpl(data, "https://www.tibia.com/library/?subtopic=boostablebosses")
}
}