-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathclient_test.go
More file actions
106 lines (87 loc) · 2.46 KB
/
client_test.go
File metadata and controls
106 lines (87 loc) · 2.46 KB
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
package fcm
import (
"fmt"
fuzz "github.com/google/gofuzz"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
)
var _ = Describe("Client", func() {
Context("handleResponse func", func() {
var (
fuzzer = fuzz.New().NilChance(0)
statusCode int
resp sendResponse
respBody []byte
expectedErr error
)
When("status code is success - 2XX", func() {
It("should succeed", func() {
statusCode = 200
err := handleResponse(statusCode, respBody)
Ω(err).Should(Succeed())
})
})
When("status code not success != 2XX", func() {
BeforeEach(func() {
statusCode = 403
})
When("error field is missing in the sendResponse", func() {
It("should succeed", func() {
respBody = []byte(`{"field":"value"}`)
expectedErr = fmt.Errorf(`empty error in sendResponse for status code 403: %s`, string(respBody))
err := handleResponse(statusCode, respBody)
Ω(err).Should(Equal(expectedErr))
})
})
When("sendResponse body is like expected format", func() {
BeforeEach(func() {
fuzzer.Fuzz(&resp)
})
JustBeforeEach(func() {
data, err := resp.MarshalJSON()
Ω(err).ShouldNot(HaveOccurred())
respBody = data
})
When("errorDetails are missing in sendResponse", func() {
BeforeEach(func() {
resp.Error.Details = nil
})
It("should return general error", func() {
expectedErr = fmt.Errorf("unsuccessful sendResponse with status code: %d: %v",
statusCode, string(respBody))
err := handleResponse(statusCode, respBody)
Ω(err).Should(Equal(expectedErr))
})
})
When("errorDetails contain unregistered error code", func() {
BeforeEach(func() {
resp.Error.Details = []errorDetails{
{
ErrorCode: errorCodeUnregistered,
},
}
})
It("should return unregistered error", func() {
err := handleResponse(statusCode, respBody)
Ω(err).Should(Equal(ErrUnregistered))
})
})
When("errorDetails contain unspecified error code", func() {
BeforeEach(func() {
resp.Error.Details = []errorDetails{
{
ErrorCode: errorCodeUnspecified,
},
}
})
It("should return general error", func() {
expectedErr = fmt.Errorf("unsuccessful sendResponse with status code: %d: %s",
statusCode, string(respBody))
err := handleResponse(statusCode, respBody)
Ω(err).Should(Equal(expectedErr))
})
})
})
})
})
})