Debian Codegraph @

fastly/condition_test.go

raw symbols ◀ ▶
Source reconstructed at patch state 0 of 1 — not the installed (fully patched) source.
1 Debian patch touch this file
1 package fastly
2
3 import "testing"
4
5 func TestClient_Conditions(t *testing.T) {
6 t.Parallel()
7
8 var err error
9 var tv *Version
10 record(t, "conditions/version", func(c *Client) {
11 tv = testVersion(t, c)
12 })
13
14 // Create
15 var condition *Condition
16 record(t, "conditions/create", func(c *Client) {
17 condition, err = c.CreateCondition(&CreateConditionInput{
18 Service: testServiceID,
19 Version: tv.Number,
20 Name: "test/condition",
21 Statement: "req.url~+\"index.html\"",
22 Type: "REQUEST",
23 Priority: 1,
24 })
25 })
26 if err != nil {
27 t.Fatal(err)
28 }
29
30 // // Ensure deleted
31 defer func() {
32 record(t, "conditions/cleanup", func(c *Client) {
33 c.DeleteCondition(&DeleteConditionInput{
34 Service: testServiceID,
35 Version: tv.Number,
36 Name: "test/condition",
37 })
38 })
39 }()
40
41 if condition.Name != "test/condition" {
42 t.Errorf("bad name: %q", condition.Name)
43 }
44 if condition.Statement != "req.url~+\"index.html\"" {
45 t.Errorf("bad statement: %q", condition.Statement)
46 }
47 if condition.Type != "REQUEST" {
48 t.Errorf("bad type: %s", condition.Type)
49 }
50 if condition.Priority != 1 {
51 t.Errorf("bad priority: %d", condition.Priority)
52 }
53
54 // List
55 var conditions []*Condition
56 record(t, "conditions/list", func(c *Client) {
57 conditions, err = c.ListConditions(&ListConditionsInput{
58 Service: testServiceID,
59 Version: tv.Number,
60 })
61 })
62 if err != nil {
63 t.Fatal(err)
64 }
65 if len(conditions) < 1 {
66 t.Errorf("bad conditions: %v", conditions)
67 }
68
69 // Get
70 var newCondition *Condition
71 record(t, "conditions/get", func(c *Client) {
72 newCondition, err = c.GetCondition(&GetConditionInput{
73 Service: testServiceID,
74 Version: tv.Number,
75 Name: "test/condition",
76 })
77 })
78 if err != nil {
79 t.Fatal(err)
80 }
81 if condition.Name != newCondition.Name {
82 t.Errorf("bad name: %q (%q)", condition.Name, newCondition.Name)
83 }
84 if condition.Statement != "req.url~+\"index.html\"" {
85 t.Errorf("bad statement: %q", condition.Statement)
86 }
87 if condition.Type != "REQUEST" {
88 t.Errorf("bad type: %s", condition.Type)
89 }
90 if condition.Priority != 1 {
91 t.Errorf("bad priority: %d", condition.Priority)
92 }
93
94 // Update
95 var updatedCondition *Condition
96 record(t, "conditions/update", func(c *Client) {
97 updatedCondition, err = c.UpdateCondition(&UpdateConditionInput{
98 Service: testServiceID,
99 Version: tv.Number,
100 Name: "test/condition",
101 Statement: "req.url~+\"updated.html\"",
102 })
103 })
104 if err != nil {
105 t.Fatal(err)
106 }
107 if updatedCondition.Statement != "req.url~+\"updated.html\"" {
108 t.Errorf("bad statement: %q", updatedCondition.Statement)
109 }
110
111 // Delete
112 record(t, "conditions/delete", func(c *Client) {
113 err = c.DeleteCondition(&DeleteConditionInput{
114 Service: testServiceID,
115 Version: tv.Number,
116 Name: "test/condition",
117 })
118 })
119 if err != nil {
120 t.Fatal(err)
121 }
122 }
123
124 func TestClient_ListConditions_validation(t *testing.T) {
125 var err error
126 _, err = testClient.ListConditions(&ListConditionsInput{
127 Service: "",
128 })
129 if err != ErrMissingService {
130 t.Errorf("bad error: %s", err)
131 }
132
133 _, err = testClient.ListConditions(&ListConditionsInput{
134 Service: "foo",
135 Version: 0,
136 })
137 if err != ErrMissingVersion {
138 t.Errorf("bad error: %s", err)
139 }
140 }
141
142 func TestClient_CreateCondition_validation(t *testing.T) {
143 var err error
144 _, err = testClient.CreateCondition(&CreateConditionInput{
145 Service: "",
146 })
147 if err != ErrMissingService {
148 t.Errorf("bad error: %s", err)
149 }
150
151 _, err = testClient.CreateCondition(&CreateConditionInput{
152 Service: "foo",
153 Version: 0,
154 })
155 if err != ErrMissingVersion {
156 t.Errorf("bad error: %s", err)
157 }
158 }
159
160 func TestClient_GetCondition_validation(t *testing.T) {
161 var err error
162 _, err = testClient.GetCondition(&GetConditionInput{
163 Service: "",
164 })
165 if err != ErrMissingService {
166 t.Errorf("bad error: %s", err)
167 }
168
169 _, err = testClient.GetCondition(&GetConditionInput{
170 Service: "foo",
171 Version: 0,
172 })
173 if err != ErrMissingVersion {
174 t.Errorf("bad error: %s", err)
175 }
176
177 _, err = testClient.GetCondition(&GetConditionInput{
178 Service: "foo",
179 Version: 1,
180 Name: "",
181 })
182 if err != ErrMissingName {
183 t.Errorf("bad error: %s", err)
184 }
185 }
186
187 func TestClient_UpdateCondition_validation(t *testing.T) {
188 var err error
189 _, err = testClient.UpdateCondition(&UpdateConditionInput{
190 Service: "",
191 })
192 if err != ErrMissingService {
193 t.Errorf("bad error: %s", err)
194 }
195
196 _, err = testClient.UpdateCondition(&UpdateConditionInput{
197 Service: "foo",
198 Version: 0,
199 })
200 if err != ErrMissingVersion {
201 t.Errorf("bad error: %s", err)
202 }
203
204 _, err = testClient.UpdateCondition(&UpdateConditionInput{
205 Service: "foo",
206 Version: 1,
207 Name: "",
208 })
209 if err != ErrMissingName {
210 t.Errorf("bad error: %s", err)
211 }
212 }
213
214 func TestClient_DeleteCondition_validation(t *testing.T) {
215 var err error
216 err = testClient.DeleteCondition(&DeleteConditionInput{
217 Service: "",
218 })
219 if err != ErrMissingService {
220 t.Errorf("bad error: %s", err)
221 }
222
223 err = testClient.DeleteCondition(&DeleteConditionInput{
224 Service: "foo",
225 Version: 0,
226 })
227 if err != ErrMissingVersion {
228 t.Errorf("bad error: %s", err)
229 }
230
231 err = testClient.DeleteCondition(&DeleteConditionInput{
232 Service: "foo",
233 Version: 1,
234 Name: "",
235 })
236 if err != ErrMissingName {
237 t.Errorf("bad error: %s", err)
238 }
239 }