-
Notifications
You must be signed in to change notification settings - Fork 0
/
util_test.go
115 lines (91 loc) · 6.89 KB
/
util_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
package GTCHA
import (
"os"
"testing"
)
func TestParseDomains(t *testing.T) {
domains, err := parseDomains(
[]string{"http://bowery.io", "\ngoogle.com ", " https://bing.no"},
)
if err != nil {
t.Fatal(err)
}
if n, a := len(domains), 3; n != a {
t.Fatalf("expected %d domains, got %d", n, a)
}
if n, a := domains[0], "bowery.io"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
if n, a := domains[1], "google.com"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
if n, a := domains[2], "bing.no"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
domains, err = parseDomains([]string{"a", "\nb", "\nhttp://abc.com:8080"})
if err != nil {
t.Fatal(err)
}
if n, a := len(domains), 3; n != a {
t.Fatalf("expected %d domains, got %d", n, a)
}
if n, a := domains[0], "a"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
if n, a := domains[1], "b"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
if n, a := domains[2], "abc.com:8080"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
domains, err = parseDomains([]string{"abc.com:8080"})
if err == nil {
t.Fatal("expected error")
}
domains, err = parseDomains([]string{
"a", "\n\n", "\n\n", " \n\n", "b\n", "http://abc.com:8080",
})
if err != nil {
t.Fatal(err)
}
if n, a := len(domains), 3; n != a {
t.Fatalf("expected %d domains, got %d", n, a)
}
}
func TestParseDomain(t *testing.T) {
if domain, err := parseDomain(" http://bowery.io "); err != nil {
t.Fatal(err)
} else if n, a := domain, "bowery.io"; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
if _, err := parseDomain(" spark.io:90 "); err == nil {
t.Fatal("expected error")
}
if domain, err := parseDomain(" http://spark.io:90 "); err != nil {
t.Fatal(err)
} else if n, a := "spark.io:90", domain; n != a {
t.Fatalf("expected '%s', got '%s'", n, a)
}
}
func TestDataURI(t *testing.T) {
exp := "data:image/gif;base64,R0lGODdhNgA8ALMAAAAAAEsXfpkz//9mZqWLv8yZ//+zswDM/4Dm/wD/mYD/zP//mf//zP///wAAAAAAACH5BAkKAA4ALAAAAAA2ADwAAARJ0MlJq7046827/2AojmRpnmiqrmzrvnAsz25jN7R34zm3974bcEgsGo/IpHLJbDqf0Kh0Sq1ar9isdsvter/gsHhMLpvP6HQ5AgAh+QQJCgAOACwMAAwABAAIAAAECZDJSStrOOvdIgAh+QQJCgAOACwMAAwABAAMAAAEDXDJSetSOOutmv9g2EQAIfkECQoADgAsDAAMAAQAEAAABBJwyUnrSjjrnZT/YKg0ZGmeTQQAIfkECQoADgAsDAAMAAQAFAAABBNwyUnrSjjrzbtWYCiOSmOeaNpEACH5BAkKAA4ALAwADAAEABgAAAQVcMlJ60o46827/5kijmSpNGiqrk0EACH5BAkKAA4ALAwADAAEABwAAAQWcMlJ60o46827/+CnjGRpKk2qrmwTAQAh+QQJCgAOACwMAAwABAAgAAAEF3DJSetKOOvNu/9gKGJKaZ6o0qxs6zYRACH5BAkKAA4ALAwADAAEACQAAAQYcMlJ60o46827/2AojptinmiqNGzrvk0EACH5BAkKAA4ALAwADAAIACQAAAQ7cMnlqpvUYnsnT2DyhSNYilaIVurppiRsyqvT0i8b6zNf376cbTfsFX9E4FGoRDgRjWjjCZVSpdMnNgIAIfkECQoADgAsDAAMAAwAJAAABFBwyeWqrZNemzefXpWMSeiQZYiaq0qyrzvCs5x6LR7rNX9vOeBO2CP+LkHkUFlkHi1J6FLapD5FU2xVe3Uc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M5HbYF3gF2ewSPl+d0uBzvqO/xAoECf3OCg3d8DoaEbYuIfI5AiSORSZOKgoxhlZcVnJ2fl6GTo4mlkJmPgKmSoIIHsLGys7S1tre4ubq7vL0RACH5BAkKAA4ALAwADAAeACQAAASXcK1GG7tMaj36cGAISpWFbZv3iSFZYRkqqWw7vae80LWT/IleT8UDAYNCFtEjOiaVy5UR+BRFpT5qFXRVObeOrue7FXfIVfMADWYF3gF2OwSPa+duuBxf388FgAJ+bYGCd3ghhYNgioeIDo0/jyKRSJOQgYtblZcgnJ2fl6GTo4+liKd4qX+BB66vsLGys7S1tre4ubq7EQAh+QQJcBcOACwMAAwAHgAkAAAEiXDJSesceLjNt/1VpnUcaC4iWZ5fqjpJnLyv6G7yTJN21uU7Xm+EkwU7QyLMeNwkRcCm45mJNqkY6xE70EpJgXDA++WIx8wyWExWn9tlgVwA/87paTXnXpfy83oOfzGBHYM6hYJzfU2HiRuOj5GJk4WVgZd6mWqbcXMHoKGio6SlpqeoqaqrrK0RADs="
f, err := os.Open("giphy_logo_laser.gif")
if err != nil {
t.Fatal(err)
}
defer f.Close()
finfo, err := f.Stat()
if err != nil {
t.Fatal(err)
}
buf := make([]byte, finfo.Size())
_, err = f.Read(buf)
if err != nil {
t.Fatal(err)
}
uri := dataURI(buf, gifType)
if uri != exp {
t.Fatalf("data uri different than expected")
}
}
func TestGet(t *testing.T) { t.Log("TODO") }