This repository has been archived by the owner on Nov 7, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extract_test.go
75 lines (65 loc) · 1.68 KB
/
extract_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
package resources
import (
"fmt"
"os"
"path/filepath"
"testing"
"github.com/datatogether/warc"
)
func TestExtractResponseUrls(t *testing.T) {
recs, err := readTestWarc("test_extract_response_urls.warc")
if err != nil {
t.Error(err.Error())
return
}
e := NewExtractor()
cases := []struct {
rec *warc.Record
urls []string
err string
}{
{recs[1], []string{
"http://datatogether.org/",
"./css/style.css",
"./img/favicon.ico",
"https://s3.amazonaws.com/datatogether/svg/lines_left.svg",
"https://s3.amazonaws.com/datatogether/svg/lines_right.svg",
"https://s3.us-east-2.amazonaws.com/static.archivers.space/add-metadata.png",
"https://s3.amazonaws.com/datatogether/svg/lines_left.svg",
"https://s3.amazonaws.com/datatogether/svg/lines_right.svg",
"./js/site.js",
}, ""},
}
for i, c := range cases {
urls, err := e.ExtractResponseUrls(c.rec)
if !(err == nil && c.err == "" || err != nil && err.Error() == c.err) {
t.Errorf("case %d marshal error mismatch: expected: %s, got: %s", i, c.err, err)
continue
}
if len(urls) != len(c.urls) {
for j, u := range urls {
fmt.Printf("case %d returned urls:", i)
fmt.Printf("%d: %s\n", j, u)
}
t.Errorf("case %d url length mismatch. expected: %d, got: %d", i, len(c.urls), len(urls))
continue
}
for j, u := range urls {
if c.urls[j] != u {
t.Errorf("case %d url %d mistmatch. expected: %s, got: %s", i, j, c.urls[j], u)
break
}
}
}
}
func readTestWarc(file string) (warc.Records, error) {
f, err := os.Open(filepath.Join("testdata", file))
if err != nil {
return nil, err
}
r, err := warc.NewReader(f)
if err != nil {
return nil, err
}
return r.ReadAll()
}