| 1 |
package fastly |
| 2 |
|
| 3 |
import ( |
| 4 |
"testing" |
| 5 |
) |
| 6 |
|
| 7 |
func TestClient_Bigqueries(t *testing.T) { |
| 8 |
t.Parallel() |
| 9 |
|
| 10 |
var err error |
| 11 |
var tv *Version |
| 12 |
record(t, "bigqueries/version", func(c *Client) { |
| 13 |
tv = testVersion(t, c) |
| 14 |
}) |
| 15 |
|
| 16 |
var secretKey string |
| 17 |
secretKey = privateKey() |
| 18 |
|
| 19 |
// Create |
| 20 |
var bq *BigQuery |
| 21 |
record(t, "bigqueries/create", func(c *Client) { |
| 22 |
bq, err = c.CreateBigQuery(&CreateBigQueryInput{ |
| 23 |
Service: testServiceID, |
| 24 |
Version: tv.Number, |
| 25 |
Name: "test-bigquery", |
| 26 |
ProjectID: "example-fastly-log", |
| 27 |
Dataset: "fastly_log_test", |
| 28 |
Table: "fastly_logs", |
| 29 |
Template: "", |
| 30 |
User: "[email protected]", |
| 31 |
SecretKey: secretKey, |
| 32 |
Format: "{\n \"timestamp\":\"%{begin:%Y-%m-%dT%H:%M:%S}t\",\n \"time_elapsed\":%{time.elapsed.usec}V,\n \"is_tls\":%{if(req.is_ssl, \"true\", \"false\")}V,\n \"client_ip\":\"%{req.http.Fastly-Client-IP}V\",\n \"geo_city\":\"%{client.geo.city}V\",\n \"geo_country_code\":\"%{client.geo.country_code}V\",\n \"request\":\"%{req.request}V\",\n \"host\":\"%{req.http.Fastly-Orig-Host}V\",\n \"url\":\"%{json.escape(req.url)}V\",\n \"request_referer\":\"%{json.escape(req.http.Referer)}V\",\n \"request_user_agent\":\"%{json.escape(req.http.User-Agent)}V\",\n \"request_accept_language\":\"%{json.escape(req.http.Accept-Language)}V\",\n \"request_accept_charset\":\"%{json.escape(req.http.Accept-Charset)}V\",\n \"cache_status\":\"%{regsub(fastly_info.state, \"^(HIT-(SYNTH)|(HITPASS|HIT|MISS|PASS|ERROR|PIPE)).*\", \"\\\\2\\\\3\") }V\"\n}", |
| 33 |
Placement: "waf_debug", |
| 34 |
FormatVersion: 2, |
| 35 |
}) |
| 36 |
}) |
| 37 |
if err != nil { |
| 38 |
t.Fatal(err) |
| 39 |
} |
| 40 |
|
| 41 |
// Ensure deleted |
| 42 |
defer func() { |
| 43 |
record(t, "bigqueries/cleanup", func(c *Client) { |
| 44 |
c.DeleteBigQuery(&DeleteBigQueryInput{ |
| 45 |
Service: testServiceID, |
| 46 |
Version: tv.Number, |
| 47 |
Name: "test-bigquery", |
| 48 |
}) |
| 49 |
|
| 50 |
c.DeleteBigQuery(&DeleteBigQueryInput{ |
| 51 |
Service: testServiceID, |
| 52 |
Version: tv.Number, |
| 53 |
Name: "new-test-bigquery", |
| 54 |
}) |
| 55 |
}) |
| 56 |
}() |
| 57 |
|
| 58 |
if bq.Name != "test-bigquery" { |
| 59 |
t.Errorf("bad name: %q", bq.Name) |
| 60 |
} |
| 61 |
if bq.ProjectID != "example-fastly-log" { |
| 62 |
t.Errorf("bad project_id: %q", bq.ProjectID) |
| 63 |
} |
| 64 |
if bq.Dataset != "fastly_log_test" { |
| 65 |
t.Errorf("bad dataset: %q", bq.Dataset) |
| 66 |
} |
| 67 |
if bq.Table != "fastly_logs" { |
| 68 |
t.Errorf("bad table: %q", bq.Table) |
| 69 |
} |
| 70 |
if bq.Template != "" { |
| 71 |
t.Errorf("bad template_suffix: %q", bq.Template) |
| 72 |
} |
| 73 |
if bq.User != "[email protected]" { |
| 74 |
t.Errorf("bad user: %q", bq.User) |
| 75 |
} |
| 76 |
if bq.SecretKey != secretKey { |
| 77 |
t.Errorf("bad secret_key: %q", bq.SecretKey) |
| 78 |
} |
| 79 |
if bq.Format != "{\n \"timestamp\":\"%{begin:%Y-%m-%dT%H:%M:%S}t\",\n \"time_elapsed\":%{time.elapsed.usec}V,\n \"is_tls\":%{if(req.is_ssl, \"true\", \"false\")}V,\n \"client_ip\":\"%{req.http.Fastly-Client-IP}V\",\n \"geo_city\":\"%{client.geo.city}V\",\n \"geo_country_code\":\"%{client.geo.country_code}V\",\n \"request\":\"%{req.request}V\",\n \"host\":\"%{req.http.Fastly-Orig-Host}V\",\n \"url\":\"%{json.escape(req.url)}V\",\n \"request_referer\":\"%{json.escape(req.http.Referer)}V\",\n \"request_user_agent\":\"%{json.escape(req.http.User-Agent)}V\",\n \"request_accept_language\":\"%{json.escape(req.http.Accept-Language)}V\",\n \"request_accept_charset\":\"%{json.escape(req.http.Accept-Charset)}V\",\n \"cache_status\":\"%{regsub(fastly_info.state, \"^(HIT-(SYNTH)|(HITPASS|HIT|MISS|PASS|ERROR|PIPE)).*\", \"\\\\2\\\\3\") }V\"\n}" { |
| 80 |
t.Errorf("bad format: %q", bq.Format) |
| 81 |
} |
| 82 |
if bq.ResponseCondition != "" { |
| 83 |
t.Errorf("bad response_condition: %q", bq.ResponseCondition) |
| 84 |
} |
| 85 |
if bq.Placement != "waf_debug" { |
| 86 |
t.Errorf("bad placement: %q", bq.Placement) |
| 87 |
} |
| 88 |
if bq.FormatVersion != 2 { |
| 89 |
t.Errorf("bad format_version: %q", bq.FormatVersion) |
| 90 |
} |
| 91 |
|
| 92 |
// List |
| 93 |
var bqs []*BigQuery |
| 94 |
record(t, "bigqueries/list", func(c *Client) { |
| 95 |
bqs, err = c.ListBigQueries(&ListBigQueriesInput{ |
| 96 |
Service: testServiceID, |
| 97 |
Version: tv.Number, |
| 98 |
}) |
| 99 |
}) |
| 100 |
if err != nil { |
| 101 |
t.Fatal(err) |
| 102 |
} |
| 103 |
if len(bqs) < 1 { |
| 104 |
t.Errorf("bad bigqueries: %v", bqs) |
| 105 |
} |
| 106 |
|
| 107 |
// Get |
| 108 |
var nbq *BigQuery |
| 109 |
record(t, "bigqueries/get", func(c *Client) { |
| 110 |
nbq, err = c.GetBigQuery(&GetBigQueryInput{ |
| 111 |
Service: testServiceID, |
| 112 |
Version: tv.Number, |
| 113 |
Name: "test-bigquery", |
| 114 |
}) |
| 115 |
}) |
| 116 |
if err != nil { |
| 117 |
t.Fatal(err) |
| 118 |
} |
| 119 |
if bq.Name != nbq.Name { |
| 120 |
t.Errorf("bad name: %q", bq.Name) |
| 121 |
} |
| 122 |
if bq.ProjectID != nbq.ProjectID { |
| 123 |
t.Errorf("bad project_id: %q", bq.ProjectID) |
| 124 |
} |
| 125 |
if bq.Dataset != nbq.Dataset { |
| 126 |
t.Errorf("bad dataset: %q", bq.Dataset) |
| 127 |
} |
| 128 |
if bq.Table != nbq.Table { |
| 129 |
t.Errorf("bad table: %q", bq.Table) |
| 130 |
} |
| 131 |
if bq.Template != nbq.Template { |
| 132 |
t.Errorf("bad template_suffix: %q", bq.Template) |
| 133 |
} |
| 134 |
if bq.User != nbq.User { |
| 135 |
t.Errorf("bad user: %q", bq.User) |
| 136 |
} |
| 137 |
if bq.SecretKey != nbq.SecretKey { |
| 138 |
t.Errorf("bad secret_key: %q", bq.SecretKey) |
| 139 |
} |
| 140 |
if bq.Format != nbq.Format { |
| 141 |
t.Errorf("bad format: %q", bq.Format) |
| 142 |
} |
| 143 |
if bq.ResponseCondition != nbq.ResponseCondition { |
| 144 |
t.Errorf("bad response_condition: %q", bq.ResponseCondition) |
| 145 |
} |
| 146 |
if bq.Placement != nbq.Placement { |
| 147 |
t.Errorf("bad placement: %q", bq.Placement) |
| 148 |
} |
| 149 |
if bq.FormatVersion != nbq.FormatVersion { |
| 150 |
t.Errorf("bad format_version: %q", bq.FormatVersion) |
| 151 |
} |
| 152 |
|
| 153 |
// Update |
| 154 |
var ubq *BigQuery |
| 155 |
record(t, "bigqueries/update", func(c *Client) { |
| 156 |
ubq, err = c.UpdateBigQuery(&UpdateBigQueryInput{ |
| 157 |
Service: testServiceID, |
| 158 |
Version: tv.Number, |
| 159 |
Name: "test-bigquery", |
| 160 |
NewName: "new-test-bigquery", |
| 161 |
}) |
| 162 |
}) |
| 163 |
if err != nil { |
| 164 |
t.Fatal(err) |
| 165 |
} |
| 166 |
if ubq.Name != "new-test-bigquery" { |
| 167 |
t.Errorf("bad name: %q", ubq.Name) |
| 168 |
} |
| 169 |
|
| 170 |
// Delete |
| 171 |
record(t, "bigqueries/delete", func(c *Client) { |
| 172 |
err = c.DeleteBigQuery(&DeleteBigQueryInput{ |
| 173 |
Service: testServiceID, |
| 174 |
Version: tv.Number, |
| 175 |
Name: "new-test-bigquery", |
| 176 |
}) |
| 177 |
}) |
| 178 |
if err != nil { |
| 179 |
t.Fatal(err) |
| 180 |
} |
| 181 |
} |
| 182 |
|
| 183 |
func TestClient_ListBigQueries_validation(t *testing.T) { |
| 184 |
var err error |
| 185 |
_, err = testClient.ListBigQueries(&ListBigQueriesInput{ |
| 186 |
Service: "", |
| 187 |
}) |
| 188 |
if err != ErrMissingService { |
| 189 |
t.Errorf("bad error: %s", err) |
| 190 |
} |
| 191 |
|
| 192 |
_, err = testClient.ListBigQueries(&ListBigQueriesInput{ |
| 193 |
Service: "foo", |
| 194 |
Version: 0, |
| 195 |
}) |
| 196 |
if err != ErrMissingVersion { |
| 197 |
t.Errorf("bad error: %s", err) |
| 198 |
} |
| 199 |
} |
| 200 |
|
| 201 |
func TestClient_CreateBigQuery_validation(t *testing.T) { |
| 202 |
var err error |
| 203 |
_, err = testClient.CreateBigQuery(&CreateBigQueryInput{ |
| 204 |
Service: "", |
| 205 |
}) |
| 206 |
if err != ErrMissingService { |
| 207 |
t.Errorf("bad error: %s", err) |
| 208 |
} |
| 209 |
|
| 210 |
_, err = testClient.CreateBigQuery(&CreateBigQueryInput{ |
| 211 |
Service: "foo", |
| 212 |
Version: 0, |
| 213 |
}) |
| 214 |
if err != ErrMissingVersion { |
| 215 |
t.Errorf("bad error: %s", err) |
| 216 |
} |
| 217 |
} |
| 218 |
|
| 219 |
func TestClient_GetBigQuery_validation(t *testing.T) { |
| 220 |
var err error |
| 221 |
_, err = testClient.GetBigQuery(&GetBigQueryInput{ |
| 222 |
Service: "", |
| 223 |
}) |
| 224 |
if err != ErrMissingService { |
| 225 |
t.Errorf("bad error: %s", err) |
| 226 |
} |
| 227 |
|
| 228 |
_, err = testClient.GetBigQuery(&GetBigQueryInput{ |
| 229 |
Service: "foo", |
| 230 |
Version: 0, |
| 231 |
}) |
| 232 |
if err != ErrMissingVersion { |
| 233 |
t.Errorf("bad error: %s", err) |
| 234 |
} |
| 235 |
|
| 236 |
_, err = testClient.GetBigQuery(&GetBigQueryInput{ |
| 237 |
Service: "foo", |
| 238 |
Version: 1, |
| 239 |
Name: "", |
| 240 |
}) |
| 241 |
if err != ErrMissingName { |
| 242 |
t.Errorf("bad error: %s", err) |
| 243 |
} |
| 244 |
} |
| 245 |
|
| 246 |
func TestClient_UpdateBigQuery_validation(t *testing.T) { |
| 247 |
var err error |
| 248 |
_, err = testClient.UpdateBigQuery(&UpdateBigQueryInput{ |
| 249 |
Service: "", |
| 250 |
}) |
| 251 |
if err != ErrMissingService { |
| 252 |
t.Errorf("bad error: %s", err) |
| 253 |
} |
| 254 |
|
| 255 |
_, err = testClient.UpdateBigQuery(&UpdateBigQueryInput{ |
| 256 |
Service: "foo", |
| 257 |
Version: 0, |
| 258 |
}) |
| 259 |
if err != ErrMissingVersion { |
| 260 |
t.Errorf("bad error: %s", err) |
| 261 |
} |
| 262 |
|
| 263 |
_, err = testClient.UpdateBigQuery(&UpdateBigQueryInput{ |
| 264 |
Service: "foo", |
| 265 |
Version: 1, |
| 266 |
Name: "", |
| 267 |
}) |
| 268 |
if err != ErrMissingName { |
| 269 |
t.Errorf("bad error: %s", err) |
| 270 |
} |
| 271 |
} |
| 272 |
|
| 273 |
func TestClient_DeleteBigQuery_validation(t *testing.T) { |
| 274 |
var err error |
| 275 |
err = testClient.DeleteBigQuery(&DeleteBigQueryInput{ |
| 276 |
Service: "", |
| 277 |
}) |
| 278 |
if err != ErrMissingService { |
| 279 |
t.Errorf("bad error: %s", err) |
| 280 |
} |
| 281 |
|
| 282 |
err = testClient.DeleteBigQuery(&DeleteBigQueryInput{ |
| 283 |
Service: "foo", |
| 284 |
Version: 0, |
| 285 |
}) |
| 286 |
if err != ErrMissingVersion { |
| 287 |
t.Errorf("bad error: %s", err) |
| 288 |
} |
| 289 |
|
| 290 |
err = testClient.DeleteBigQuery(&DeleteBigQueryInput{ |
| 291 |
Service: "foo", |
| 292 |
Version: 1, |
| 293 |
Name: "", |
| 294 |
}) |
| 295 |
if err != ErrMissingName { |
| 296 |
t.Errorf("bad error: %s", err) |
| 297 |
} |
| 298 |
} |