-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathshard_test.go
61 lines (55 loc) · 1.71 KB
/
shard_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
package giashard
import (
"errors"
"testing"
)
type testcase struct {
url string
n uint
slug string
shard uint64
}
var testcases [11]testcase = [...]testcase{
// https://github.com/paracrawl/giashard/issues/1
{"http://www.reddit.com/", 8, "reddit", 249},
{"http://www.reddit.com/.", 8, "reddit", 249},
{"http://www.reddit.com./", 8, "reddit", 249},
{"http://www.reddit.com.", 8, "reddit", 249},
{"www.reddit.com/.", 8, "reddit", 249},
{"www.reddit.com.", 8, "reddit", 249},
{"tulas-handy-charts.de/en/index.html", 8, "tulas-handy-charts", 179},
{"localhost/ford_a/ford_a_restore_2013_02.html", 8, "localhost", 24},
{"localhost", 8, "localhost", 24},
// https://github.com/paracrawl/giashard/issues/8
{"https://www.futuremovieshop.fi/index.php?language=en", 8, "futuremovieshop", 128},
{"https://www.futuremovieshop.fi/%s", 8, "futuremovieshop", 128},
}
func TestSlug(t *testing.T) {
for _, tcase := range testcases {
slug, err := Slug(tcase.url)
if err != nil {
t.Errorf("Slug(%v): error: %v", tcase.url, err)
} else if slug != tcase.slug {
t.Errorf("Slug(%v): got %v expected %v", tcase.url, slug, tcase.slug)
}
}
}
func TestShardId(t *testing.T) {
for _, tcase := range testcases {
shard, err := ShardId(tcase.url, tcase.n)
if err != nil {
t.Errorf("ShardId(%v, %v): error: %v", tcase.url, tcase.n, err)
} else if shard != tcase.shard {
t.Errorf("ShardId(%v, %v): got %d expected %d", tcase.url, tcase.n, shard, tcase.shard)
}
}
}
func TestError(t *testing.T) {
e := NewShardErr("test", nil)
if !errors.Is(e, ShardError) {
t.Errorf("Cannot identify ShardErr")
}
if errors.Is(e, errors.New("generic error")) {
t.Errorf("ShardErr mistakenly identified as generic error")
}
}