Debian Codegraph @

fastly/cache_setting_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_CacheSettings(t *testing.T) {
6 t.Parallel()
7
8 var err error
9 var tv *Version
10 record(t, "cache_settings/version", func(c *Client) {
11 tv = testVersion(t, c)
12 })
13
14 // Create
15 var cacheSetting *CacheSetting
16 record(t, "cache_settings/create", func(c *Client) {
17 cacheSetting, err = c.CreateCacheSetting(&CreateCacheSettingInput{
18 Service: testServiceID,
19 Version: tv.Number,
20 Name: "test-cache-setting",
21 Action: CacheSettingActionCache,
22 TTL: 1234,
23 StaleTTL: 1500,
24 })
25 })
26 if err != nil {
27 t.Fatal(err)
28 }
29
30 // Ensure deleted
31 defer func() {
32 record(t, "cache_settings/cleanup", func(c *Client) {
33 c.DeleteCacheSetting(&DeleteCacheSettingInput{
34 Service: testServiceID,
35 Version: tv.Number,
36 Name: "test-cache-setting",
37 })
38
39 c.DeleteCacheSetting(&DeleteCacheSettingInput{
40 Service: testServiceID,
41 Version: tv.Number,
42 Name: "new-test-cache-setting",
43 })
44 })
45 }()
46
47 if cacheSetting.Name != "test-cache-setting" {
48 t.Errorf("bad name: %q", cacheSetting.Name)
49 }
50 if cacheSetting.Action != CacheSettingActionCache {
51 t.Errorf("bad action: %q", cacheSetting.Action)
52 }
53 if cacheSetting.TTL != 1234 {
54 t.Errorf("bad ttl: %d", cacheSetting.TTL)
55 }
56 if cacheSetting.StaleTTL != 1500 {
57 t.Errorf("bad stale_ttl: %d", cacheSetting.StaleTTL)
58 }
59
60 // List
61 var cacheSettings []*CacheSetting
62 record(t, "cache_settings/list", func(c *Client) {
63 cacheSettings, err = c.ListCacheSettings(&ListCacheSettingsInput{
64 Service: testServiceID,
65 Version: tv.Number,
66 })
67 })
68 if err != nil {
69 t.Fatal(err)
70 }
71 if len(cacheSettings) < 1 {
72 t.Errorf("bad cache settings: %v", cacheSettings)
73 }
74
75 // Get
76 var newCacheSetting *CacheSetting
77 record(t, "cache_settings/get", func(c *Client) {
78 newCacheSetting, err = c.GetCacheSetting(&GetCacheSettingInput{
79 Service: testServiceID,
80 Version: tv.Number,
81 Name: "test-cache-setting",
82 })
83 })
84 if err != nil {
85 t.Fatal(err)
86 }
87 if cacheSetting.Name != newCacheSetting.Name {
88 t.Errorf("bad name: %q (%q)", cacheSetting.Name, newCacheSetting.Name)
89 }
90 if cacheSetting.Action != CacheSettingActionCache {
91 t.Errorf("bad action: %q", cacheSetting.Action)
92 }
93 if cacheSetting.TTL != 1234 {
94 t.Errorf("bad ttl: %d", cacheSetting.TTL)
95 }
96 if cacheSetting.StaleTTL != 1500 {
97 t.Errorf("bad stale_ttl: %d", cacheSetting.StaleTTL)
98 }
99
100 // Update
101 var updatedCacheSetting *CacheSetting
102 record(t, "cache_settings/update", func(c *Client) {
103 updatedCacheSetting, err = c.UpdateCacheSetting(&UpdateCacheSettingInput{
104 Service: testServiceID,
105 Version: tv.Number,
106 Name: "test-cache-setting",
107 NewName: "new-test-cache-setting",
108 })
109 })
110 if err != nil {
111 t.Fatal(err)
112 }
113 if updatedCacheSetting.Name != "new-test-cache-setting" {
114 t.Errorf("bad name: %q", updatedCacheSetting.Name)
115 }
116
117 // Delete
118 record(t, "cache_settings/delete", func(c *Client) {
119 err = c.DeleteCacheSetting(&DeleteCacheSettingInput{
120 Service: testServiceID,
121 Version: tv.Number,
122 Name: "new-test-cache-setting",
123 })
124 })
125 if err != nil {
126 t.Fatal(err)
127 }
128 }
129
130 func TestClient_ListCacheSettings_validation(t *testing.T) {
131 var err error
132 _, err = testClient.ListCacheSettings(&ListCacheSettingsInput{
133 Service: "",
134 })
135 if err != ErrMissingService {
136 t.Errorf("bad error: %s", err)
137 }
138
139 _, err = testClient.ListCacheSettings(&ListCacheSettingsInput{
140 Service: "foo",
141 Version: 0,
142 })
143 if err != ErrMissingVersion {
144 t.Errorf("bad error: %s", err)
145 }
146 }
147
148 func TestClient_CreateCacheSetting_validation(t *testing.T) {
149 var err error
150 _, err = testClient.CreateCacheSetting(&CreateCacheSettingInput{
151 Service: "",
152 })
153 if err != ErrMissingService {
154 t.Errorf("bad error: %s", err)
155 }
156
157 _, err = testClient.CreateCacheSetting(&CreateCacheSettingInput{
158 Service: "foo",
159 Version: 0,
160 })
161 if err != ErrMissingVersion {
162 t.Errorf("bad error: %s", err)
163 }
164 }
165
166 func TestClient_GetCacheSetting_validation(t *testing.T) {
167 var err error
168 _, err = testClient.GetCacheSetting(&GetCacheSettingInput{
169 Service: "",
170 })
171 if err != ErrMissingService {
172 t.Errorf("bad error: %s", err)
173 }
174
175 _, err = testClient.GetCacheSetting(&GetCacheSettingInput{
176 Service: "foo",
177 Version: 0,
178 })
179 if err != ErrMissingVersion {
180 t.Errorf("bad error: %s", err)
181 }
182
183 _, err = testClient.GetCacheSetting(&GetCacheSettingInput{
184 Service: "foo",
185 Version: 1,
186 Name: "",
187 })
188 if err != ErrMissingName {
189 t.Errorf("bad error: %s", err)
190 }
191 }
192
193 func TestClient_UpdateCacheSetting_validation(t *testing.T) {
194 var err error
195 _, err = testClient.UpdateCacheSetting(&UpdateCacheSettingInput{
196 Service: "",
197 })
198 if err != ErrMissingService {
199 t.Errorf("bad error: %s", err)
200 }
201
202 _, err = testClient.UpdateCacheSetting(&UpdateCacheSettingInput{
203 Service: "foo",
204 Version: 0,
205 })
206 if err != ErrMissingVersion {
207 t.Errorf("bad error: %s", err)
208 }
209
210 _, err = testClient.UpdateCacheSetting(&UpdateCacheSettingInput{
211 Service: "foo",
212 Version: 1,
213 Name: "",
214 })
215 if err != ErrMissingName {
216 t.Errorf("bad error: %s", err)
217 }
218 }
219
220 func TestClient_DeleteCacheSetting_validation(t *testing.T) {
221 var err error
222 err = testClient.DeleteCacheSetting(&DeleteCacheSettingInput{
223 Service: "",
224 })
225 if err != ErrMissingService {
226 t.Errorf("bad error: %s", err)
227 }
228
229 err = testClient.DeleteCacheSetting(&DeleteCacheSettingInput{
230 Service: "foo",
231 Version: 0,
232 })
233 if err != ErrMissingVersion {
234 t.Errorf("bad error: %s", err)
235 }
236
237 err = testClient.DeleteCacheSetting(&DeleteCacheSettingInput{
238 Service: "foo",
239 Version: 1,
240 Name: "",
241 })
242 if err != ErrMissingName {
243 t.Errorf("bad error: %s", err)
244 }
245 }