Skip to content

Commit 95b3225

Browse files
Merge pull request GoogleCloudPlatform#3382 from justinsb/add_export_for_bigquery_table
tests: add test coverage for exporting BigQueryTable
2 parents 4dffbd6 + 457d2c6 commit 95b3225

File tree

5 files changed

+266
-0
lines changed

5 files changed

+266
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
2+
kind: BigQueryTable
3+
metadata:
4+
annotations:
5+
cnrm.cloud.google.com/project-id: ${projectId}
6+
labels:
7+
cnrm-test: "true"
8+
managed-by-cnrm: "true"
9+
name: bigquerytablesample${uniqueId}
10+
spec:
11+
datasetRef:
12+
external: bigquerydatasetsample${uniqueId}
13+
externalDataConfiguration:
14+
autodetect: true
15+
compression: NONE
16+
sourceFormat: CSV
17+
sourceUris:
18+
- gs://gcp-public-data-landsat/LC08/01/044/034/LC08_L1GT_044034_20130330_20170310_01_T2/LC08_L1GT_044034_20130330_20170310_01_T2_ANG.txt
19+
friendlyName: bigquerytable-sample-updated
20+
resourceID: bigquerytablesample${uniqueId}
21+
schema: '[{"mode":"NULLABLE","name":"string_field_0","type":"STRING"},{"mode":"NULLABLE","name":"string_field_1","type":"STRING"},{"mode":"NULLABLE","name":"string_field_2","type":"STRING"},{"mode":"NULLABLE","name":"string_field_3","type":"STRING"},{"mode":"NULLABLE","name":"string_field_4","type":"STRING"},{"mode":"NULLABLE","name":"string_field_5","type":"STRING"},{"mode":"NULLABLE","name":"int64_field_6","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_7","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_8","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_9","type":"INTEGER"},{"mode":"NULLABLE","name":"string_field_10","type":"STRING"},{"mode":"NULLABLE","name":"int64_field_11","type":"INTEGER"},{"mode":"NULLABLE","name":"int64_field_12","type":"INTEGER"},{"mode":"NULLABLE","name":"string_field_13","type":"STRING"}]'

pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_http.log

+153
Original file line numberDiff line numberDiff line change
@@ -818,6 +818,159 @@ X-Xss-Protection: 0
818818

819819
---
820820

