From 457d2c6eb4d9bde1651f4ce8b091d82ef7eb6c26 Mon Sep 17 00:00:00 2001 From: justinsb Date: Fri, 13 Dec 2024 05:34:43 -0800 Subject: [PATCH] tests: add test coverage for exporting BigQueryTable --- .../_generated_export_bigquerytable.golden | 21 +++ .../bigquery/v1beta1/bigquerytable/_http.log | 153 ++++++++++++++++++ ...eferencewithuserspecifiedresourceid.golden | 14 ++ .../_http.log | 70 ++++++++ tests/e2e/export.go | 8 + 5 files changed, 266 insertions(+) create mode 100644 pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_generated_export_bigquerytable.golden create mode 100644 pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_generated_export_referencewithuserspecifiedresourceid.golden diff --git a/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_generated_export_bigquerytable.golden b/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_generated_export_bigquerytable.golden new file mode 100644 index 0000000000..993591583f --- /dev/null +++ b/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_generated_export_bigquerytable.golden @@ -0,0 +1,21 @@ +apiVersion: bigquery.cnrm.cloud.google.com/v1beta1 +kind: BigQueryTable +metadata: + annotations: + cnrm.cloud.google.com/project-id: ${projectId} + labels: + cnrm-test: "true" + managed-by-cnrm: "true" + name: bigquerytablesample${uniqueId} +spec: + datasetRef: + external: bigquerydatasetsample${uniqueId} + externalDataConfiguration: + autodetect: true + compression: NONE + sourceFormat: CSV + sourceUris: + - 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 + friendlyName: bigquerytable-sample-updated + resourceID: bigquerytablesample${uniqueId} + 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"}]' \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_http.log b/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_http.log index 51ff6b9e35..fa60249d21 100644 --- a/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_http.log +++ b/pkg/test/resourcefixture/testdata/basic/bigquery/v1beta1/bigquerytable/_http.log @@ -818,6 +818,159 @@ X-Xss-Protection: 0 --- +POST https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytablesample${uniqueId}:getIamPolicy?alt=json +Content-Type: application/json +User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager + +{ + "options": { + "requestedPolicyVersion": 1 + } +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "etag": "abcdef0123A=" +} + +--- + +GET https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytablesample${uniqueId}?alt=json&prettyPrint=false +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 + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "creationTime": "123456789", + "etag": "abcdef0123A=", + "externalDataConfiguration": { + "autodetect": true, + "compression": "NONE", + "sourceFormat": "CSV", + "sourceUris": [ + "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" + ] + }, + "friendlyName": "bigquerytable-sample-updated", + "id": "000000000000000000000", + "kind": "bigquery#table", + "labels": { + "cnrm-test": "true", + "managed-by-cnrm": "true" + }, + "lastModifiedTime": "123456789", + "location": "US", + "numActiveLogicalBytes": "0", + "numBytes": "0", + "numLongTermBytes": "0", + "numLongTermLogicalBytes": "0", + "numRows": "0", + "numTotalLogicalBytes": "0", + "requirePartitionFilter": false, + "schema": { + "fields": [ + { + "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" + } + ] + }, + "selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/bigquerydatasetsample${uniqueId}/tables/bigquerytablesample${uniqueId}", + "tableReference": { + "datasetId": "bigquerydatasetsample${uniqueId}", + "projectId": "${projectId}", + "tableId": "bigquerytablesample${uniqueId}" + }, + "type": "EXTERNAL" +} + +--- + DELETE https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytablesample${uniqueId}?alt=json&prettyPrint=false 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 diff --git a/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_generated_export_referencewithuserspecifiedresourceid.golden b/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_generated_export_referencewithuserspecifiedresourceid.golden new file mode 100644 index 0000000000..6dfaa94ed5 --- /dev/null +++ b/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_generated_export_referencewithuserspecifiedresourceid.golden @@ -0,0 +1,14 @@ +apiVersion: bigquery.cnrm.cloud.google.com/v1beta1 +kind: BigQueryTable +metadata: + annotations: + cnrm.cloud.google.com/project-id: ${projectId} + labels: + cnrm-test: "true" + managed-by-cnrm: "true" + name: bigquerytable-resourceid-${uniqueId} +spec: + datasetRef: + external: bigquerydataset_resourceid_${uniqueId} + friendlyName: bigquerytable-sample-updated + resourceID: bigquerytable_resourceid_${uniqueId} \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_http.log b/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_http.log index 79b1223427..55272f050f 100644 --- a/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_http.log +++ b/pkg/test/resourcefixture/testdata/resourceid/referencewithuserspecifiedresourceid/_http.log @@ -382,6 +382,76 @@ X-Xss-Protection: 0 --- +POST https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytable_resourceid_${uniqueId}:getIamPolicy?alt=json +Content-Type: application/json +User-Agent: Terraform/ (+https://www.terraform.io) Terraform-Plugin-SDK/2.10.1 terraform-provider-google-beta/kcc/controller-manager + +{ + "options": { + "requestedPolicyVersion": 1 + } +} + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "etag": "abcdef0123A=" +} + +--- + +GET https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytable_resourceid_${uniqueId}?alt=json&prettyPrint=false +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 + +200 OK +Cache-Control: private +Content-Type: application/json; charset=UTF-8 +Server: ESF +Vary: Origin +Vary: X-Origin +Vary: Referer +X-Content-Type-Options: nosniff +X-Frame-Options: SAMEORIGIN +X-Xss-Protection: 0 + +{ + "creationTime": "123456789", + "etag": "abcdef0123A=", + "friendlyName": "bigquerytable-sample-updated", + "id": "000000000000000000000", + "kind": "bigquery#table", + "labels": { + "cnrm-test": "true", + "managed-by-cnrm": "true" + }, + "lastModifiedTime": "123456789", + "location": "US", + "numActiveLogicalBytes": "0", + "numBytes": "0", + "numLongTermBytes": "0", + "numLongTermLogicalBytes": "0", + "numRows": "0", + "numTotalLogicalBytes": "0", + "selfLink": "https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/bigquerydataset_resourceid_${uniqueId}/tables/bigquerytable_resourceid_${uniqueId}", + "tableReference": { + "datasetId": "bigquerydataset_resourceid_${uniqueId}", + "projectId": "${projectId}", + "tableId": "bigquerytable_resourceid_${uniqueId}" + }, + "type": "TABLE" +} + +--- + DELETE https://bigquery.googleapis.com/bigquery/v2/projects/${projectId}/datasets/${datasetID}/tables/bigquerytable_resourceid_${uniqueId}?alt=json&prettyPrint=false 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 diff --git a/tests/e2e/export.go b/tests/e2e/export.go index 1945b680ad..a2728e5522 100644 --- a/tests/e2e/export.go +++ b/tests/e2e/export.go @@ -47,6 +47,9 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured, expectati if !found && expectations.Location { h.T.Error("expected to find location or region in obj but did not find it") } + + statusSelfLink, _, _ := unstructured.NestedString(obj.Object, "status", "selfLink") + // This list should match https://cloud.google.com/asset-inventory/docs/resource-name-format gvk := obj.GroupVersionKind() switch gvk.GroupKind() { @@ -55,6 +58,11 @@ func exportResource(h *create.Harness, obj *unstructured.Unstructured, expectati case schema.GroupKind{Group: "bigquery.cnrm.cloud.google.com", Kind: "BigQueryDataset"}: exportURI = "//bigquery.googleapis.com/projects/" + projectID + "/datasets/" + resourceID + case schema.GroupKind{Group: "bigquery.cnrm.cloud.google.com", Kind: "BigQueryTable"}: + if statusSelfLink == "" { + h.T.Errorf("status.selfLink not set in BigQueryTable object") + } + exportURI = strings.ReplaceAll(statusSelfLink, "https://bigquery.googleapis.com/bigquery/v2/", "//bigquery.googleapis.com/") case schema.GroupKind{Group: "discoveryengine.cnrm.cloud.google.com", Kind: "DiscoveryEngineDataStore"}: exportURI = "//discoveryengine.googleapis.com/projects/{projectID}/locations/{.spec.location}/collections/{.spec.collection}/dataStores/{resourceID}"