| 1 |
package fastly |
| 2 |
|
| 3 |
import "testing" |
| 4 |
|
| 5 |
func TestClient_BlobStorages(t *testing.T) { |
| 6 |
t.Parallel() |
| 7 |
|
| 8 |
var err error |
| 9 |
var tv *Version |
| 10 |
record(t, "blobstorages/version", func(c *Client) { |
| 11 |
tv = testVersion(t, c) |
| 12 |
}) |
| 13 |
|
| 14 |
// Create |
| 15 |
var bs *BlobStorage |
| 16 |
record(t, "blobstorages/create", func(c *Client) { |
| 17 |
bs, err = c.CreateBlobStorage(&CreateBlobStorageInput{ |
| 18 |
Service: testServiceID, |
| 19 |
Version: tv.Number, |
| 20 |
Name: "test-blobstorage", |
| 21 |
Path: "/logs", |
| 22 |
AccountName: "test", |
| 23 |
Container: "fastly", |
| 24 |
SASToken: "sv=2015-04-05&ss=b&srt=sco&sp=rw&se=2019-07-21T18%3A00%3A00Z&sig=3ABdLOJZosCp0o491T%2BqZGKIhafF1nlM3MzESDDD3Gg%3D", |
| 25 |
Period: 12, |
| 26 |
TimestampFormat: "%Y-%m-%dT%H:%M:%S.000", |
| 27 |
GzipLevel: 9, |
| 28 |
PublicKey: "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQENBFyUD8sBCACyFnB39AuuTygseek+eA4fo0cgwva6/FSjnWq7riouQee8GgQ/\nibXTRyv4iVlwI12GswvMTIy7zNvs1R54i0qvsLr+IZ4GVGJqs6ZJnvQcqe3xPoR4\n8AnBfw90o32r/LuHf6QCJXi+AEu35koNlNAvLJ2B+KACaNB7N0EeWmqpV/1V2k9p\nlDYk+th7LcCuaFNGqKS/PrMnnMqR6VDLCjHhNx4KR79b0Twm/2qp6an3hyNRu8Gn\ndwxpf1/BUu3JWf+LqkN4Y3mbOmSUL3MaJNvyQguUzTfS0P0uGuBDHrJCVkMZCzDB\n89ag55jCPHyGeHBTd02gHMWzsg3WMBWvCsrzABEBAAG0JXRlcnJhZm9ybSAodGVz\ndCkgPHRlc3RAdGVycmFmb3JtLmNvbT6JAU4EEwEIADgWI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c\nFaNmEfKKy/r1PO20NXEG6t9t05K/frHy6ZG8bCNYdpagfFVot47r9JaQqWlTNtIR\n5+zkkSq/eG9BEtRij3a6cTdQbktdBzx2KBeI0PYc1vlZR0LpuFKZqY9vlE6vTGLR\nwMfrTEOvx0NxUM3rpaCgEmuWbB1G1Hu371oyr4srrr+N\n=28dr\n-----END PGP PUBLIC KEY BLOCK-----\n", |
| 29 |
Format: "%h %l %u %{now}V %{req.method}V %{req.url}V %>s %{resp.http.Content-Length}V", |
| 30 |
FormatVersion: 2, |
| 31 |
MessageType: "classic", |
| 32 |
Placement: "waf_debug", |
| 33 |
}) |
| 34 |
}) |
| 35 |
if err != nil { |
| 36 |
t.Fatal(err) |
| 37 |
} |
| 38 |
|
| 39 |
// Ensure deleted |
| 40 |
defer func() { |
| 41 |
record(t, "blobstorages/cleanup", func(c *Client) { |
| 42 |
c.DeleteBlobStorage(&DeleteBlobStorageInput{ |
| 43 |
Service: testServiceID, |
| 44 |
Version: tv.Number, |
| 45 |
Name: "test-blobstorage", |
| 46 |
}) |
| 47 |
|
| 48 |
c.DeleteBlobStorage(&DeleteBlobStorageInput{ |
| 49 |
Service: testServiceID, |
| 50 |
Version: tv.Number, |
| 51 |
Name: "new-test-blobstorage", |
| 52 |
}) |
| 53 |
}) |
| 54 |
}() |
| 55 |
|
| 56 |
if bs.Name != "test-blobstorage" { |
| 57 |
t.Errorf("bad name: %q", bs.Name) |
| 58 |
} |
| 59 |
if bs.Path != "/logs" { |
| 60 |
t.Errorf("bad path: %q", bs.Path) |
| 61 |
} |
| 62 |
if bs.AccountName != "test" { |
| 63 |
t.Errorf("bad account_name: %q", bs.AccountName) |
| 64 |
} |
| 65 |
if bs.Container != "fastly" { |
| 66 |
t.Errorf("bad container: %q", bs.Container) |
| 67 |
} |
| 68 |
if bs.SASToken != "sv=2015-04-05&ss=b&srt=sco&sp=rw&se=2019-07-21T18%3A00%3A00Z&sig=3ABdLOJZosCp0o491T%2BqZGKIhafF1nlM3MzESDDD3Gg%3D" { |
| 69 |
t.Errorf("bad sas_token: %q", bs.SASToken) |
| 70 |
} |
| 71 |
if bs.Period != 12 { |
| 72 |
t.Errorf("bad period: %q", bs.Period) |
| 73 |
} |
| 74 |
if bs.TimestampFormat != "%Y-%m-%dT%H:%M:%S.000" { |
| 75 |
t.Errorf("bad timestamp_format: %q", bs.TimestampFormat) |
| 76 |
} |
| 77 |
if bs.GzipLevel != 9 { |
| 78 |
t.Errorf("bad gzip_level: %q", bs.GzipLevel) |
| 79 |
} |
| 80 |
if bs.PublicKey != "-----BEGIN PGP PUBLIC KEY BLOCK-----\n\nmQENBFyUD8sBCACyFnB39AuuTygseek+eA4fo0cgwva6/FSjnWq7riouQee8GgQ/\nibXTRyv4iVlwI12GswvMTIy7zNvs1R54i0qvsLr+IZ4GVGJqs6ZJnvQcqe3xPoR4\n8AnBfw90o32r/LuHf6QCJXi+AEu35koNlNAvLJ2B+KACaNB7N0EeWmqpV/1V2k9p\nlDYk+th7LcCuaFNGqKS/PrMnnMqR6VDLCjHhNx4KR79b0Twm/2qp6an3hyNRu8Gn\ndwxpf1/BUu3JWf+LqkN4Y3mbOmSUL3MaJNvyQguUzTfS0P0uGuBDHrJCVkMZCzDB\n89ag55jCPHyGeHBTd02gHMWzsg3WMBWvCsrzABEBAAG0JXRlcnJhZm9ybSAodGVz\ndCkgPHRlc3RAdGVycmFmb3JtLmNvbT6JAU4EEwEIADgWIQSHYyc6Kj9l6HzQsau6\nvFFc9jxV/wUCXJQPywIbAwULCQgHAgYVCgkICwIEFgIDAQIeAQIXgAAKCRC6vFFc\n9jxV/815CAClb32OxV7wG01yF97TzlyTl8TnvjMtoG29Mw4nSyg+mjM3b8N7iXm9\nOLX59fbDAWtBSldSZE22RXd3CvlFOG/EnKBXSjBtEqfyxYSnyOPkMPBYWGL/ApkX\nSvPYJ4LKdvipYToKFh3y9kk2gk1DcDBDyaaHvR+3rv1u3aoy7/s2EltAfDS3ZQIq\n7/cWTLJml/lleeB/Y6rPj8xqeCYhE5ahw9gsV/Mdqatl24V9Tks30iijx0Hhw+Gx\nkATUikMGr2GDVqoIRga5kXI7CzYff4rkc0Twn47fMHHHe/KY9M2yVnMHUXmAZwbG\nM1cMI/NH1DjevCKdGBLcRJlhuLPKF/anuQENBFyUD8sBCADIpd7r7GuPd6n/Ikxe\nu6h7umV6IIPoAm88xCYpTbSZiaK30Svh6Ywra9jfE2KlU9o6Y/art8ip0VJ3m07L\n4RSfSpnzqgSwdjSq5hNour2Fo/BzYhK7yaz2AzVSbe33R0+RYhb4b/6N+bKbjwGF\nftCsqVFMH+PyvYkLbvxyQrHlA9woAZaNThI1ztO5rGSnGUR8xt84eup28WIFKg0K\nUEGUcTzz+8QGAwAra+0ewPXo/AkO+8BvZjDidP417u6gpBHOJ9qYIcO9FxHeqFyu\nYrjlrxowEgXn5wO8xuNz6Vu1vhHGDHGDsRbZF8pv1d5O+0F1G7ttZ2GRRgVBZPwi\nkiyRABEBAAGJATYEGAEIACAWIQSHYyc6Kj9l6HzQsau6vFFc9jxV/wUCXJQPywIb\nDAAKCRC6vFFc9jxV/9YOCACe8qmOSnKQpQfW+PqYOqo3dt7JyweTs3FkD6NT8Zml\ndYy/vkstbTjPpX6aTvUZjkb46BVi7AOneVHpD5GBqvRsZ9iVgDYHaehmLCdKiG5L\n3Tp90NN+QY5WDbsGmsyk6+6ZMYejb4qYfweQeduOj27aavCJdLkCYMoRKfcFYI8c\nFaNmEfKKy/r1PO20NXEG6t9t05K/frHy6ZG8bCNYdpagfFVot47r9JaQqWlTNtIR\n5+zkkSq/eG9BEtRij3a6cTdQbktdBzx2KBeI0PYc1vlZR0LpuFKZqY9vlE6vTGLR\nwMfrTEOvx0NxUM3rpaCgEmuWbB1G1Hu371oyr4srrr+N\n=28dr\n-----END PGP PUBLIC KEY BLOCK-----\n" { |
| 81 |
t.Errorf("bad public_key: %q", bs.PublicKey) |
| 82 |
} |
| 83 |
if bs.Format != "%h %l %u %{now}V %{req.method}V %{req.url}V %>s %{resp.http.Content-Length}V" { |
| 84 |
t.Errorf("bad format: %q", bs.Format) |
| 85 |
} |
| 86 |
if bs.FormatVersion != 2 { |
| 87 |
t.Errorf("bad format_version: %q", bs.FormatVersion) |
| 88 |
} |
| 89 |
if bs.MessageType != "classic" { |
| 90 |
t.Errorf("bad message_type: %q", bs.MessageType) |
| 91 |
} |
| 92 |
if bs.Placement != "waf_debug" { |
| 93 |
t.Errorf("bad placement: %q", bs.Placement) |
| 94 |
} |
| 95 |
|
| 96 |
// List |
| 97 |
var bsl []*BlobStorage |
| 98 |
record(t, "blobstorages/list", func(c *Client) { |
| 99 |
bsl, err = c.ListBlobStorages(&ListBlobStoragesInput{ |
| 100 |
Service: testServiceID, |
| 101 |
Version: tv.Number, |
| 102 |
}) |
| 103 |
}) |
| 104 |
if err != nil { |
| 105 |
t.Fatal(err) |
| 106 |
} |
| 107 |
if len(bsl) < 1 { |
| 108 |
t.Errorf("bad blob storages: %v", bsl) |
| 109 |
} |
| 110 |
|
| 111 |
// Get |
| 112 |
var nbs *BlobStorage |
| 113 |
record(t, "blobstorages/get", func(c *Client) { |
| 114 |
nbs, err = c.GetBlobStorage(&GetBlobStorageInput{ |
| 115 |
Service: testServiceID, |
| 116 |
Version: tv.Number, |
| 117 |
Name: "test-blobstorage", |
| 118 |
}) |
| 119 |
}) |
| 120 |
if err != nil { |
| 121 |
t.Fatal(err) |
| 122 |
} |
| 123 |
if bs.Name != nbs.Name { |
| 124 |
t.Errorf("bad name: %q", bs.Name) |
| 125 |
} |
| 126 |
if bs.Path != nbs.Path { |
| 127 |
t.Errorf("bad path: %q", bs.Path) |
| 128 |
} |
| 129 |
if bs.AccountName != nbs.AccountName { |
| 130 |
t.Errorf("bad account_name: %q", bs.AccountName) |
| 131 |
} |
| 132 |
if bs.Container != nbs.Container { |
| 133 |
t.Errorf("bad container: %q", bs.Container) |
| 134 |
} |
| 135 |
if bs.SASToken != nbs.SASToken { |
| 136 |
t.Errorf("bad sas_token: %q", bs.SASToken) |
| 137 |
} |
| 138 |
if bs.Period != nbs.Period { |
| 139 |
t.Errorf("bad period: %q", bs.Period) |
| 140 |
} |
| 141 |
if bs.TimestampFormat != nbs.TimestampFormat { |
| 142 |
t.Errorf("bad timestamp_format: %q", bs.TimestampFormat) |
| 143 |
} |
| 144 |
if bs.GzipLevel != nbs.GzipLevel { |
| 145 |
t.Errorf("bad gzip_level: %q", bs.GzipLevel) |
| 146 |
} |
| 147 |
if bs.PublicKey != nbs.PublicKey { |
| 148 |
t.Errorf("bad public_key: %q", bs.PublicKey) |
| 149 |
} |
| 150 |
if bs.Format != nbs.Format { |
| 151 |
t.Errorf("bad format: %q", bs.Format) |
| 152 |
} |
| 153 |
if bs.FormatVersion != nbs.FormatVersion { |
| 154 |
t.Errorf("bad format_version: %q", bs.FormatVersion) |
| 155 |
} |
| 156 |
if bs.MessageType != nbs.MessageType { |
| 157 |
t.Errorf("bad message_type: %q", bs.MessageType) |
| 158 |
} |
| 159 |
if bs.Placement != nbs.Placement { |
| 160 |
t.Errorf("bad placement: %q", bs.Placement) |
| 161 |
} |
| 162 |
|
| 163 |
// Update |
| 164 |
var ubs *BlobStorage |
| 165 |
record(t, "blobstorages/update", func(c *Client) { |
| 166 |
ubs, err = c.UpdateBlobStorage(&UpdateBlobStorageInput{ |
| 167 |
Service: testServiceID, |
| 168 |
Version: tv.Number, |
| 169 |
Name: "test-blobstorage", |
| 170 |
NewName: "new-test-blobstorage", |
| 171 |
}) |
| 172 |
}) |
| 173 |
if err != nil { |
| 174 |
t.Fatal(err) |
| 175 |
} |
| 176 |
if ubs.Name != "new-test-blobstorage" { |
| 177 |
t.Errorf("bad name: %q", ubs.Name) |
| 178 |
} |
| 179 |
|
| 180 |
// Delete |
| 181 |
record(t, "blobstorages/delete", func(c *Client) { |
| 182 |
err = c.DeleteBlobStorage(&DeleteBlobStorageInput{ |
| 183 |
Service: testServiceID, |
| 184 |
Version: tv.Number, |
| 185 |
Name: "new-test-blobstorage", |
| 186 |
}) |
| 187 |
}) |
| 188 |
if err != nil { |
| 189 |
t.Fatal(err) |
| 190 |
} |
| 191 |
} |
| 192 |
|
| 193 |
func TestClient_ListBlobStorages_validation(t *testing.T) { |
| 194 |
var err error |
| 195 |
_, err = testClient.ListBlobStorages(&ListBlobStoragesInput{ |
| 196 |
Service: "", |
| 197 |
}) |
| 198 |
if err != ErrMissingService { |
| 199 |
t.Errorf("bad error: %s", err) |
| 200 |
} |
| 201 |
|
| 202 |
_, err = testClient.ListBlobStorages(&ListBlobStoragesInput{ |
| 203 |
Service: "foo", |
| 204 |
Version: 0, |
| 205 |
}) |
| 206 |
if err != ErrMissingVersion { |
| 207 |
t.Errorf("bad error: %s", err) |
| 208 |
} |
| 209 |
} |
| 210 |
|
| 211 |
func TestClient_CreateBlobStorage_validation(t *testing.T) { |
| 212 |
var err error |
| 213 |
_, err = testClient.CreateBlobStorage(&CreateBlobStorageInput{ |
| 214 |
Service: "", |
| 215 |
}) |
| 216 |
if err != ErrMissingService { |
| 217 |
t.Errorf("bad error: %s", err) |
| 218 |
} |
| 219 |
|
| 220 |
_, err = testClient.CreateBlobStorage(&CreateBlobStorageInput{ |
| 221 |
Service: "foo", |
| 222 |
Version: 0, |
| 223 |
}) |
| 224 |
if err != ErrMissingVersion { |
| 225 |
t.Errorf("bad error: %s", err) |
| 226 |
} |
| 227 |
} |
| 228 |
|
| 229 |
func TestClient_GetBlobStorage_validation(t *testing.T) { |
| 230 |
var err error |
| 231 |
_, err = testClient.GetBlobStorage(&GetBlobStorageInput{ |
| 232 |
Service: "", |
| 233 |
}) |
| 234 |
if err != ErrMissingService { |
| 235 |
t.Errorf("bad error: %s", err) |
| 236 |
} |
| 237 |
|
| 238 |
_, err = testClient.GetBlobStorage(&GetBlobStorageInput{ |
| 239 |
Service: "foo", |
| 240 |
Version: 0, |
| 241 |
}) |
| 242 |
if err != ErrMissingVersion { |
| 243 |
t.Errorf("bad error: %s", err) |
| 244 |
} |
| 245 |
|
| 246 |
_, err = testClient.GetBlobStorage(&GetBlobStorageInput{ |
| 247 |
Service: "foo", |
| 248 |
Version: 1, |
| 249 |
Name: "", |
| 250 |
}) |
| 251 |
if err != ErrMissingName { |
| 252 |
t.Errorf("bad error: %s", err) |
| 253 |
} |
| 254 |
} |
| 255 |
|
| 256 |
func TestClient_UpdateBlobStorage_validation(t *testing.T) { |
| 257 |
var err error |
| 258 |
_, err = testClient.UpdateBlobStorage(&UpdateBlobStorageInput{ |
| 259 |
Service: "", |
| 260 |
}) |
| 261 |
if err != ErrMissingService { |
| 262 |
t.Errorf("bad error: %s", err) |
| 263 |
} |
| 264 |
|
| 265 |
_, err = testClient.UpdateBlobStorage(&UpdateBlobStorageInput{ |
| 266 |
Service: "foo", |
| 267 |
Version: 0, |
| 268 |
}) |
| 269 |
if err != ErrMissingVersion { |
| 270 |
t.Errorf("bad error: %s", err) |
| 271 |
} |
| 272 |
|
| 273 |
_, err = testClient.UpdateBlobStorage(&UpdateBlobStorageInput{ |
| 274 |
Service: "foo", |
| 275 |
Version: 1, |
| 276 |
Name: "", |
| 277 |
}) |
| 278 |
if err != ErrMissingName { |
| 279 |
t.Errorf("bad error: %s", err) |
| 280 |
} |
| 281 |
} |
| 282 |
|
| 283 |
func TestClient_DeleteBlobStorage_validation(t *testing.T) { |
| 284 |
var err error |
| 285 |
err = testClient.DeleteBlobStorage(&DeleteBlobStorageInput{ |
| 286 |
Service: "", |
| 287 |
}) |
| 288 |
if err != ErrMissingService { |
| 289 |
t.Errorf("bad error: %s", err) |
| 290 |
} |
| 291 |
|
| 292 |
err = testClient.DeleteBlobStorage(&DeleteBlobStorageInput{ |
| 293 |
Service: "foo", |
| 294 |
Version: 0, |
| 295 |
}) |
| 296 |
if err != ErrMissingVersion { |
| 297 |
t.Errorf("bad error: %s", err) |
| 298 |
} |
| 299 |
|
| 300 |
err = testClient.DeleteBlobStorage(&DeleteBlobStorageInput{ |
| 301 |
Service: "foo", |
| 302 |
Version: 1, |
| 303 |
Name: "", |
| 304 |
}) |
| 305 |
if err != ErrMissingName { |
| 306 |
t.Errorf("bad error: %s", err) |
| 307 |
} |
| 308 |
} |