Skip to content

Commit

Permalink
replay
Browse files Browse the repository at this point in the history
  • Loading branch information
gemmahou committed Mar 29, 2024
1 parent e3c3b01 commit c60188b
Show file tree
Hide file tree
Showing 5 changed files with 1,001 additions and 144 deletions.
14 changes: 11 additions & 3 deletions config/tests/samples/create/harness.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ import (
"testing"
"time"

"gopkg.in/dnaeon/go-vcr.v3/recorder"

"github.com/go-logr/logr"
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
"golang.org/x/oauth2"
Expand Down Expand Up @@ -333,6 +331,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 == "record" {
vcrMode = recorder.ModeRecordOnly
} else if input == "replay" {
vcrMode = recorder.ModeReplayOnly
} else {
t.Fatalf("[VCR] VCR_MODE should be set to record or replay; value %q is not known", input)
}
transport_tpg.DefaultHTTPClientTransformer = func(ctx context.Context, inner *http.Client) *http.Client {
ret := inner
if t := ctx.Value(httpRoundTripperKey); t != nil {
Expand All @@ -342,7 +350,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)
Expand Down
30 changes: 30 additions & 0 deletions go.sum

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit c60188b

Please sign in to comment.