-
Notifications
You must be signed in to change notification settings - Fork 2
/
schedule_test.go
183 lines (162 loc) · 4.15 KB
/
schedule_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
package runscope
import (
"net/http"
"testing"
)
func TestListSchedules(t *testing.T) {
setup()
defer teardown()
path := "/buckets/1/tests/1/schedules"
responseCode := http.StatusOK
responseData := `
{
"data": [
{
"environment_id": "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
"interval": "1h",
"note": "Staging Environment",
"id": "084e6df7-9165-46d2-9e1c-b87ccfc53d18"
},
{
"environment_id": "5e70db57-7485-4ca9-bb4d-482416993ddd",
"interval": "5m",
"note": "Production Monitoring",
"id": "c60e5a78-0dbd-493a-9e99-9a8282935d0c"
}
],
"error": null,
"meta": {
"status": "success"
}
}`
want := []Schedule{
Schedule{
ID: "084e6df7-9165-46d2-9e1c-b87ccfc53d18",
EnvironmentID: "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
Interval: "1h",
Note: "Staging Environment",
},
Schedule{
ID: "c60e5a78-0dbd-493a-9e99-9a8282935d0c",
EnvironmentID: "5e70db57-7485-4ca9-bb4d-482416993ddd",
Interval: "5m",
Note: "Production Monitoring",
},
}
handleGet(t, path, responseCode, responseData)
result, err := client.ListSchedules("1", "1")
if err != nil {
t.Errorf("ListSchedules returned error: %v", err)
}
testResponseData(t, result, want)
}
func TestGetSchedule(t *testing.T) {
setup()
defer teardown()
path := "/buckets/1/tests/1/schedules/1"
responseCode := http.StatusOK
responseData := `
{
"data": {
"environment_id": "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
"interval": "1h",
"note": "Staging Environment",
"id": "084e6df7-9165-46d2-9e1c-b87ccfc53d18"
},
"error": null,
"meta": {
"status": "success"
}
}`
want := Schedule{
ID: "084e6df7-9165-46d2-9e1c-b87ccfc53d18",
Note: "Staging Environment",
EnvironmentID: "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
Interval: "1h",
}
handleGet(t, path, responseCode, responseData)
result, err := client.GetSchedule("1", "1", "1")
if err != nil {
t.Errorf("GetSchedule returned error: %v", err)
}
testResponseData(t, result, want)
}
func TestNewSchedule(t *testing.T) {
setup()
defer teardown()
path := "/buckets/1/tests/1/schedules"
request := Schedule{
Interval: "6h",
EnvironmentID: "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
}
responseCode := http.StatusCreated
responseData := `
{
"data": {
"environment_id": "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
"interval": "6h",
"note": "",
"id": "084e6df7-9165-46d2-9e1c-b87ccfc53d18"
},
"error": null,
"meta": {
"status": "success"
}
}`
want := Schedule{
ID: "084e6df7-9165-46d2-9e1c-b87ccfc53d18",
EnvironmentID: "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
Interval: "6h",
}
handlePost(t, path, responseCode, responseData, new(Schedule), request)
result, err := client.NewSchedule("1", "1", request)
if err != nil {
t.Errorf("NewSchedule returned error: %v", err)
}
testResponseData(t, result, want)
}
func TestUpdateSchedule(t *testing.T) {
setup()
defer teardown()
path := "/buckets/1/tests/1/schedules/1"
request := Schedule{
ID: "084e6df7-9165-46d2-9e1c-b87ccfc53d18",
EnvironmentID: "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
Interval: "12h",
}
responseCode := http.StatusOK
responseData := `
{
"data": {
"environment_id": "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
"interval": "12h",
"note": "",
"id": "084e6df7-9165-46d2-9e1c-b87ccfc53d18"
},
"meta": {
"status": "success"
}
}`
want := Schedule{
ID: "084e6df7-9165-46d2-9e1c-b87ccfc53d18",
EnvironmentID: "1eeb3695-5d0f-467c-9d51-8b773dce29ba",
Interval: "12h",
}
handlePut(t, path, responseCode, responseData, new(Schedule), request)
result, err := client.UpdateSchedule("1", "1", "1", request)
if err != nil {
t.Errorf("UpdateSchedule returned error: %v", err)
}
testResponseData(t, result, want)
}
func TestDeleteSchedule(t *testing.T) {
setup()
defer teardown()
path := "/buckets/1/tests/1/schedules/1"
responseCode := http.StatusNoContent
handleDelete(t, path, responseCode)
err := client.DeleteSchedule("1", "1", "1")
if err != nil {
t.Errorf("DeleteSchedule returned error: %v", err)
}
}