821+
POST https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytablesample${uniqueId}:getIamPolicy?alt=json
822+
Content-Type: application/json
823+
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
824+
825+
{
826+
"options": {
827+
"requestedPolicyVersion": 1
828+
}
829+
}
830+
831+
200 OK
832+
Cache-Control: private
833+
Content-Type: application/json; charset=UTF-8
834+
Server: ESF
835+
Vary: Origin
836+
Vary: X-Origin
837+
Vary: Referer
838+
X-Content-Type-Options: nosniff
839+
X-Frame-Options: SAMEORIGIN
840+
X-Xss-Protection: 0
841+
842+
{
843+
"etag": "abcdef0123A="
844+
}
845+
846+
---
847+
848+
GET https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytablesample${uniqueId}?alt=json&prettyPrint=false
849+
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
850+
851+
200 OK
852+
Cache-Control: private
853+
Content-Type: application/json; charset=UTF-8
854+
Server: ESF
855+
Vary: Origin
856+
Vary: X-Origin
857+
Vary: Referer
858+
X-Content-Type-Options: nosniff
859+
X-Frame-Options: SAMEORIGIN
860+
X-Xss-Protection: 0
861+
862+
{
863+
"creationTime": "123456789",
864+
"etag": "abcdef0123A=",
865+
"externalDataConfiguration": {
866+
"autodetect": true,
867+
"compression": "NONE",
868+
"sourceFormat": "CSV",
869+
"sourceUris": [
870+
"gs://gcp-public-data-landsat/LC08/01/044/034/LC08_L1GT_044034_20130330_20170310_01_T2/LC08_L1GT_044034_20130330_20170310_01_T2_ANG.txt"
871+
]
872+
},
873+
"friendlyName": "bigquerytable-sample-updated",
874+
"id": "000000000000000000000",
875+
"kind": "bigquery#table",
876+
"labels": {
877+
"cnrm-test": "true",
878+
"managed-by-cnrm": "true"
879+
},
880+
"lastModifiedTime": "123456789",
881+
"location": "US",
882+
"numActiveLogicalBytes": "0",
883+
"numBytes": "0",
884+
"numLongTermBytes": "0",
885+
"numLongTermLogicalBytes": "0",
886+
"numRows": "0",
887+
"numTotalLogicalBytes": "0",
888+
"requirePartitionFilter": false,
889+
"schema": {
890+
"fields": [
891+
{
892+
"mode": "NULLABLE",
893+
"name": "string_field_0",
894+
"type": "STRING"
895+
},
896+
{
897+
"mode": "NULLABLE",
898+
"name": "string_field_1",
899+
"type": "STRING"
900+
},
901+
{
902+
"mode": "NULLABLE",
903+
"name": "string_field_2",
904+
"type": "STRING"
905+
},
906+
{
907+
"mode": "NULLABLE",
908+
"name": "string_field_3",
909+
"type": "STRING"
910+
},
911+
{
912+
"mode": "NULLABLE",
913+
"name": "string_field_4",
914+
"type": "STRING"
915+
},
916+
{
917+
"mode": "NULLABLE",
918+
"name": "string_field_5",
919+
"type": "STRING"
920+
},
921+
{
922+
"mode": "NULLABLE",
923+
"name": "int64_field_6",
924+
"type": "INTEGER"
925+
},
926+
{
927+
"mode": "NULLABLE",
928+
"name": "int64_field_7",
929+
"type": "INTEGER"
930+
},
931+
{
932+
"mode": "NULLABLE",
933+
"name": "int64_field_8",
934+
"type": "INTEGER"
935+
},
936+
{
937+
"mode": "NULLABLE",
938+
"name": "int64_field_9",
939+
"type": "INTEGER"
940+
},
941+
{
942+
"mode": "NULLABLE",
943+
"name": "string_field_10",
944+
"type": "STRING"
945+
},
946+
{
947+
"mode": "NULLABLE",
948+
"name": "int64_field_11",
949+
"type": "INTEGER"
950+
},
951+
{
952+
"mode": "NULLABLE",
953+
"name": "int64_field_12",
954+
"type": "INTEGER"
955+
},
956+
{
957+
"mode": "NULLABLE",
958+
"name": "string_field_13",
959+
"type": "STRING"
960+
}
961+
]
962+
},
963+
"selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/bigquerydatasetsample${uniqueId}/tables/bigquerytablesample${uniqueId}",
964+
"tableReference": {
965+
"datasetId": "bigquerydatasetsample${uniqueId}",
966+
"projectId": "${projectId}",
967+
"tableId": "bigquerytablesample${uniqueId}"
968+
},
969+
"type": "EXTERNAL"
970+
}
971+
972+
---
973+
821974
DELETE https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytablesample${uniqueId}?alt=json&prettyPrint=false
822975
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
823976

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
apiVersion: bigquery.cnrm.cloud.google.com/v1beta1
2+
kind: BigQueryTable
3+
metadata:
4+
annotations:
5+
cnrm.cloud.google.com/project-id: ${projectId}
6+
labels:
7+
cnrm-test: "true"
8+
managed-by-cnrm: "true"
9+
name: bigquerytable-resourceid-${uniqueId}
10+
spec:
11+
datasetRef:
12+
external: bigquerydataset_resourceid_${uniqueId}
13+
friendlyName: bigquerytable-sample-updated
14+
resourceID: bigquerytable_resourceid_${uniqueId}

pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_http.log

+70
Original file line numberDiff line numberDiff line change
@@ -382,6 +382,76 @@ X-Xss-Protection: 0
382382

383383
---
384384

