-
-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathschedules_test.go
185 lines (159 loc) · 5.46 KB
/
schedules_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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
package cachet
import (
"fmt"
"net/http"
"reflect"
"testing"
)
func TestSchedulesService_GetAll(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/api/v1/schedules", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"meta":{"pagination":{"total":1,"count":1,"per_page":20,"current_page":1,"total_pages":1,"links":{"next_page":null,"previous_page":null}}},"data":[{"id":1,"name":"Schedule Name","status":2,"message":"Schedule Message","scheduled_at":"2015-08-01 12:30:00","completed_at":"2015-08-01 13:00:00","created_at":"2015-08-01 12:00:00","updated_at":"2015-08-01 12:00:00","components":[],"human_status":"Complete"}]}`)
})
queryParams := &SchedulesQueryParams{}
got, _, err := testClient.Schedules.GetAll(queryParams)
if err != nil {
t.Errorf("Schedules.GetAll returned error: %v", err)
}
expected := &ScheduleResponse{
Meta: Meta{
Pagination: Pagination{
Total: 1,
Count: 1,
PerPage: 20,
CurrentPage: 1,
TotalPages: 1,
Links: Links{
NextPage: "",
PreviousPage: "",
},
},
},
Schedules: []Schedule{
{
ID: 1,
Name: "Schedule Name",
Status: 2,
Message: "Schedule Message",
ScheduledAt: "2015-08-01 12:30:00",
CompletedAt: "2015-08-01 13:00:00",
CreatedAt: "2015-08-01 12:00:00",
UpdatedAt: "2015-08-01 12:00:00",
Components: []Component{},
HumanStatus: "Complete",
},
},
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Schedules.GetAll returned %+v, want %+v", got, expected)
}
}
func TestSchedulesService_Get(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/api/v1/schedules/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "GET")
fmt.Fprint(w, `{"data":{"id":1,"name":"Schedule Name","status":2,"message":"Schedule Message","scheduled_at":"2015-08-01 12:30:00","completed_at":"2015-08-01 13:00:00","created_at":"2015-08-01 12:00:00","updated_at":"2015-08-01 12:00:00","components":[],"human_status":"Complete"}}`)
})
got, _, err := testClient.Schedules.Get(1)
if err != nil {
t.Errorf("Schedules.Get returned error: %v", err)
}
expected := &Schedule{
ID: 1,
Name: "Schedule Name",
Status: 2,
Message: "Schedule Message",
ScheduledAt: "2015-08-01 12:30:00",
CompletedAt: "2015-08-01 13:00:00",
CreatedAt: "2015-08-01 12:00:00",
UpdatedAt: "2015-08-01 12:00:00",
Components: []Component{},
HumanStatus: "Complete",
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Schedules.Get returned %+v, want %+v", got, expected)
}
}
func TestSchedulesService_Create(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/api/v1/schedules", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "POST")
fmt.Fprint(w, `{"data":{"id":1,"name":"Schedule Name","status":2,"message":"Schedule Message","scheduled_at":"2015-08-01 12:30:00","completed_at":"2015-08-01 13:00:00","created_at":"2015-08-01 12:00:00","updated_at":"2015-08-01 12:00:00","components":[],"human_status":"Complete"}}`)
})
i := &Schedule{
Name: "Schedule Name",
Message: "Schedule Message",
Status: ScheduleComplete,
ScheduledAt: "2015-08-01 12:30:00",
CompletedAt: "2015-08-01 13:00:00",
Components: []Component{},
}
got, _, err := testClient.Schedules.Create(i)
if err != nil {
t.Errorf("Schedules.Create returned error: %v", err)
}
expected := &Schedule{
ID: 1,
Name: "Schedule Name",
Status: 2,
Message: "Schedule Message",
ScheduledAt: "2015-08-01 12:30:00",
CompletedAt: "2015-08-01 13:00:00",
CreatedAt: "2015-08-01 12:00:00",
UpdatedAt: "2015-08-01 12:00:00",
Components: []Component{},
HumanStatus: "Complete",
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Schedule.Create returned %+v, want %+v", got, expected)
}
}
func TestSchedulesService_Update(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/api/v1/schedules/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "PUT")
fmt.Fprint(w, `{"data":{"id":1,"name":"Schedule Name Update","status":2,"message":"Schedule Message","scheduled_at":"2015-08-01 12:30:00","completed_at":"2015-08-01 13:00:00","created_at":"2015-08-01 12:00:00","updated_at":"2015-08-01 12:00:00","components":[],"human_status":"Complete"}}`)
})
i := &Schedule{
Name: "Schedule Name Update",
}
got, _, err := testClient.Schedules.Update(1, i)
if err != nil {
t.Errorf("Schedules.Update returned error: %v", err)
}
expected := &Schedule{
ID: 1,
Name: "Schedule Name Update",
Status: 2,
Message: "Schedule Message",
ScheduledAt: "2015-08-01 12:30:00",
CompletedAt: "2015-08-01 13:00:00",
CreatedAt: "2015-08-01 12:00:00",
UpdatedAt: "2015-08-01 12:00:00",
Components: []Component{},
HumanStatus: "Complete",
}
if !reflect.DeepEqual(got, expected) {
t.Errorf("Schedules.Update returned %+v, want %+v", got, expected)
}
}
func TestSchedulesService_Delete(t *testing.T) {
setup()
defer teardown()
testMux.HandleFunc("/api/v1/schedules/1", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
w.WriteHeader(http.StatusNoContent)
})
resp, err := testClient.Schedules.Delete(1)
if err != nil {
t.Errorf("Schedules.Delete returned error: %v", err)
}
if resp.StatusCode != http.StatusNoContent {
t.Errorf("Schedules.Delete returned status %+v, want %+v", resp.StatusCode, http.StatusNoContent)
}
}