forked from jherman3/zencoder
-
Notifications
You must be signed in to change notification settings - Fork 1
/
zencoder_test.go
66 lines (50 loc) · 1.35 KB
/
zencoder_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
package zencoder
import (
"net/http"
"net/http/httptest"
"testing"
)
func TestGenericCall(t *testing.T) {
var headers http.Header
mux := http.NewServeMux()
mux.HandleFunc("/test", func(w http.ResponseWriter, r *http.Request) {
headers = r.Header
})
srv := httptest.NewServer(mux)
zc := NewZencoder("abc")
zc.BaseUrl = srv.URL
resp, err := zc.call("GET", "test", nil, []int{http.StatusOK})
if err != nil {
t.Fatal("Expected no error", err)
}
if resp == nil {
t.Fatal("Expected a response")
}
if len(headers) == 0 {
t.Fatal("Expected headers")
}
if len(headers["User-Agent"]) == 0 {
t.Fatal("Expected User-Agent")
}
if headers["User-Agent"][0] != "gozencoder v1" {
t.Fatal("Expected User-Agent=gozencoder v1", headers["User-Agent"])
}
if len(headers["Accept"]) == 0 {
t.Fatal("Expected Accept")
}
if headers["Accept"][0] != "application/json" {
t.Fatal("Expected Accept=application/json", headers["Accept"])
}
if len(headers["Content-Type"]) == 0 {
t.Fatal("Expected Content-Type")
}
if headers["Content-Type"][0] != "application/json" {
t.Fatal("Expected Content-Type=application/json", headers["Content-Type"])
}
if len(headers["Zencoder-Api-Key"]) == 0 {
t.Fatal("Expected Zencoder-Api-Key")
}
if headers["Zencoder-Api-Key"][0] != "abc" {
t.Fatal("Expected Zencoder-Api-Key=abc", headers["Zencoder-Api-Key"])
}
}