forked from fastly/go-fastly
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdirector_backend_test.go
172 lines (153 loc) · 3.63 KB
/
director_backend_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
package fastly
import "testing"
func TestClient_DirectorBackends(t *testing.T) {
t.Parallel()
var err error
var tv *Version
record(t, "director_backends/version", func(c *Client) {
tv = testVersion(t, c)
})
// Create
var b *DirectorBackend
record(t, "director_backends/create", func(c *Client) {
b, err = c.CreateDirectorBackend(&CreateDirectorBackendInput{
Service: testServiceID,
Version: tv.Number,
Director: "director",
Backend: "backend",
})
})
if err != nil {
t.Fatal(err)
}
// Ensure deleted
defer func() {
record(t, "director_backends/cleanup", func(c *Client) {
c.DeleteDirectorBackend(&DeleteDirectorBackendInput{
Service: testServiceID,
Version: tv.Number,
Director: "director",
Backend: "backend",
})
})
}()
if b.Director != "director" {
t.Errorf("bad director: %q", b.Director)
}
if b.Backend != "backend" {
t.Errorf("bad backend: %q", b.Backend)
}
// Get
var nb *DirectorBackend
record(t, "director_backends/get", func(c *Client) {
nb, err = c.GetDirectorBackend(&GetDirectorBackendInput{
Service: testServiceID,
Version: tv.Number,
Director: "director",
Backend: "backend",
})
})
if err != nil {
t.Fatal(err)
}
if b.Director != nb.Director {
t.Errorf("bad director: %q", b.Director)
}
if b.Backend != nb.Backend {
t.Errorf("bad backend: %q", b.Backend)
}
// Delete
record(t, "director_backends/delete", func(c *Client) {
err = c.DeleteDirectorBackend(&DeleteDirectorBackendInput{
Service: testServiceID,
Version: tv.Number,
Director: "director",
Backend: "backend",
})
})
if err != nil {
t.Fatal(err)
}
}
func TestClient_CreateDirectorBackend_validation(t *testing.T) {
var err error
_, err = testClient.CreateDirectorBackend(&CreateDirectorBackendInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.CreateDirectorBackend(&CreateDirectorBackendInput{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
}
func TestClient_GetDirectorBackend_validation(t *testing.T) {
var err error
_, err = testClient.GetDirectorBackend(&GetDirectorBackendInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetDirectorBackend(&GetDirectorBackendInput{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetDirectorBackend(&GetDirectorBackendInput{
Service: "foo",
Version: "1",
Director: "",
})
if err != ErrMissingDirector {
t.Errorf("bad error: %s", err)
}
_, err = testClient.GetDirectorBackend(&GetDirectorBackendInput{
Service: "foo",
Version: "1",
Director: "director",
Backend: "",
})
if err != ErrMissingBackend {
t.Errorf("bad error: %s", err)
}
}
func TestClient_DeleteDirectorBackend_validation(t *testing.T) {
var err error
err = testClient.DeleteDirectorBackend(&DeleteDirectorBackendInput{
Service: "",
})
if err != ErrMissingService {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteDirectorBackend(&DeleteDirectorBackendInput{
Service: "foo",
Version: "",
})
if err != ErrMissingVersion {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteDirectorBackend(&DeleteDirectorBackendInput{
Service: "foo",
Version: "1",
Director: "",
})
if err != ErrMissingDirector {
t.Errorf("bad error: %s", err)
}
err = testClient.DeleteDirectorBackend(&DeleteDirectorBackendInput{
Service: "foo",
Version: "1",
Director: "director",
Backend: "",
})
if err != ErrMissingBackend {
t.Errorf("bad error: %s", err)
}
}