-
Notifications
You must be signed in to change notification settings - Fork 23
/
endpoints_test.go
106 lines (86 loc) · 2.39 KB
/
endpoints_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
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 plivo
import (
"errors"
"github.com/stretchr/testify/assert"
"testing"
)
func TestEndpointService_Create(t *testing.T) {
expectResponse("endpointCreateResponse.json", 202)
if _, err := client.Endpoints.Create(EndpointCreateParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.Endpoints.Create(EndpointCreateParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "POST", "Endpoint")
}
func TestEndpointService_Update(t *testing.T) {
expectResponse("endpointUpdateResponse.json", 202)
endpointId := "endpointId"
if _, err := client.Endpoints.Update(endpointId, EndpointUpdateParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.Endpoints.Update(endpointId, EndpointUpdateParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "POST", "Endpoint/%s", endpointId)
}
func TestEndpointService_List(t *testing.T) {
expectResponse("endpointListResponse.json", 200)
if _, err := client.Endpoints.List(EndpointListParams{}); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err := client.Endpoints.List(EndpointListParams{})
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Endpoint")
}
func TestEndpointService_Get(t *testing.T) {
expectResponse("endpointGetResponse.json", 200)
endpointId := "endpointId"
endpoint, err := client.Endpoints.Get(endpointId)
assert.Equal(t, endpoint.ID(), endpoint.EndpointID)
if err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
_, err = client.Endpoints.Get(endpointId)
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "GET", "Endpoint/%s", endpointId)
}
func TestEndpointService_Delete(t *testing.T) {
expectResponse("", 204)
endpointId := "endpointId"
if err := client.Endpoints.Delete(endpointId); err != nil {
panic(err)
}
cl := client.httpClient
client.httpClient = nil
err := client.Endpoints.Delete(endpointId)
if err == nil {
client.httpClient = cl
panic(errors.New("error expected"))
}
client.httpClient = cl
assertRequest(t, "DELETE", "Endpoint/%s", endpointId)
}