Debian Codegraph @

fastly/dictionary_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_Dictionaries(t *testing.T) {
6 t.Parallel()
7
8 fixtureBase := "dictionaries/"
9
10 testVersion := createTestVersion(t, fixtureBase+"version", testServiceID)
11
12 // Create
13 var err error
14 var d *Dictionary
15 record(t, fixtureBase+"create", func(c *Client) {
16 d, err = c.CreateDictionary(&CreateDictionaryInput{
17 Service: testServiceID,
18 Version: testVersion.Number,
19 Name: "test_dictionary",
20 })
21 })
22 if err != nil {
23 t.Fatal(err)
24 }
25
26 // Ensure deleted
27 defer func() {
28 record(t, fixtureBase+"cleanup", func(c *Client) {
29 c.DeleteDictionary(&DeleteDictionaryInput{
30 Service: testServiceID,
31 Version: testVersion.Number,
32 Name: "test_dictionary",
33 })
34
35 c.DeleteDictionary(&DeleteDictionaryInput{
36 Service: testServiceID,
37 Version: testVersion.Number,
38 Name: "new_test_dictionary",
39 })
40 })
41 }()
42
43 if d.Name != "test_dictionary" {
44 t.Errorf("bad name: %q", d.Name)
45 }
46
47 // List
48 var ds []*Dictionary
49 record(t, fixtureBase+"list", func(c *Client) {
50 ds, err = c.ListDictionaries(&ListDictionariesInput{
51 Service: testServiceID,
52 Version: testVersion.Number,
53 })
54 })
55 if err != nil {
56 t.Fatal(err)
57 }
58 if len(ds) < 1 {
59 t.Errorf("bad dictionaries: %v", ds)
60 }
61
62 // Get
63 var nd *Dictionary
64 record(t, fixtureBase+"get", func(c *Client) {
65 nd, err = c.GetDictionary(&GetDictionaryInput{
66 Service: testServiceID,
67 Version: testVersion.Number,
68 Name: "test_dictionary",
69 })
70 })
71 if err != nil {
72 t.Fatal(err)
73 }
74 if d.Name != nd.Name {
75 t.Errorf("bad name: %q (%q)", d.Name, nd.Name)
76 }
77
78 // Update
79 var ud *Dictionary
80 record(t, fixtureBase+"update", func(c *Client) {
81 ud, err = c.UpdateDictionary(&UpdateDictionaryInput{
82 Service: testServiceID,
83 Version: testVersion.Number,
84 Name: "test_dictionary",
85 NewName: "new_test_dictionary",
86 })
87 })
88 if err != nil {
89 t.Fatal(err)
90 }
91 if ud.Name != "new_test_dictionary" {
92 t.Errorf("bad name: %q", ud.Name)
93 }
94
95 // Delete
96 record(t, fixtureBase+"delete", func(c *Client) {
97 err = c.DeleteDictionary(&DeleteDictionaryInput{
98 Service: testServiceID,
99 Version: testVersion.Number,
100 Name: "new_test_dictionary",
101 })
102 })
103 if err != nil {
104 t.Fatal(err)
105 }
106 }
107
108 func TestClient_ListDictionaries_validation(t *testing.T) {
109 var err error
110 _, err = testClient.ListDictionaries(&ListDictionariesInput{
111 Service: "",
112 })
113 if err != ErrMissingService {
114 t.Errorf("bad error: %s", err)
115 }
116
117 _, err = testClient.ListDictionaries(&ListDictionariesInput{
118 Service: "foo",
119 Version: 0,
120 })
121 if err != ErrMissingVersion {
122 t.Errorf("bad error: %s", err)
123 }
124 }
125
126 func TestClient_CreateDictionary_validation(t *testing.T) {
127 var err error
128 _, err = testClient.CreateDictionary(&CreateDictionaryInput{
129 Service: "",
130 })
131 if err != ErrMissingService {
132 t.Errorf("bad error: %s", err)
133 }
134
135 _, err = testClient.CreateDictionary(&CreateDictionaryInput{
136 Service: "foo",
137 Version: 0,
138 })
139 if err != ErrMissingVersion {
140 t.Errorf("bad error: %s", err)
141 }
142 }
143
144 func TestClient_GetDictionary_validation(t *testing.T) {
145 var err error
146 _, err = testClient.GetDictionary(&GetDictionaryInput{
147 Service: "",
148 })
149 if err != ErrMissingService {
150 t.Errorf("bad error: %s", err)
151 }
152
153 _, err = testClient.GetDictionary(&GetDictionaryInput{
154 Service: "foo",
155 Version: 0,
156 })
157 if err != ErrMissingVersion {
158 t.Errorf("bad error: %s", err)
159 }
160
161 _, err = testClient.GetDictionary(&GetDictionaryInput{
162 Service: "foo",
163 Version: 1,
164 Name: "",
165 })
166 if err != ErrMissingName {
167 t.Errorf("bad error: %s", err)
168 }
169 }
170
171 func TestClient_UpdateDictionary_validation(t *testing.T) {
172 var err error
173 _, err = testClient.UpdateDictionary(&UpdateDictionaryInput{
174 Service: "",
175 })
176 if err != ErrMissingService {
177 t.Errorf("bad error: %s", err)
178 }
179
180 _, err = testClient.UpdateDictionary(&UpdateDictionaryInput{
181 Service: "foo",
182 Version: 0,
183 })
184 if err != ErrMissingVersion {
185 t.Errorf("bad error: %s", err)
186 }
187
188 _, err = testClient.UpdateDictionary(&UpdateDictionaryInput{
189 Service: "foo",
190 Version: 1,
191 Name: "",
192 })
193 if err != ErrMissingName {
194 t.Errorf("bad error: %s", err)
195 }
196 }
197
198 func TestClient_DeleteDictionary_validation(t *testing.T) {
199 var err error
200 err = testClient.DeleteDictionary(&DeleteDictionaryInput{
201 Service: "",
202 })
203 if err != ErrMissingService {
204 t.Errorf("bad error: %s", err)
205 }
206
207 err = testClient.DeleteDictionary(&DeleteDictionaryInput{
208 Service: "foo",
209 Version: 0,
210 })
211 if err != ErrMissingVersion {
212 t.Errorf("bad error: %s", err)
213 }
214
215 err = testClient.DeleteDictionary(&DeleteDictionaryInput{
216 Service: "foo",
217 Version: 1,
218 Name: "",
219 })
220 if err != ErrMissingName {
221 t.Errorf("bad error: %s", err)
222 }
223 }