Skip to content

Commit b05f5b3

Browse files
committed
test(bigquery): validate maximumBytesBilled
1 parent acc5afb commit b05f5b3

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

internal/sources/bigquery/bigquery.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ type Config struct {
9090
ImpersonateServiceAccount string `yaml:"impersonateServiceAccount"`
9191
Scopes StringOrStringSlice `yaml:"scopes"`
9292
MaxQueryResultRows int `yaml:"maxQueryResultRows"`
93-
MaximumBytesBilled int64 `yaml:"maximumBytesBilled"`
93+
MaximumBytesBilled int64 `yaml:"maximumBytesBilled" validate:"gte=0"`
9494
}
9595

9696
// StringOrStringSlice is a custom type that can unmarshal both a single string

internal/sources/bigquery/bigquery_test.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,6 +299,17 @@ func TestFailParseFromYaml(t *testing.T) {
299299
`,
300300
err: "error unmarshaling sources: unable to parse source \"my-instance\" as \"bigquery\": Key: 'Config.Project' Error:Field validation for 'Project' failed on the 'required' tag",
301301
},
302+
{
303+
desc: "negative maximum bytes billed",
304+
in: `
305+
kind: sources
306+
name: my-instance
307+
type: bigquery
308+
project: my-project
309+
maximumBytesBilled: -1
310+
`,
311+
err: "error unmarshaling sources: unable to parse source \"my-instance\" as \"bigquery\": [1:21] Key: 'Config.MaximumBytesBilled' Error:Field validation for 'MaximumBytesBilled' failed on the 'gte' tag\n> 1 | maximumBytesBilled: -1\n ^\n 2 | name: my-instance\n 3 | project: my-project\n 4 | type: bigquery",
312+
},
302313
}
303314
for _, tc := range tcs {
304315
t.Run(tc.desc, func(t *testing.T) {
@@ -386,7 +397,7 @@ func TestInitialize_MaximumBytesBilled(t *testing.T) {
386397
Name: "test-default",
387398
Type: bigquery.SourceType,
388399
Project: "test-project",
389-
UseClientOAuth: true,
400+
UseClientOAuth: "true",
390401
},
391402
want: 0,
392403
},
@@ -396,7 +407,7 @@ func TestInitialize_MaximumBytesBilled(t *testing.T) {
396407
Name: "test-configured",
397408
Type: bigquery.SourceType,
398409
Project: "test-project",
399-
UseClientOAuth: true,
410+
UseClientOAuth: "true",
400411
MaximumBytesBilled: 10737418240,
401412
},
402413
want: 10737418240,

0 commit comments

Comments
 (0)