-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcurse_test.go
181 lines (158 loc) · 5.59 KB
/
curse_test.go
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
/*
Copyright 2017 Oliver Kahrmann
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
or implied. See the License for the specific language governing
permissions and limitations under the License.
*/
package curse
import (
"strings"
"testing"
"time"
)
func TestParseCurse(t *testing.T) {
testUrls := []string{
"https://mods.curse.com/mc-mods/minecraft/238424-taam",
"https://mods.curse.com/texture-packs/minecraft/equanimity-32x",
"https://mods.curse.com/worlds/minecraft/246026-skyblock-3",
"https://mods.curse.com/addons/wow/pawn",
}
for idx, url := range testUrls {
resp, err := FetchPage(url)
if err != nil {
t.Fatal(url, err)
}
results, err := ParseCurse(url, resp)
if err != nil {
t.Fatal(url, err)
}
// For first element (taam project page), check for existence of the donation URL.
validateResults(t, url, results, idx == 0)
}
}
func validateResults(t *testing.T, url string, results *Curse, expectDonationURL bool) {
// Just some basic tests that tell us when a value returns nil or default values.
// If that is the case, the parser is likely borked because curse changed their website layout.
if len(results.Downloads) == 0 {
t.Errorf("Empty list 'Downloads' when testing URL %s", url)
}
for _, dl := range results.Downloads {
if dl.Date == time.Unix(0, 0).UTC() {
t.Errorf("Empty value 'Download/Date' when testing URL %s", url)
}
if time.Since(dl.Date).Hours() > 96 && dl.Downloads == 0 {
// Only fail for downloads that are reasonably old. Some may actually have 0 downloads
t.Errorf("Empty value 'Download/Downloads' when testing URL %s", url)
}
if dl.GameVersion == "" {
t.Errorf("Empty value 'Download/GameVersion' when testing URL %s", url)
}
if dl.Name == "" {
t.Errorf("Empty value 'Download/Name' when testing URL %s", url)
}
if dl.ReleaseType == "" {
t.Errorf("Empty value 'Download/ReleaseType' when testing URL %s", url)
}
if dl.URL == nil || dl.URL.Host == "" {
t.Errorf("Empty value 'Download/ReleaseType' when testing URL %s", url)
}
}
if len(results.Authors) == 0 {
t.Errorf("Empty list 'Authors' when testing URL %s", url)
}
for _, a := range results.Authors {
if a.Name == "" {
t.Errorf("Empty value 'Author/Name' when testing URL %s", url)
}
if a.Role == "" {
t.Errorf("Empty value 'Author/Role' when testing URL %s", url)
}
if strings.Contains(a.Role, ":") {
t.Errorf("Trimming ':' from author role failed when testing URL %s", url)
}
if a.Role == "" {
t.Errorf("Empty value 'Author/Role' when testing URL %s", url)
}
if a.URL == nil || a.URL.Host == "" {
t.Errorf("Empty value 'Author/URL' when testing URL %s", url)
}
if a.ImageURL != nil {
// Avatar ImageURL is not filled by the mods.curse.com parser...
t.Errorf("'How on earch did that get here?' FILLED value 'Author/ImageURL' when testing URL %s", url)
}
}
if len(results.Screenshots) == 0 {
t.Errorf("Empty list 'Screenshots' when testing URL %s", url)
}
for _, s := range results.Screenshots {
if s.URL == nil || s.URL.Host == "" {
t.Errorf("Empty value 'Screenshot/URL' when testing URL %s", url)
}
if s.ThumbnailURL != nil {
// Thumbnail URL is not filled by the mods.curse.com parser...
t.Errorf("'How on earch did that get here?' FILLED value 'Screenshot/ThumbnailURL' when testing URL %s", url)
}
}
if len(results.Categories) == 0 {
t.Errorf("Empty list 'Categories' when testing URL %s", url)
}
for _, c := range results.Categories {
if c.URL == nil || c.URL.Host == "" {
t.Errorf("Empty value 'Category/URL' when testing URL %s", url)
}
if c.ImageURL == nil || c.ImageURL.Host == "" {
t.Errorf("Empty value 'Category/ImageURL' when testing URL %s", url)
}
if c.Name == "" {
t.Errorf("Empty value 'Category/Name' when testing URL %s", url)
}
}
if results.Title == "" {
t.Errorf("Empty value 'Title' when testing URL %s", url)
}
if results.License == "" {
t.Errorf("Empty value 'License' when testing URL %s", url)
}
if results.Game == "" {
t.Errorf("Empty value 'Game' when testing URL %s", url)
}
if results.GameURL == nil || results.GameURL.Host == "" {
t.Errorf("Empty value 'GameURL' when testing URL %s", url)
}
if results.CurseforgeURL == nil || results.CurseforgeURL.Host == "" {
t.Errorf("Empty value 'CurseforgeURL' when testing URL %s", url)
}
// The donation URL may actually be empty for some projects..
if expectDonationURL {
if results.DontationURL == nil || results.DontationURL.Host == "" {
t.Errorf("Empty value 'DontationURL' when testing URL %s", url)
}
}
if results.Favorites == 0 {
t.Errorf("Empty value 'Favorites' when testing URL %s", url)
}
if results.Likes == 0 {
t.Errorf("Empty value 'Likes' when testing URL %s", url)
}
if results.AvgDownloads == 0 {
t.Errorf("Empty value 'AvgDownloads' when testing URL %s", url)
}
if results.TotalDownloads == 0 {
t.Errorf("Empty value 'TotalDownloads' when testing URL %s", url)
}
if results.AvgDownloadsTimeframe == "" {
t.Errorf("Empty value 'AvgDownloadsTimeframe' when testing URL %s", url)
}
if results.Created == time.Unix(0, 0).UTC() {
t.Errorf("Empty value 'Created' when testing URL %s", url)
}
if results.Updated == time.Unix(0, 0).UTC() {
t.Errorf("Empty value 'Updated' when testing URL %s", url)
}
}