Debian Codegraph @

fastly/gzip_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_Gzips(t *testing.T) {
6 t.Parallel()
7
8 var err error
9 var tv *Version
10 record(t, "gzips/version", func(c *Client) {
11 tv = testVersion(t, c)
12 })
13
14 // Create
15 var gzip *Gzip
16 record(t, "gzips/create", func(c *Client) {
17 gzip, err = c.CreateGzip(&CreateGzipInput{
18 Service: testServiceID,
19 Version: tv.Number,
20 Name: "test-gzip",
21 ContentTypes: "text/html text/css",
22 Extensions: "html css",
23 })
24 })
25 if err != nil {
26 t.Fatal(err)
27 }
28
29 // Create omissions (GH-7)
30 var gzipomit *Gzip
31 record(t, "gzips/create_omissions", func(c *Client) {
32 gzipomit, err = c.CreateGzip(&CreateGzipInput{
33 Service: testServiceID,
34 Version: tv.Number,
35 Name: "test-gzip-omit",
36 })
37 })
38 if err != nil {
39 t.Fatal(err)
40 }
41 if gzipomit.ContentTypes != "" {
42 t.Errorf("bad content_types: %q", gzipomit.ContentTypes)
43 }
44 if gzipomit.Extensions != "" {
45 t.Errorf("bad extensions: %q", gzipomit.Extensions)
46 }
47
48 // Ensure deleted
49 defer func() {
50 record(t, "gzips/cleanup", func(c *Client) {
51 c.DeleteGzip(&DeleteGzipInput{
52 Service: testServiceID,
53 Version: tv.Number,
54 Name: "test-gzip",
55 })
56
57 c.DeleteGzip(&DeleteGzipInput{
58 Service: testServiceID,
59 Version: tv.Number,
60 Name: "test-gzip-omit",
61 })
62
63 c.DeleteGzip(&DeleteGzipInput{
64 Service: testServiceID,
65 Version: tv.Number,
66 Name: "new-test-gzip",
67 })
68 })
69 }()
70
71 if gzip.Name != "test-gzip" {
72 t.Errorf("bad name: %q", gzip.Name)
73 }
74 if gzip.ContentTypes != "text/html text/css" {
75 t.Errorf("bad content_types: %q", gzip.ContentTypes)
76 }
77 if gzip.Extensions != "html css" {
78 t.Errorf("bad extensions: %q", gzip.Extensions)
79 }
80
81 // List
82 var gzips []*Gzip
83 record(t, "gzips/list", func(c *Client) {
84 gzips, err = c.ListGzips(&ListGzipsInput{
85 Service: testServiceID,
86 Version: tv.Number,
87 })
88 })
89 if err != nil {
90 t.Fatal(err)
91 }
92 if len(gzips) < 1 {
93 t.Errorf("bad gzips: %v", gzips)
94 }
95
96 // Get
97 var ngzip *Gzip
98 record(t, "gzips/get", func(c *Client) {
99 ngzip, err = c.GetGzip(&GetGzipInput{
100 Service: testServiceID,
101 Version: tv.Number,
102 Name: "test-gzip",
103 })
104 })
105 if err != nil {
106 t.Fatal(err)
107 }
108 if ngzip.Name != gzip.Name {
109 t.Errorf("bad name: %q", ngzip.Name)
110 }
111 if ngzip.ContentTypes != gzip.ContentTypes {
112 t.Errorf("bad content_types: %q", ngzip.ContentTypes)
113 }
114 if ngzip.Extensions != gzip.Extensions {
115 t.Errorf("bad extensions: %q", ngzip.Extensions)
116 }
117
118 // Update
119 var ugzip *Gzip
120 record(t, "gzips/update", func(c *Client) {
121 ugzip, err = c.UpdateGzip(&UpdateGzipInput{
122 Service: testServiceID,
123 Version: tv.Number,
124 Name: "test-gzip",
125 NewName: "new-test-gzip",
126 })
127 })
128 if err != nil {
129 t.Fatal(err)
130 }
131 if ugzip.Name != "new-test-gzip" {
132 t.Errorf("bad name: %q", ugzip.Name)
133 }
134
135 // Delete
136 record(t, "gzips/delete", func(c *Client) {
137 err = c.DeleteGzip(&DeleteGzipInput{
138 Service: testServiceID,
139 Version: tv.Number,
140 Name: "new-test-gzip",
141 })
142 })
143 if err != nil {
144 t.Fatal(err)
145 }
146 }
147
148 func TestClient_ListGzips_validation(t *testing.T) {
149 var err error
150 _, err = testClient.ListGzips(&ListGzipsInput{
151 Service: "",
152 })
153 if err != ErrMissingService {
154 t.Errorf("bad error: %s", err)
155 }
156
157 _, err = testClient.ListGzips(&ListGzipsInput{
158 Service: "foo",
159 Version: 0,
160 })
161 if err != ErrMissingVersion {
162 t.Errorf("bad error: %s", err)
163 }
164 }
165
166 func TestClient_CreateGzip_validation(t *testing.T) {
167 var err error
168 _, err = testClient.CreateGzip(&CreateGzipInput{
169 Service: "",
170 })
171 if err != ErrMissingService {
172 t.Errorf("bad error: %s", err)
173 }
174
175 _, err = testClient.CreateGzip(&CreateGzipInput{
176 Service: "foo",
177 Version: 0,
178 })
179 if err != ErrMissingVersion {
180 t.Errorf("bad error: %s", err)
181 }
182 }
183
184 func TestClient_GetGzip_validation(t *testing.T) {
185 var err error
186 _, err = testClient.GetGzip(&GetGzipInput{
187 Service: "",
188 })
189 if err != ErrMissingService {
190 t.Errorf("bad error: %s", err)
191 }
192
193 _, err = testClient.GetGzip(&GetGzipInput{
194 Service: "foo",
195 Version: 0,
196 })
197 if err != ErrMissingVersion {
198 t.Errorf("bad error: %s", err)
199 }
200
201 _, err = testClient.GetGzip(&GetGzipInput{
202 Service: "foo",
203 Version: 1,
204 Name: "",
205 })
206 if err != ErrMissingName {
207 t.Errorf("bad error: %s", err)
208 }
209 }
210
211 func TestClient_UpdateGzip_validation(t *testing.T) {
212 var err error
213 _, err = testClient.UpdateGzip(&UpdateGzipInput{
214 Service: "",
215 })
216 if err != ErrMissingService {
217 t.Errorf("bad error: %s", err)
218 }
219
220 _, err = testClient.UpdateGzip(&UpdateGzipInput{
221 Service: "foo",
222 Version: 0,
223 })
224 if err != ErrMissingVersion {
225 t.Errorf("bad error: %s", err)
226 }
227
228 _, err = testClient.UpdateGzip(&UpdateGzipInput{
229 Service: "foo",
230 Version: 1,
231 Name: "",
232 })
233 if err != ErrMissingName {
234 t.Errorf("bad error: %s", err)
235 }
236 }
237
238 func TestClient_DeleteGzip_validation(t *testing.T) {
239 var err error
240 err = testClient.DeleteGzip(&DeleteGzipInput{
241 Service: "",
242 })
243 if err != ErrMissingService {
244 t.Errorf("bad error: %s", err)
245 }
246
247 err = testClient.DeleteGzip(&DeleteGzipInput{
248 Service: "foo",
249 Version: 0,
250 })
251 if err != ErrMissingVersion {
252 t.Errorf("bad error: %s", err)
253 }
254
255 err = testClient.DeleteGzip(&DeleteGzipInput{
256 Service: "foo",
257 Version: 1,
258 Name: "",
259 })
260 if err != ErrMissingName {
261 t.Errorf("bad error: %s", err)
262 }
263 }