Debian Codegraph @

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