| 1 |
package fastly |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestClient_ACLs(t *testing.T) { |
| 6 |
t.Parallel() |
| 7 |
|
| 8 |
fixtureBase := "acls/" |
| 9 |
|
| 10 |
testVersion := createTestVersion(t, fixtureBase+"version", testServiceID) |
| 11 |
|
| 12 |
// Create |
| 13 |
var err error |
| 14 |
var a *ACL |
| 15 |
record(t, fixtureBase+"create", func(c *Client) { |
| 16 |
a, err = c.CreateACL(&CreateACLInput{ |
| 17 |
Service: testServiceID, |
| 18 |
Version: testVersion.Number, |
| 19 |
Name: "test_acl", |
| 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.DeleteACL(&DeleteACLInput{ |
| 30 |
Service: testServiceID, |
| 31 |
Version: testVersion.Number, |
| 32 |
Name: "test_acl", |
| 33 |
}) |
| 34 |
|
| 35 |
c.DeleteACL(&DeleteACLInput{ |
| 36 |
Service: testServiceID, |
| 37 |
Version: testVersion.Number, |
| 38 |
Name: "new_test_acl", |
| 39 |
}) |
| 40 |
}) |
| 41 |
}() |
| 42 |
|
| 43 |
if a.Name != "test_acl" { |
| 44 |
t.Errorf("bad name: %q", a.Name) |
| 45 |
} |
| 46 |
|
| 47 |
// List |
| 48 |
var as []*ACL |
| 49 |
record(t, fixtureBase+"list", func(c *Client) { |
| 50 |
as, err = c.ListACLs(&ListACLsInput{ |
| 51 |
Service: testServiceID, |
| 52 |
Version: testVersion.Number, |
| 53 |
}) |
| 54 |
}) |
| 55 |
if err != nil { |
| 56 |
t.Fatal(err) |
| 57 |
} |
| 58 |
if len(as) != 1 { |
| 59 |
t.Errorf("bad ACLs: %v", as) |
| 60 |
} |
| 61 |
|
| 62 |
// Get |
| 63 |
var na *ACL |
| 64 |
record(t, fixtureBase+"get", func(c *Client) { |
| 65 |
na, err = c.GetACL(&GetACLInput{ |
| 66 |
Service: testServiceID, |
| 67 |
Version: testVersion.Number, |
| 68 |
Name: "test_acl", |
| 69 |
}) |
| 70 |
}) |
| 71 |
if err != nil { |
| 72 |
t.Fatal(err) |
| 73 |
} |
| 74 |
if a.Name != na.Name { |
| 75 |
t.Errorf("bad name: %q (%q)", a.Name, na.Name) |
| 76 |
} |
| 77 |
|
| 78 |
// Update |
| 79 |
var ua *ACL |
| 80 |
record(t, fixtureBase+"update", func(c *Client) { |
| 81 |
ua, err = c.UpdateACL(&UpdateACLInput{ |
| 82 |
Service: testServiceID, |
| 83 |
Version: testVersion.Number, |
| 84 |
Name: "test_acl", |
| 85 |
NewName: "new_test_acl", |
| 86 |
}) |
| 87 |
}) |
| 88 |
if err != nil { |
| 89 |
t.Fatal(err) |
| 90 |
} |
| 91 |
if ua.Name != "new_test_acl" { |
| 92 |
t.Errorf("Bad name after update %s", ua.Name) |
| 93 |
} |
| 94 |
|
| 95 |
if a.ID != ua.ID { |
| 96 |
t.Errorf("bad ACL id: %q (%q)", a.ID, ua.ID) |
| 97 |
} |
| 98 |
|
| 99 |
// Delete |
| 100 |
record(t, fixtureBase+"delete", func(c *Client) { |
| 101 |
err = c.DeleteACL(&DeleteACLInput{ |
| 102 |
Service: testServiceID, |
| 103 |
Version: testVersion.Number, |
| 104 |
Name: "new_test_acl", |
| 105 |
}) |
| 106 |
}) |
| 107 |
if err != nil { |
| 108 |
t.Fatal(err) |
| 109 |
} |
| 110 |
|
| 111 |
} |
| 112 |
|
| 113 |
func TestClient_ListACLs_validation(t *testing.T) { |
| 114 |
var err error |
| 115 |
_, err = testClient.ListACLs(&ListACLsInput{ |
| 116 |
Service: "", |
| 117 |
}) |
| 118 |
if err != ErrMissingService { |
| 119 |
t.Errorf("bad error: %s", err) |
| 120 |
} |
| 121 |
|
| 122 |
_, err = testClient.ListACLs(&ListACLsInput{ |
| 123 |
Service: "foo", |
| 124 |
Version: 0, |
| 125 |
}) |
| 126 |
if err != ErrMissingVersion { |
| 127 |
t.Errorf("bad error: %s", err) |
| 128 |
} |
| 129 |
} |
| 130 |
|
| 131 |
func TestClient_CreateACL_validation(t *testing.T) { |
| 132 |
var err error |
| 133 |
_, err = testClient.CreateACL(&CreateACLInput{ |
| 134 |
Service: "", |
| 135 |
}) |
| 136 |
if err != ErrMissingService { |
| 137 |
t.Errorf("bad error: %s", err) |
| 138 |
} |
| 139 |
|
| 140 |
_, err = testClient.CreateACL(&CreateACLInput{ |
| 141 |
Service: "foo", |
| 142 |
Version: 0, |
| 143 |
}) |
| 144 |
if err != ErrMissingVersion { |
| 145 |
t.Errorf("bad error: %s", err) |
| 146 |
} |
| 147 |
} |
| 148 |
|
| 149 |
func TestClient_GetACL_validation(t *testing.T) { |
| 150 |
var err error |
| 151 |
_, err = testClient.GetACL(&GetACLInput{ |
| 152 |
Service: "", |
| 153 |
}) |
| 154 |
if err != ErrMissingService { |
| 155 |
t.Errorf("bad error: %s", err) |
| 156 |
} |
| 157 |
|
| 158 |
_, err = testClient.GetACL(&GetACLInput{ |
| 159 |
Service: "foo", |
| 160 |
Version: 0, |
| 161 |
}) |
| 162 |
if err != ErrMissingVersion { |
| 163 |
t.Errorf("bad error: %s", err) |
| 164 |
} |
| 165 |
|
| 166 |
_, err = testClient.GetACL(&GetACLInput{ |
| 167 |
Service: "foo", |
| 168 |
Version: 1, |
| 169 |
Name: "", |
| 170 |
}) |
| 171 |
if err != ErrMissingName { |
| 172 |
t.Errorf("bad error: %s", err) |
| 173 |
} |
| 174 |
} |
| 175 |
|
| 176 |
func TestClient_UpdateACL_validation(t *testing.T) { |
| 177 |
var err error |
| 178 |
_, err = testClient.UpdateACL(&UpdateACLInput{ |
| 179 |
Service: "", |
| 180 |
}) |
| 181 |
if err != ErrMissingService { |
| 182 |
t.Errorf("bad error: %s", err) |
| 183 |
} |
| 184 |
|
| 185 |
_, err = testClient.UpdateACL(&UpdateACLInput{ |
| 186 |
Service: "foo", |
| 187 |
Version: 0, |
| 188 |
}) |
| 189 |
if err != ErrMissingVersion { |
| 190 |
t.Errorf("bad error: %s", err) |
| 191 |
} |
| 192 |
|
| 193 |
_, err = testClient.UpdateACL(&UpdateACLInput{ |
| 194 |
Service: "foo", |
| 195 |
Version: 1, |
| 196 |
Name: "", |
| 197 |
}) |
| 198 |
if err != ErrMissingName { |
| 199 |
t.Errorf("bad error: %s", err) |
| 200 |
} |
| 201 |
_, err = testClient.UpdateACL(&UpdateACLInput{ |
| 202 |
Service: "foo", |
| 203 |
Version: 1, |
| 204 |
Name: "acl", |
| 205 |
NewName: "", |
| 206 |
}) |
| 207 |
if err != ErrMissingNewName { |
| 208 |
t.Errorf("bad error: %s", err) |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
func TestClient_DeleteACL_validation(t *testing.T) { |
| 213 |
var err error |
| 214 |
err = testClient.DeleteACL(&DeleteACLInput{ |
| 215 |
Service: "", |
| 216 |
}) |
| 217 |
if err != ErrMissingService { |
| 218 |
t.Errorf("bad error: %s", err) |
| 219 |
} |
| 220 |
|
| 221 |
err = testClient.DeleteACL(&DeleteACLInput{ |
| 222 |
Service: "foo", |
| 223 |
Version: 0, |
| 224 |
}) |
| 225 |
if err != ErrMissingVersion { |
| 226 |
t.Errorf("bad error: %s", err) |
| 227 |
} |
| 228 |
|
| 229 |
err = testClient.DeleteACL(&DeleteACLInput{ |
| 230 |
Service: "foo", |
| 231 |
Version: 1, |
| 232 |
Name: "", |
| 233 |
}) |
| 234 |
if err != ErrMissingName { |
| 235 |
t.Errorf("bad error: %s", err) |
| 236 |
} |
| 237 |
} |