-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoonshine_test.go
72 lines (64 loc) · 1.56 KB
/
moonshine_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
package main
import (
"log"
"os"
"testing"
)
type dataCount struct {
fpath string
count int
pagecount int
}
var htmCountTests = []dataCount{
{"baddeed.shine.html.test", 179, 18},
{"d0cf11e0.shine.html.test", 5501087, 550109},
{"gif89.shine.html.test", 133576903, 13357691},
}
var jsonCountTests = []dataCount{
{"baadeed.warclight.json.test", 0, 0},
{"d0cf11e0.warclight.json.test", 10, 1},
{"gif89.warclight.json.test", 379, 38},
}
func getData(fname string) string {
rawhtm, err := os.ReadFile(fname)
if err != nil {
log.Fatal(err)
}
return string(rawhtm)
}
func TestParseHtmForLinks(t *testing.T) {
for _, htmTest := range htmCountTests {
htm := getData(htmTest.fpath)
h, err := parseHtmForLinks(htm)
if err != nil {
t.Error("didn't work, error returned")
}
if len(h) != 10 {
t.Error("didn't work")
}
}
}
func TestParseHtmForResults(t *testing.T) {
for _, htmTest := range htmCountTests {
htm := getData(htmTest.fpath)
count, pagecount, _ := statResults(htm)
if count != htmTest.count {
t.Errorf("didn't find correct count in %s", htmTest.fpath)
}
if pagecount != htmTest.pagecount {
t.Errorf("didn't find correct pagecount in %s", htmTest.fpath)
}
}
}
func TestParseWarclight(t *testing.T) {
for _, jsonTest := range jsonCountTests {
js := getData(jsonTest.fpath)
res, err := parseWarclight(js)
if err != nil {
t.Errorf("Unexpected error in parsing JSON in %s", jsonTest.fpath)
}
if res.Meta.Pages.TotalCount != jsonTest.count {
t.Errorf("didn't find correct res count in %s", jsonTest.fpath)
}
}
}