Skip to content

Commit

Permalink
Capture VCR record
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Apr 2, 2024
1 parent c60188b commit 1eac19b
Show file tree
Hide file tree
Showing 17 changed files with 49,100 additions and 61 deletions.
44 changes: 41 additions & 3 deletions config/tests/samples/create/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ package create

import (
"context"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp"
"golang.org/x/oauth2/google"
"net/http"
"os"
"path/filepath"
Expand All @@ -27,7 +29,6 @@ import (
"github.com/go-logr/logr"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"golang.org/x/oauth2"
"golang.org/x/oauth2/google"
cloudresourcemanagerv1 "google.golang.org/api/cloudresourcemanager/v1"
"google.golang.org/api/option"
"gopkg.in/dnaeon/go-vcr.v3/recorder"
Expand All @@ -52,7 +53,6 @@ import (
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/kccmanager/nocache"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/controller/registration"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/crd/crdloader"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/gcp"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/k8s"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/logging"
"github.com/GoogleCloudPlatform/k8s-config-connector/pkg/test"
Expand Down Expand Up @@ -297,6 +297,22 @@ func NewHarness(ctx context.Context, t *testing.T) *Harness {
}
testgcp.TestKCCAttachedClusterProject.Set("mock-project")
h.Project = project
} else if os.Getenv("E2E_GCP_TARGET") == "vcr" && os.Getenv("VCR_MODE") == "replay" {
h.Project = testgcp.GCPProject{
ProjectID: "example-project",
ProjectNumber: 12345678,
}
mockCloud := mockgcp.NewMockRoundTripper(t, h.client, storage.NewInMemoryStorage())

roundTripper := http.RoundTripper(mockCloud)

kccConfig.HTTPClient = &http.Client{Transport: roundTripper}

// Also hook the oauth2 library
ctx = context.WithValue(ctx, oauth2.HTTPClient, kccConfig.HTTPClient)
h.Ctx = ctx
h.gcpAccessToken = "dummytoken"
kccConfig.GCPAccessToken = h.gcpAccessToken
} else {
h.Project = testgcp.GetDefaultProject(t)
}
Expand Down Expand Up @@ -346,7 +362,7 @@ func NewHarness(ctx context.Context, t *testing.T) *Harness {
if t := ctx.Value(httpRoundTripperKey); t != nil {
ret = &http.Client{Transport: t.(http.RoundTripper)}
}
dir := "pkg/test/resourcefixture/testdata/vcr/cassette/"
dir := "./testdata/vcr-cassette/"
testName := strings.ReplaceAll(t.Name(), "/", "_")
opts := &recorder.Options{
CassetteName: filepath.Join(dir, testName),
Expand Down Expand Up @@ -525,6 +541,28 @@ func MaybeSkip(t *testing.T, name string, resources []*unstructured.Unstructured
}
}
}
if os.Getenv("E2E_GCP_TARGET") == "vcr" {
switch name {
case "basicalloydbbackup":
//case "fullalloydbbackup":
case "basicalloydbcluster":
case "basicalloydbsecondarycluster":
case "fullalloydbcluster":
case "restorebackupalloydbcluster":
case "basicalloydbinstance":
//case "basicalloydbsecondaryinstance":
case "fullalloydbinstance":
case "readalloydbinstance":
case "zonalalloydbinstance":
case "databasealloydbuser":
case "iamalloydbuser":

case "computenodegroup":
case "computenodetemplate":
default:
t.Skipf("test %v not suppported by vcr; skipping", name)
}
}
}

func (h *Harness) waitForCRDReady(obj client.Object) {
Expand Down
4 changes: 2 additions & 2 deletions scripts/github-actions/ga-vcr-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ source ${REPO_ROOT}/scripts/fetch_ext_bins.sh && \
cd ${REPO_ROOT}/
echo "Running e2e vcr tests..."
E2E_KUBE_TARGET=envtest \
RUN_E2E=1 E2E_GCP_TARGET=vcr VCR_MODE=record \
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures/computenodetemplate 2>&1
RUN_E2E=1 E2E_GCP_TARGET=vcr VCR_MODE=replay \
go test -test.count=1 -timeout 3600s -v ./tests/e2e -run TestAllInSeries/fixtures 2>&1
Loading

0 comments on commit 1eac19b

Please sign in to comment.