@@ -2,6 +2,7 @@ package bigquery_test
2
2
3
3
import (
4
4
"fmt"
5
+ "regexp"
5
6
"testing"
6
7
7
8
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
@@ -81,3 +82,64 @@ resource "google_bigquery_job" "job" {
81
82
}
82
83
` , context )
83
84
}
85
+
86
+ func TestAccBigQueryJob_validationErrors (t * testing.T ) {
87
+ t .Parallel ()
88
+ context := map [string ]interface {}{
89
+ "random_suffix" : acctest .RandString (t , 10 ),
90
+ "project" : envvar .GetTestProjectFromEnv (),
91
+ }
92
+
93
+ acctest .VcrTest (t , resource.TestCase {
94
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
95
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
96
+ Steps : []resource.TestStep {
97
+ {
98
+ Config : testAccBigQueryJob_missingProjectId (context ),
99
+ ExpectError : regexp .MustCompile (
100
+ `(?s)Invalid BigQuery job destination_table configuration\. You must either:.*Missing or empty projectId` ,
101
+ ),
102
+ },
103
+ {
104
+ Config : testAccBigQueryJob_missingDatasetId (context ),
105
+ ExpectError : regexp .MustCompile (
106
+ `(?s)Invalid BigQuery job destination_table configuration\. You must either:.*Missing or empty datasetId` ,
107
+ ),
108
+ },
109
+ },
110
+ })
111
+ }
112
+
113
+ func testAccBigQueryJob_missingProjectId (context map [string ]interface {}) string {
114
+ return acctest .Nprintf (`
115
+ resource "google_bigquery_job" "job" {
116
+ job_id = "tf-test-job-%{random_suffix}"
117
+
118
+ query {
119
+ query = "SELECT state FROM [lookerdata:cdc.project_tycho_reports]"
120
+ destination_table {
121
+ dataset_id = "example_dataset"
122
+ table_id = "example_table"
123
+ # project_id intentionally omitted
124
+ }
125
+ }
126
+ }
127
+ ` , context )
128
+ }
129
+
130
+ func testAccBigQueryJob_missingDatasetId (context map [string ]interface {}) string {
131
+ return acctest .Nprintf (`
132
+ resource "google_bigquery_job" "job" {
133
+ job_id = "tf-test-job-%{random_suffix}"
134
+
135
+ query {
136
+ query = "SELECT state FROM [lookerdata:cdc.project_tycho_reports]"
137
+ destination_table {
138
+ project_id = "%{project}"
139
+ table_id = "example_table"
140
+ # dataset_id intentionally omitted
141
+ }
142
+ }
143
+ }
144
+ ` , context )
145
+ }
0 commit comments