diff --git a/config/tests/samples/create/harness.go b/config/tests/samples/create/harness.go index 20f343a90d..5b87f30a60 100644 --- a/config/tests/samples/create/harness.go +++ b/config/tests/samples/create/harness.go @@ -312,6 +312,16 @@ func NewHarness(ctx context.Context, t *testing.T) *Harness { } if targetGCP := os.Getenv("E2E_GCP_TARGET"); targetGCP == "vcr" { + // Initialize VCR for TF requests + input := os.Getenv("VCR_MODE") + var VCRMode recorder.Mode + if input == "Recording" { + VCRMode = recorder.ModeRecordOnly + } else if input == "Replaying" { + VCRMode = recorder.ModeReplayOnly + } else { + t.Fatalf("[VCR] Input mode is not supported.") + } transport_tpg.DefaultHTTPClientTransformer = func(ctx context.Context, inner *http.Client) *http.Client { ret := inner if t := ctx.Value(httpRoundTripperKey); t != nil { @@ -321,7 +331,7 @@ func NewHarness(ctx context.Context, t *testing.T) *Harness { testName := strings.ReplaceAll(t.Name(), "/", "_") opts := &recorder.Options{ CassetteName: filepath.Join(dir, testName), - Mode: recorder.ModeRecordOnly, + Mode: VCRMode, RealTransport: ret.Transport, } r, err := recorder.NewWithOptions(opts) diff --git a/go.mod b/go.mod index d867d1c458..30389664df 100644 --- a/go.mod +++ b/go.mod @@ -44,7 +44,7 @@ require ( golang.org/x/sync v0.6.0 golang.org/x/time v0.5.0 google.golang.org/api v0.160.0 - google.golang.org/protobuf v1.32.0 + google.golang.org/protobuf v1.33.0 gopkg.in/dnaeon/go-vcr.v3 v3.2.0 gopkg.in/yaml.v2 v2.4.0 k8s.io/api v0.27.11 diff --git a/go.sum b/go.sum index 4c33ac7dc5..06dcf92a61 100644 --- a/go.sum +++ b/go.sum @@ -1465,6 +1465,7 @@ google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQ google.golang.org/protobuf v1.27.1/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.32.0 h1:pPC6BG5ex8PDFnkbrGU3EixyhKcQ2aDuBS36lqK/C7I= google.golang.org/protobuf v1.32.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/alecthomas/kingpin.v2 v2.2.6/go.mod h1:FMv+mEhP44yOT+4EoQTLFTRgOQ1FBLkstjWtayDeSgw= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= diff --git a/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodegroup.seed b/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodegroup.seed new file mode 100644 index 0000000000..012ac2f00c --- /dev/null +++ b/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodegroup.seed @@ -0,0 +1 @@ +4096998150677633605 \ No newline at end of file diff --git a/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodegroup.yaml b/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodegroup.yaml new file mode 100644 index 0000000000..ebcd23db57 --- /dev/null +++ b/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodegroup.yaml @@ -0,0 +1,1032 @@ +# Copyright 2024 Google LLC +# +# Licensed under the Apache License, Version 2.0 (the "License"); +# you may not use this file except in compliance with the License. +# You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, +# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +# See the License for the specific language governing permissions and +# limitations under the License. + +--- +version: 2 +interactions: + - id: 0 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "error": { + "code": 404, + "message": "The resource 'projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733' was not found", + "errors": [ + { + "message": "The resource 'projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733' was not found", + "domain": "global", + "reason": "notFound", + "debugInfo": "fake debug info" + } + ] + } + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 404 Not Found + code: 404 + duration: 219.138258ms + - id: 1 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 254 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: | + {"cpuOvercommitType":"NONE","name":"computenodetemplate-181629406ab2052733","nodeAffinityLabels":{"cnrm-test":"true","managed-by-cnrm":"true"},"nodeTypeFlexibility":{"cpus":"any","memory":"any"},"region":"projects/cnrm-user/global/regions/us-central1"} + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates?alt=json + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#operation", + "id": "5166943856068539359", + "name": "operation-1710722351858-613e4961782e5-33b0f1d6-41421f1a", + "operationType": "compute.nodeTemplates.insert", + "targetLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "targetId": "3467262981637288927", + "status": "RUNNING", + "user": "user@google.com", + "progress": 0, + "insertTime": "2024-03-17T17:39:12.156-07:00", + "startTime": "2024-03-17T17:39:12.194-07:00", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/operations/operation-1710722351858-613e4961782e5-33b0f1d6-41421f1a", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 468.089744ms + - id: 2 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + X-Goog-Api-Client: + - gl-go/1.21.5 gdcl/0.160.0 + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/operations/operation-1710722351858-613e4961782e5-33b0f1d6-41421f1a?alt=json&prettyPrint=false + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"kind":"compute#operation","id":"5166943856068539359","name":"operation-1710722351858-613e4961782e5-33b0f1d6-41421f1a","operationType":"compute.nodeTemplates.insert","targetLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733","targetId":"3467262981637288927","status":"DONE","user":"user@google.com","progress":100,"insertTime":"2024-03-17T17:39:12.156-07:00","startTime":"2024-03-17T17:39:12.194-07:00","endTime":"2024-03-17T17:39:12.470-07:00","selfLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/operations/operation-1710722351858-613e4961782e5-33b0f1d6-41421f1a","region":"https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1"}' + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 300.785156ms + - id: 3 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeTemplate", + "id": "3467262981637288927", + "creationTimestamp": "2024-03-17T17:39:12.165-07:00", + "name": "computenodetemplate-181629406ab2052733", + "nodeAffinityLabels": { + "managed-by-cnrm": "true", + "cnrm-test": "true" + }, + "status": "READY", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "nodeTypeFlexibility": { + "cpus": "any", + "memory": "any" + }, + "serverBinding": { + "type": "RESTART_NODE_ON_ANY_SERVER" + }, + "cpuOvercommitType": "NONE" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 142.474442ms + - id: 4 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "error": { + "code": 404, + "message": "The resource 'projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733' was not found", + "errors": [ + { + "message": "The resource 'projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733' was not found", + "domain": "global", + "reason": "notFound", + "debugInfo": "fake debug info" + } + ] + } + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 404 Not Found + code: 404 + duration: 144.587762ms + - id: 5 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeTemplate", + "id": "3467262981637288927", + "creationTimestamp": "2024-03-17T17:39:12.165-07:00", + "name": "computenodetemplate-181629406ab2052733", + "nodeAffinityLabels": { + "managed-by-cnrm": "true", + "cnrm-test": "true" + }, + "status": "READY", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "nodeTypeFlexibility": { + "cpus": "any", + "memory": "any" + }, + "serverBinding": { + "type": "RESTART_NODE_ON_ANY_SERVER" + }, + "cpuOvercommitType": "NONE" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 275.058261ms + - id: 6 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 321 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: | + {"description":"A single sole-tenant node in the us-central1-b zone.","maintenancePolicy":"DEFAULT","name":"computenodegroup-181629406ab2052733","nodeTemplate":"projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733","size":1,"zone":"projects/cnrm-user/global/zones/us-central1-b"} + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups?alt=json&initialNodeCount=1 + method: POST + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#operation", + "id": "1164200057509655517", + "name": "operation-1710722354013-613e4963865f9-f11bcc7a-dc980414", + "zone": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b", + "operationType": "compute.nodeGroups.insert", + "targetLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733", + "targetId": "8833015441855755229", + "status": "RUNNING", + "user": "user@google.com", + "progress": 0, + "insertTime": "2024-03-17T17:39:14.389-07:00", + "startTime": "2024-03-17T17:39:14.414-07:00", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722354013-613e4963865f9-f11bcc7a-dc980414" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 494.585499ms + - id: 7 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + X-Goog-Api-Client: + - gl-go/1.21.5 gdcl/0.160.0 + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722354013-613e4963865f9-f11bcc7a-dc980414?alt=json&prettyPrint=false + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"kind":"compute#operation","id":"1164200057509655517","name":"operation-1710722354013-613e4963865f9-f11bcc7a-dc980414","zone":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b","operationType":"compute.nodeGroups.insert","targetLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733","targetId":"8833015441855755229","status":"RUNNING","user":"user@google.com","progress":0,"insertTime":"2024-03-17T17:39:14.389-07:00","startTime":"2024-03-17T17:39:14.414-07:00","selfLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722354013-613e4963865f9-f11bcc7a-dc980414"}' + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 309.135558ms + - id: 8 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + X-Goog-Api-Client: + - gl-go/1.21.5 gdcl/0.160.0 + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722354013-613e4963865f9-f11bcc7a-dc980414?alt=json&prettyPrint=false + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"kind":"compute#operation","id":"1164200057509655517","name":"operation-1710722354013-613e4963865f9-f11bcc7a-dc980414","zone":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b","operationType":"compute.nodeGroups.insert","targetLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733","targetId":"8833015441855755229","status":"DONE","user":"user@google.com","progress":100,"insertTime":"2024-03-17T17:39:14.389-07:00","startTime":"2024-03-17T17:39:14.414-07:00","endTime":"2024-03-17T17:39:21.510-07:00","selfLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722354013-613e4963865f9-f11bcc7a-dc980414"}' + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 159.481675ms + - id: 9 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeGroup", + "id": "8833015441855755229", + "creationTimestamp": "2024-03-17T17:39:14.394-07:00", + "name": "computenodegroup-181629406ab2052733", + "description": "A single sole-tenant node in the us-central1-b zone.", + "nodeTemplate": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "zone": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733", + "status": "READY", + "size": 1, + "autoscalingPolicy": { + "mode": "OFF", + "minNodes": 0 + }, + "maintenancePolicy": "DEFAULT", + "fingerprint": "vkfssCrYzMY=", + "shareSettings": { + "shareType": "LOCAL" + }, + "maintenanceInterval": "AS_NEEDED" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 331.38324ms + - id: 10 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeGroup", + "id": "8833015441855755229", + "creationTimestamp": "2024-03-17T17:39:14.394-07:00", + "name": "computenodegroup-181629406ab2052733", + "description": "A single sole-tenant node in the us-central1-b zone.", + "nodeTemplate": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "zone": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733", + "status": "READY", + "size": 1, + "autoscalingPolicy": { + "mode": "OFF", + "minNodes": 0 + }, + "maintenancePolicy": "DEFAULT", + "fingerprint": "vkfssCrYzMY=", + "shareSettings": { + "shareType": "LOCAL" + }, + "maintenanceInterval": "AS_NEEDED" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 337.972901ms + - id: 11 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeGroup", + "id": "8833015441855755229", + "creationTimestamp": "2024-03-17T17:39:14.394-07:00", + "name": "computenodegroup-181629406ab2052733", + "description": "A single sole-tenant node in the us-central1-b zone.", + "nodeTemplate": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "zone": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733", + "status": "READY", + "size": 1, + "autoscalingPolicy": { + "mode": "OFF", + "minNodes": 0 + }, + "maintenancePolicy": "DEFAULT", + "fingerprint": "vkfssCrYzMY=", + "shareSettings": { + "shareType": "LOCAL" + }, + "maintenanceInterval": "AS_NEEDED" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 168.912546ms + - id: 12 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeTemplate", + "id": "3467262981637288927", + "creationTimestamp": "2024-03-17T17:39:12.165-07:00", + "name": "computenodetemplate-181629406ab2052733", + "nodeAffinityLabels": { + "cnrm-test": "true", + "managed-by-cnrm": "true" + }, + "status": "READY", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "nodeTypeFlexibility": { + "cpus": "any", + "memory": "any" + }, + "serverBinding": { + "type": "RESTART_NODE_ON_ANY_SERVER" + }, + "cpuOvercommitType": "NONE" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 277.084559ms + - id: 13 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733?alt=json + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#operation", + "id": "8504392792365740975", + "name": "operation-1710722368386-613e49713b4c8-89892117-3b9e900f", + "zone": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b", + "operationType": "compute.nodeGroups.delete", + "targetLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733", + "targetId": "8833015441855755229", + "status": "RUNNING", + "user": "user@google.com", + "progress": 0, + "insertTime": "2024-03-17T17:39:28.589-07:00", + "startTime": "2024-03-17T17:39:28.613-07:00", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722368386-613e49713b4c8-89892117-3b9e900f" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 496.630355ms + - id: 14 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "error": { + "code": 400, + "message": "The node_template resource 'projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733' is already being used by 'projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733'", + "errors": [ + { + "message": "The node_template resource 'projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733' is already being used by 'projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733'", + "domain": "global", + "reason": "resourceInUseByAnotherResource", + "debugInfo": "fake debug info" + } + ] + } + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 400 Bad Request + code: 400 + duration: 449.426246ms + - id: 15 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + X-Goog-Api-Client: + - gl-go/1.21.5 gdcl/0.160.0 + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722368386-613e49713b4c8-89892117-3b9e900f?alt=json&prettyPrint=false + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"kind":"compute#operation","id":"8504392792365740975","name":"operation-1710722368386-613e49713b4c8-89892117-3b9e900f","zone":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b","operationType":"compute.nodeGroups.delete","targetLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733","targetId":"8833015441855755229","status":"RUNNING","user":"user@google.com","progress":0,"insertTime":"2024-03-17T17:39:28.589-07:00","startTime":"2024-03-17T17:39:28.613-07:00","selfLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722368386-613e49713b4c8-89892117-3b9e900f"}' + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 141.27689ms + - id: 16 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeTemplate", + "id": "3467262981637288927", + "creationTimestamp": "2024-03-17T17:39:12.165-07:00", + "name": "computenodetemplate-181629406ab2052733", + "nodeAffinityLabels": { + "managed-by-cnrm": "true", + "cnrm-test": "true" + }, + "status": "READY", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "nodeTypeFlexibility": { + "cpus": "any", + "memory": "any" + }, + "serverBinding": { + "type": "RESTART_NODE_ON_ANY_SERVER" + }, + "cpuOvercommitType": "NONE" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 200.768272ms + - id: 17 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "error": { + "code": 400, + "message": "The node_template resource 'projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733' is already being used by 'projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733'", + "errors": [ + { + "message": "The node_template resource 'projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733' is already being used by 'projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733'", + "domain": "global", + "reason": "resourceInUseByAnotherResource", + "debugInfo": "fake debug info" + } + ] + } + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 400 Bad Request + code: 400 + duration: 335.261121ms + - id: 18 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#nodeTemplate", + "id": "3467262981637288927", + "creationTimestamp": "2024-03-17T17:39:12.165-07:00", + "name": "computenodetemplate-181629406ab2052733", + "nodeAffinityLabels": { + "managed-by-cnrm": "true", + "cnrm-test": "true" + }, + "status": "READY", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "nodeTypeFlexibility": { + "cpus": "any", + "memory": "any" + }, + "serverBinding": { + "type": "RESTART_NODE_ON_ANY_SERVER" + }, + "cpuOvercommitType": "NONE" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 176.580817ms + - id: 19 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + Content-Type: + - application/json + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733?alt=json + method: DELETE + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: | + { + "kind": "compute#operation", + "id": "5114859324540859300", + "name": "operation-1710722379329-613e497baaecf-d4a5b202-406b4220", + "operationType": "compute.nodeTemplates.delete", + "targetLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733", + "targetId": "3467262981637288927", + "status": "RUNNING", + "user": "user@google.com", + "progress": 0, + "insertTime": "2024-03-17T17:39:39.569-07:00", + "startTime": "2024-03-17T17:39:39.593-07:00", + "selfLink": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/operations/operation-1710722379329-613e497baaecf-d4a5b202-406b4220", + "region": "https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1" + } + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 390.397891ms + - id: 20 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + X-Goog-Api-Client: + - gl-go/1.21.5 gdcl/0.160.0 + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722368386-613e49713b4c8-89892117-3b9e900f?alt=json&prettyPrint=false + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"kind":"compute#operation","id":"8504392792365740975","name":"operation-1710722368386-613e49713b4c8-89892117-3b9e900f","zone":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b","operationType":"compute.nodeGroups.delete","targetLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/nodeGroups/computenodegroup-181629406ab2052733","targetId":"8833015441855755229","status":"DONE","user":"user@google.com","progress":100,"insertTime":"2024-03-17T17:39:28.589-07:00","startTime":"2024-03-17T17:39:28.613-07:00","endTime":"2024-03-17T17:39:32.946-07:00","selfLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/zones/us-central1-b/operations/operation-1710722368386-613e49713b4c8-89892117-3b9e900f"}' + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 250.808652ms + - id: 21 + request: + proto: HTTP/1.1 + proto_major: 1 + proto_minor: 1 + content_length: 0 + transfer_encoding: [] + trailer: {} + host: compute.googleapis.com + remote_addr: "" + request_uri: "" + body: "" + form: {} + headers: + X-Goog-Api-Client: + - gl-go/1.21.5 gdcl/0.160.0 + url: https://compute.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/operations/operation-1710722379329-613e497baaecf-d4a5b202-406b4220?alt=json&prettyPrint=false + method: GET + response: + proto: HTTP/2.0 + proto_major: 2 + proto_minor: 0 + transfer_encoding: [] + trailer: {} + content_length: -1 + uncompressed: true + body: '{"kind":"compute#operation","id":"5114859324540859300","name":"operation-1710722379329-613e497baaecf-d4a5b202-406b4220","operationType":"compute.nodeTemplates.delete","targetLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/nodeTemplates/computenodetemplate-181629406ab2052733","targetId":"3467262981637288927","status":"DONE","user":"user@google.com","progress":100,"insertTime":"2024-03-17T17:39:39.569-07:00","startTime":"2024-03-17T17:39:39.593-07:00","endTime":"2024-03-17T17:39:39.999-07:00","selfLink":"https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1/operations/operation-1710722379329-613e497baaecf-d4a5b202-406b4220","region":"https://www.googleapis.com/compute/beta/projects/cnrm-user/regions/us-central1"}' + headers: + Content-Type: + - application/json; charset=UTF-8 + status: 200 OK + code: 200 + duration: 148.752001ms diff --git a/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodetemplate.seed b/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodetemplate.seed new file mode 100644 index 0000000000..b8ce45fb08 --- /dev/null +++ b/pkg/test/resourcefixture/testdata/vcr/cassette/TestAllInSeries_fixtures_computenodetemplate.seed @@ -0,0 +1 @@ +6691153758165004635 \ No newline at end of file diff --git a/tests/e2e/unified_test.go b/tests/e2e/unified_test.go index dca8fba41e..2b898c08ba 100644 --- a/tests/e2e/unified_test.go +++ b/tests/e2e/unified_test.go @@ -19,14 +19,17 @@ import ( "context" "encoding/json" "fmt" + "github.com/hashicorp/terraform-provider-google-beta/google-beta/tpgresource" "gopkg.in/dnaeon/go-vcr.v3/cassette" "gopkg.in/dnaeon/go-vcr.v3/recorder" "io" "io/ioutil" "k8s.io/klog/v2" + "math/rand" "net/http" "os" "path/filepath" + "strconv" "strings" "testing" @@ -124,7 +127,14 @@ func testFixturesInSeries(ctx context.Context, t *testing.T, testName string, te // TODO(b/259496928): Randomize the resource names for parallel execution when/if needed. t.Run(fixture.Name, func(t *testing.T) { - uniqueID := testvariable.NewUniqueID() + var uniqueID string + if os.Getenv("E2E_GCP_TARGET") != "vcr" { + uniqueID = testvariable.NewUniqueID() + //} else { + // var fakeseed int64 = 42 + // r := rand.New(rand.NewSource(fakeseed)) + // uniqueID = strconv.FormatUint(r.Uint64(), 12) + } loadFixture := func(project testgcp.GCPProject) (*unstructured.Unstructured, create.CreateDeleteTestOptions) { primaryResource := bytesToUnstructured(t, fixture.Create, uniqueID, project) @@ -162,6 +172,29 @@ func testFixturesInSeries(ctx context.Context, t *testing.T, testName string, te } if os.Getenv("E2E_GCP_TARGET") == "vcr" { + // Handle unique ID in tests by recording & replaying with a same seed, + // so the generated ID is same for certain test. + var seed int64 + var err error + + dir := "pkg/test/resourcefixture/testdata/vcr/cassette/" + name := strings.ReplaceAll(t.Name(), "/", "_") + fileName := filepath.Join(dir, fmt.Sprintf("%s.seed", name)) + + if h.VCRRecorder.Mode() == recorder.ModeRecordOnly { + seed = rand.Int63() + err = writeSeed(seed, fileName) + if err != nil { + t.Errorf("[VCR] Failed write seed: %v", err) + } + } else if h.VCRRecorder.Mode() == recorder.ModeReplayOnly { + seed, err = readSeed(fileName) + if err != nil { + t.Errorf("[VCR] Failed read seed: %v", err) + } + } + r := rand.New(rand.NewSource(seed)) + uniqueID = strconv.FormatUint(r.Uint64(), 36) // Stop recording after tests finish and write to cassette t.Cleanup(func() { err := h.VCRRecorder.Stop() @@ -171,8 +204,7 @@ func testFixturesInSeries(ctx context.Context, t *testing.T, testName string, te }) replaceFunc := func(s string) string { - result := strings.Replace(s, uniqueID, "uniqueid111111", -1) - result = strings.Replace(result, project.ProjectID, "cnrm-user", -1) + result := strings.Replace(s, project.ProjectID, "cnrm-user", -1) return result } @@ -525,3 +557,28 @@ func createPausedCC(ctx context.Context, t *testing.T, c client.Client) { t.Fatalf("error creating CC: %v", err) } } + +func writeSeed(seed int64, fileName string) error { + data := strconv.FormatInt(seed, 10) + err := os.WriteFile(fileName, []byte(data), 0644) + if err != nil { + return err + } + return nil +} + +func readSeed(fileName string) (int64, error) { + file, err := os.Open(fileName) + if err != nil { + return 0, err + } + defer file.Close() + + data, err := io.ReadAll(file) + if err != nil { + return 0, err + } + data = bytes.Trim(data, "\x00") + seed := string(data) + return tpgresource.StringToFixed64(seed) +}