-
Notifications
You must be signed in to change notification settings - Fork 8
/
Copy pathtranslate_test.go
61 lines (49 loc) · 1.15 KB
/
translate_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 giphy
import (
"net/http"
"testing"
)
func TestTranslate(t *testing.T) {
for _, tt := range []struct {
args []string
s string
}{
{[]string{"foo", "bar"}, "foo bar"},
{[]string{"bar", "baz"}, "bar baz"},
} {
requests := []*http.Request{}
server, client := jsonServerAndClient(200, `{
"data": {
},
"meta": {
"status": 200,
"msg": "OK"
}
}`, &requests)
defer server.Close()
res, err := client.Translate(tt.args)
if err != nil {
t.Errorf(`unexpected error %v`, err)
}
if got, want := res.Meta.Status, 200; got != want {
t.Errorf(`search.Meta.Status = %+v, want %+v`, got, want)
}
if got := len(requests); got != 1 {
t.Fatalf(`unexpected number of requests %d`, got)
}
r := requests[0]
if got := r.URL.Path; got != "/v1/gifs/translate" {
t.Errorf(`unexpected path %#v`, got)
}
params := r.URL.Query()
if got := params.Get("api_key"); got != "test-api-key" {
t.Errorf(`unexpected api_key %#v`, got)
}
if got := params.Get("rating"); got != "g" {
t.Errorf(`unexpected rating %#v`, got)
}
if got := params.Get("s"); got != tt.s {
t.Errorf(`unexpected s %#v`, got)
}
}
}