forked from h2non/imaginary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
params_test.go
68 lines (56 loc) · 1.33 KB
/
params_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
package main
import (
"net/http"
"net/http/httptest"
"os"
"testing"
)
const fixture = "fixtures/large.jpg"
func TestReadParams(t *testing.T) {
var params ImageOptions
fakeHandler := func(w http.ResponseWriter, r *http.Request) {
params = readParams(r)
w.Write([]byte{0})
}
url := "http://foo/?width=100&height=100&opacity=0.2&noreplicate=true&text=hello"
file, _ := os.Open(fixture)
r, _ := http.NewRequest("GET", url, file)
w := httptest.NewRecorder()
fakeHandler(w, r)
assert := params.Width == 100 &&
params.Height == 100 &&
params.NoReplicate == true &&
params.Opacity == 0.2 &&
params.Text == "hello"
if assert == false {
t.Error("Invalid param")
}
}
func TestParseColor(t *testing.T) {
cases := []struct {
value string
expected []uint8
}{
{"200,100,20", []uint8{200, 100, 20}},
{"0,280,200", []uint8{0, 255, 200}},
{" -1, 256 , 50", []uint8{0, 255, 50}},
{" a, 20 , &hel0", []uint8{0, 20, 0}},
{"", []uint8{}},
}
for _, color := range cases {
c := parseColor(color.value)
l := len(color.expected)
if len(c) != l {
t.Errorf("Invalid color length: %#v", c)
}
if l == 0 {
continue
}
assert := c[0] == color.expected[0] &&
c[1] == color.expected[1] &&
c[2] == color.expected[2]
if assert == false {
t.Errorf("Invalid color schema: %#v <> %#v", color.expected, c)
}
}
}