-
Notifications
You must be signed in to change notification settings - Fork 1
/
client_test.go
78 lines (70 loc) · 2 KB
/
client_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
package client
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
"fmt"
"net/http"
)
var _ = Describe("Client", func() {
It("should create a instance of a Client", func() {
xclient, err := NewClient("http://localhost.api.snickers/")
Expect(err).NotTo(HaveOccurred())
Expect(xclient.Endpoint).To(Equal("http://localhost.api.snickers/"))
})
It("should create an instance of APIError", func() {
apiError := &APIError{
Status: http.StatusInternalServerError,
Errors: "Internal Server Error",
}
Expect(apiError.Error()).To(Equal(`Error returned by the Snickers API: {"status":500,"errors":"Internal Server Error"}`))
})
It("should execute do generic method", func() {
server := StartFakeServer(http.StatusOK, `[{
"name": "mp4_240p",
"description": "Test Preset",
"container": "mp4",
"rateControl": "vbr",
"video": {
"height": "720",
"width": "1280",
"codec": "h264",
"bitrate": "10000"
},
"audio": {
"codec": "aac",
"bitrate": "64000"
}
}]`)
defer server.Close()
client, _ := NewClient(server.URL)
var respObj []Preset
err := client.do("GET", "/presets", []interface{}{}, &respObj)
Expect(respObj[0].Name).To(Equal("mp4_240p"))
Expect(err).NotTo(HaveOccurred())
})
It("should fail when passing invalid JSON to client.do method", func() {
server := StartFakeServer(http.StatusOK, `[{
"name": "mp4_240p",
"description": "Test Preset",
"container": "mp4",
"rateControl": "vbr",
"video": {
"height": "720",
"width": "1280",
"codec": "h264",
"bitrate": "10000",
},
"audio": {
"codec": "aac",
"bitrate": "64000",
}
]`)
defer server.Close()
client, _ := NewClient(server.URL)
var respObj []Preset
err := client.do("GET", "/presets", "nil", &respObj)
fmt.Println(err)
Expect(err).To(HaveOccurred())
Expect(err.Error()).To(Equal("invalid character '}' looking for beginning of object key string"))
})
})