385+
POST https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytable_resourceid_${uniqueId}:getIamPolicy?alt=json
386+
Content-Type: application/json
387+
User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
388+
389+
{
390+
"options": {
391+
"requestedPolicyVersion": 1
392+
}
393+
}
394+
395+
200 OK
396+
Cache-Control: private
397+
Content-Type: application/json; charset=UTF-8
398+
Server: ESF
399+
Vary: Origin
400+
Vary: X-Origin
401+
Vary: Referer
402+
X-Content-Type-Options: nosniff
403+
X-Frame-Options: SAMEORIGIN
404+
X-Xss-Protection: 0
405+
406+
{
407+
"etag": "abcdef0123A="
408+
}
409+
410+
---
411+
412+
GET https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytable_resourceid_${uniqueId}?alt=json&prettyPrint=false
413+
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
414+
415+
200 OK
416+
Cache-Control: private
417+
Content-Type: application/json; charset=UTF-8
418+
Server: ESF
419+
Vary: Origin
420+
Vary: X-Origin
421+
Vary: Referer
422+
X-Content-Type-Options: nosniff
423+
X-Frame-Options: SAMEORIGIN
424+
X-Xss-Protection: 0
425+
426+
{
427+
"creationTime": "123456789",
428+
"etag": "abcdef0123A=",
429+
"friendlyName": "bigquerytable-sample-updated",
430+
"id": "000000000000000000000",
431+
"kind": "bigquery#table",
432+
"labels": {
433+
"cnrm-test": "true",
434+
"managed-by-cnrm": "true"
435+
},
436+
"lastModifiedTime": "123456789",
437+
"location": "US",
438+
"numActiveLogicalBytes": "0",
439+
"numBytes": "0",
440+
"numLongTermBytes": "0",
441+
"numLongTermLogicalBytes": "0",
442+
"numRows": "0",
443+
"numTotalLogicalBytes": "0",
444+
"selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/bigquerydataset_resourceid_${uniqueId}/tables/bigquerytable_resourceid_${uniqueId}",
445+
"tableReference": {
446+
"datasetId": "bigquerydataset_resourceid_${uniqueId}",
447+
"projectId": "${projectId}",
448+
"tableId": "bigquerytable_resourceid_${uniqueId}"
449+
},
450+
"type": "TABLE"
451+
}
452+
453+
---
454+
385455
DELETE https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytable_resourceid_${uniqueId}?alt=json&prettyPrint=false
386456
User-Agent: google-api-go-client/0.5 Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager
387457

tests/e2e/export.go

+8
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured, expectati
4747
if !found && expectations.Location {
4848
h.T.Error("expected to find location or region in obj but did not find it")
4949
}
50+
51+
statusSelfLink, _, _ := unstructured.NestedString(obj.Object, "status", "selfLink")
52+
5053
// This list should match https://cloud.google.com/asset-inventory/docs/resource-name-format
5154
gvk := obj.GroupVersionKind()
5255
switch gvk.GroupKind() {
@@ -55,6 +58,11 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured, expectati
5558

5659
case schema.GroupKind{Group: "bigquery.cnrm.cloud.google.com", Kind: "BigQueryDataset"}:
5760
exportURI = "//bigquery.googleapis.com/projects/" + projectID + "/datasets/" + resourceID
61+
case schema.GroupKind{Group: "bigquery.cnrm.cloud.google.com", Kind: "BigQueryTable"}:
62+
if statusSelfLink == "" {
63+
h.T.Errorf("status.selfLink not set in BigQueryTable object")
64+
}
65+
exportURI = strings.ReplaceAll(statusSelfLink, "https://bigquery.googleapis.com/bigquery/v2/", "//bigquery.googleapis.com/")
5866

5967
case schema.GroupKind{Group: "discoveryengine.cnrm.cloud.google.com", Kind: "DiscoveryEngineDataStore"}:
6068
exportURI = "//discoveryengine.googleapis.com/projects/{projectID}/locations/{.spec.location}/collections/{.spec.collection}/dataStores/{resourceID}"

0 commit comments

Comments
 (0)