Debian Codegraph @

fastly/dictionary_item_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_DictionaryItems(t *testing.T) {
6
7 fixtureBase := "dictionary_items/"
8 nameSuffix := "DictionaryItems"
9
10 testService := createTestService(t, fixtureBase + "create_service", nameSuffix)
11 defer deleteTestService(t, fixtureBase +"delete_service", testService.ID)
12
13 testVersion := createTestVersion(t, fixtureBase+"version", testService.ID)
14
15 testDictionary := createTestDictionary(t, fixtureBase+"dictionary", testService.ID, testVersion.Number, nameSuffix)
16 defer deleteTestDictionary(t, testDictionary, fixtureBase+"delete_dictionary")
17
18 // Create
19 var err error
20 var createdDictionaryItem *DictionaryItem
21 record(t, fixtureBase+"create", func(c *Client) {
22 createdDictionaryItem, err = c.CreateDictionaryItem(&CreateDictionaryItemInput{
23 Service: testService.ID,
24 Dictionary: testDictionary.ID,
25 ItemKey: "test-dictionary-item",
26 ItemValue: "value",
27 })
28 })
29 if err != nil {
30 t.Fatal(err)
31 }
32
33 // Ensure deleted
34 defer func() {
35 record(t, fixtureBase+"cleanup", func(c *Client) {
36 c.DeleteDictionaryItem(&DeleteDictionaryItemInput{
37 Service: testService.ID,
38 Dictionary: testDictionary.ID,
39 ItemKey: "test-dictionary-item",
40 })
41 })
42 }()
43
44 if createdDictionaryItem.ItemKey != "test-dictionary-item" {
45 t.Errorf("bad item_key: %q", createdDictionaryItem.ItemKey)
46 }
47 if createdDictionaryItem.ItemValue != "value" {
48 t.Errorf("bad item_value: %q", createdDictionaryItem.ItemValue)
49 }
50
51 // List
52 var dictionaryItems []*DictionaryItem
53 record(t, fixtureBase+"list", func(c *Client) {
54 dictionaryItems, err = c.ListDictionaryItems(&ListDictionaryItemsInput{
55 Service: testService.ID,
56 Dictionary: testDictionary.ID,
57 })
58 })
59 if err != nil {
60 t.Fatal(err)
61 }
62 if len(dictionaryItems) < 1 {
63 t.Errorf("bad dictionary items: %v", dictionaryItems)
64 }
65
66 // Get
67 var retrievedDictionaryItem *DictionaryItem
68 record(t, fixtureBase+"get", func(c *Client) {
69 retrievedDictionaryItem, err = c.GetDictionaryItem(&GetDictionaryItemInput{
70 Service: testService.ID,
71 Dictionary: testDictionary.ID,
72 ItemKey: "test-dictionary-item",
73 })
74 })
75 if err != nil {
76 t.Fatal(err)
77 }
78 if retrievedDictionaryItem.ItemKey != "test-dictionary-item" {
79 t.Errorf("bad item_key: %q", retrievedDictionaryItem.ItemKey)
80 }
81 if retrievedDictionaryItem.ItemValue != "value" {
82 t.Errorf("bad item_value: %q", retrievedDictionaryItem.ItemValue)
83 }
84
85 // Update
86 var updatedDictionaryItem *DictionaryItem
87 record(t, fixtureBase+"update", func(c *Client) {
88 updatedDictionaryItem, err = c.UpdateDictionaryItem(&UpdateDictionaryItemInput{
89 Service: testService.ID,
90 Dictionary: testDictionary.ID,
91 ItemKey: "test-dictionary-item",
92 ItemValue: "new-value",
93 })
94 })
95 if err != nil {
96 t.Fatal(err)
97 }
98 if updatedDictionaryItem.ItemValue != "new-value" {
99 t.Errorf("bad item_value: %q", updatedDictionaryItem.ItemValue)
100 }
101
102 // Delete
103 record(t, fixtureBase+"delete", func(c *Client) {
104 err = c.DeleteDictionaryItem(&DeleteDictionaryItemInput{
105 Service: testService.ID,
106 Dictionary: testDictionary.ID,
107 ItemKey: "test-dictionary-item",
108 })
109 })
110 if err != nil {
111 t.Fatal(err)
112 }
113 }
114
115 func TestClient_ListDictionaryItems_validation(t *testing.T) {
116 var err error
117 _, err = testClient.ListDictionaryItems(&ListDictionaryItemsInput{
118 Service: "",
119 })
120 if err != ErrMissingService {
121 t.Errorf("bad error: %s", err)
122 }
123
124 _, err = testClient.ListDictionaryItems(&ListDictionaryItemsInput{
125 Service: "foo",
126 Dictionary: "",
127 })
128 if err != ErrMissingDictionary {
129 t.Errorf("bad error: %s", err)
130 }
131 }
132
133 func TestClient_CreateDictionaryItem_validation(t *testing.T) {
134 var err error
135 _, err = testClient.CreateDictionaryItem(&CreateDictionaryItemInput{
136 Service: "",
137 })
138 if err != ErrMissingService {
139 t.Errorf("bad error: %s", err)
140 }
141
142 _, err = testClient.CreateDictionaryItem(&CreateDictionaryItemInput{
143 Service: "foo",
144 Dictionary: "",
145 })
146 if err != ErrMissingDictionary {
147 t.Errorf("bad error: %s", err)
148 }
149 }
150
151 func TestClient_GetDictionaryItem_validation(t *testing.T) {
152 var err error
153 _, err = testClient.GetDictionaryItem(&GetDictionaryItemInput{
154 Service: "",
155 })
156 if err != ErrMissingService {
157 t.Errorf("bad error: %s", err)
158 }
159
160 _, err = testClient.GetDictionaryItem(&GetDictionaryItemInput{
161 Service: "foo",
162 Dictionary: "",
163 })
164 if err != ErrMissingDictionary {
165 t.Errorf("bad error: %s", err)
166 }
167
168 _, err = testClient.GetDictionaryItem(&GetDictionaryItemInput{
169 Service: "foo",
170 Dictionary: "test",
171 ItemKey: "",
172 })
173 if err != ErrMissingItemKey {
174 t.Errorf("bad error: %s", err)
175 }
176 }
177
178 func TestClient_UpdateDictionaryItem_validation(t *testing.T) {
179 var err error
180 _, err = testClient.UpdateDictionaryItem(&UpdateDictionaryItemInput{
181 Service: "",
182 })
183 if err != ErrMissingService {
184 t.Errorf("bad error: %s", err)
185 }
186
187 _, err = testClient.UpdateDictionaryItem(&UpdateDictionaryItemInput{
188 Service: "foo",
189 Dictionary: "",
190 })
191 if err != ErrMissingDictionary {
192 t.Errorf("bad error: %s", err)
193 }
194
195 _, err = testClient.UpdateDictionaryItem(&UpdateDictionaryItemInput{
196 Service: "foo",
197 Dictionary: "test",
198 ItemKey: "",
199 })
200 if err != ErrMissingItemKey {
201 t.Errorf("bad error: %s", err)
202 }
203 }
204
205 func TestClient_DeleteDictionaryItem_validation(t *testing.T) {
206 var err error
207 err = testClient.DeleteDictionaryItem(&DeleteDictionaryItemInput{
208 Service: "",
209 })
210 if err != ErrMissingService {
211 t.Errorf("bad error: %s", err)
212 }
213
214 err = testClient.DeleteDictionaryItem(&DeleteDictionaryItemInput{
215 Service: "foo",
216 Dictionary: "",
217 })
218 if err != ErrMissingDictionary {
219 t.Errorf("bad error: %s", err)
220 }
221
222 err = testClient.DeleteDictionaryItem(&DeleteDictionaryItemInput{
223 Service: "foo",
224 Dictionary: "test",
225 ItemKey: "",
226 })
227 if err != ErrMissingItemKey {
228 t.Errorf("bad error: %s", err)
229 }
230 }
231
232 func TestClient_BatchModifyDictionaryItem_validation(t *testing.T) {
233 var err error
234 err = testClient.BatchModifyDictionaryItems(&BatchModifyDictionaryItemsInput{
235 Service: "",
236 })
237 if err != ErrMissingService {
238 t.Errorf("bad error: %s", err)
239 }
240 err = testClient.BatchModifyDictionaryItems(&BatchModifyDictionaryItemsInput{
241 Service: "foo",
242 Dictionary: "",
243 })
244 if err != ErrMissingDictionary {
245 t.Errorf("bad error: %s", err)
246 }
247
248 oversizedDictionaryItems := make([]*BatchDictionaryItem, BatchModifyMaximumOperations+1)
249 err = testClient.BatchModifyDictionaryItems(&BatchModifyDictionaryItemsInput{
250 Service: "foo",
251 Dictionary: "bar",
252 Items: oversizedDictionaryItems,
253 })
254 if err != ErrBatchUpdateMaximumOperationsExceeded {
255 t.Errorf("bad error: %s", err)
256 }
257
258 }