Skip to content

Commit ebf5e7e

Browse files
committed
bump go-vcr.v4 + move matching logic to the sdk-go
1 parent 288f8bb commit ebf5e7e

File tree

6 files changed

+49
-599
lines changed

6 files changed

+49
-599
lines changed

go.mod

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -155,18 +155,19 @@ require (
155155
go.opentelemetry.io/otel/metric v1.36.0 // indirect
156156
go.opentelemetry.io/otel/trace v1.36.0 // indirect
157157
golang.org/x/exp v0.0.0-20230809150735-7b3493d9a819 // indirect
158-
golang.org/x/mod v0.25.0 // indirect
159-
golang.org/x/net v0.41.0 // indirect
158+
golang.org/x/mod v0.26.0 // indirect
159+
golang.org/x/net v0.42.0 // indirect
160160
golang.org/x/sync v0.16.0 // indirect
161161
golang.org/x/sys v0.34.0 // indirect
162-
golang.org/x/text v0.27.0 // indirect
162+
golang.org/x/text v0.28.0 // indirect
163163
golang.org/x/time v0.3.0 // indirect
164-
golang.org/x/tools v0.34.0 // indirect
164+
golang.org/x/tools v0.35.0 // indirect
165165
google.golang.org/appengine v1.6.8 // indirect
166166
google.golang.org/genproto/googleapis/api v0.0.0-20250505200425-f936aa4a68b2 // indirect
167167
google.golang.org/genproto/googleapis/rpc v0.0.0-20250505200425-f936aa4a68b2 // indirect
168168
google.golang.org/grpc v1.72.1 // indirect
169169
google.golang.org/protobuf v1.36.6 // indirect
170+
gopkg.in/dnaeon/go-vcr.v4 v4.0.5 // indirect
170171
gopkg.in/ini.v1 v1.66.4 // indirect
171172
gopkg.in/yaml.v2 v2.4.0 // indirect
172173
gopkg.in/yaml.v3 v3.0.1 // indirect

go.sum

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -152,8 +152,6 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
152152
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
153153
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
154154
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
155-
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
156-
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
157155
github.com/docker/docker v28.3.3+incompatible h1:Dypm25kh4rmk49v1eiVbsAtpAsYURjYkaKubwuBdxEI=
158156
github.com/docker/docker v28.3.3+incompatible/go.mod h1:eEKB0N0r5NX/I1kEveEz05bcu8tLC/8azJZsviup8Sk=
159157
github.com/docker/go-connections v0.4.0 h1:El9xVISelRB7BuFusrZozjnkIM5YnzCViNKohAFqRJQ=
@@ -197,6 +195,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
197195
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
198196
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
199197
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
198+
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
199+
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
200200
github.com/gogo/protobuf v1.3.2 h1:Ov1cvc58UF3b5XjBnZv7+opcTcQFZebYjWzi34vdm4Q=
201201
github.com/gogo/protobuf v1.3.2/go.mod h1:P1XiOD3dCwIKUDQYPy72D8LYyHL2YPYrpS2s69NZV8Q=
202202
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
@@ -449,8 +449,6 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
449449
github.com/rogpeppe/go-internal v1.13.1 h1:KvO1DLK/DRN07sQ1LQKScxyZJuNnedQ5/wKSR38lUII=
450450
github.com/rogpeppe/go-internal v1.13.1/go.mod h1:uMEvuHeurkdAXX61udpOXGD/AzZDWNMNyH2VO9fmH0o=
451451
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
452-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686 h1:rSbtkU5fMMXbv0qwIH5dBq+TvAYnbClahwPP1KtN9bs=
453-
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686/go.mod h1:fw6BmcfYRs2BEHYW0c3/rR0JgZHvdx6uMYqpeUJx3Bc=
454452
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
455453
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
456454
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
@@ -589,8 +587,8 @@ golang.org/x/mod v0.4.0/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
589587
golang.org/x/mod v0.4.1/go.mod h1:s0Qsj1ACt9ePp/hMypM3fl4fZqREWJwdYDEqhRiZZUA=
590588
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4=
591589
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs=
592-
golang.org/x/mod v0.25.0 h1:n7a+ZbQKQA/Ysbyb0/6IbB1H/X41mKgbhfv7AfG/44w=
593-
golang.org/x/mod v0.25.0/go.mod h1:IXM97Txy2VM4PJ3gI61r1YEk/gAj6zAHN3AdZt6S9Ww=
590+
golang.org/x/mod v0.26.0 h1:EGMPT//Ezu+ylkCijjPc+f4Aih7sZvaAr+O3EHBxvZg=
591+
golang.org/x/mod v0.26.0/go.mod h1:/j6NAhSk8iQ723BGAUyoAcn7SlD7s15Dp9Nd/SfeaFQ=
594592
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
595593
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
596594
golang.org/x/net v0.0.0-20190108225652-1e06a53dbb7e/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
@@ -626,8 +624,8 @@ golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug
626624
golang.org/x/net v0.2.0/go.mod h1:KqCZLdyyvdV855qA2rE3GC2aiw5xGR5TEjj8smXukLY=
627625
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs=
628626
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg=
629-
golang.org/x/net v0.41.0 h1:vBTly1HeNPEn3wtREYfy4GZ/NECgw2Cnl+nK6Nz3uvw=
630-
golang.org/x/net v0.41.0/go.mod h1:B/K4NNqkfmg07DQYrbwvSluqCJOOXwUjeb/5lOisjbA=
627+
golang.org/x/net v0.42.0 h1:jzkYrhi3YQWD6MLBJcsklgQsoAcw89EcZbJw8Z614hs=
628+
golang.org/x/net v0.42.0/go.mod h1:FF1RA5d3u7nAYA4z2TkclSCKh68eSXtiFwcWQpPXdt8=
631629
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
632630
golang.org/x/oauth2 v0.0.0-20190226205417-e64efc72b421/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
633631
golang.org/x/oauth2 v0.0.0-20190604053449-0f29369cfe45/go.mod h1:gOpvHmFTYa4IltrdGE7lF6nIHvwfUNPOp7c8zoXwtLw=
@@ -722,8 +720,8 @@ golang.org/x/text v0.4.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
722720
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8=
723721
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8=
724722
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE=
725-
golang.org/x/text v0.27.0 h1:4fGWRpyh641NLlecmyl4LOe6yDdfaYNrGb2zdfo4JV4=
726-
golang.org/x/text v0.27.0/go.mod h1:1D28KMCvyooCX9hBiosv5Tz/+YLxj0j7XhWjpSUF7CU=
723+
golang.org/x/text v0.28.0 h1:rhazDwis8INMIwQ4tpjLDzUhx6RlXqZNPEM0huQojng=
724+
golang.org/x/text v0.28.0/go.mod h1:U8nCwOR8jO/marOQ0QbDiOngZVEBB7MAiitBuMjXiNU=
727725
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
728726
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
729727
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
@@ -782,8 +780,8 @@ golang.org/x/tools v0.0.0-20210108195828-e2f9c7f1fc8e/go.mod h1:emZCQorbCU4vsT4f
782780
golang.org/x/tools v0.1.0/go.mod h1:xkSsbof2nBLbhDlRMhhhyNLN/zl3eTqcnHD5viDpcZ0=
783781
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc=
784782
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU=
785-
golang.org/x/tools v0.34.0 h1:qIpSLOxeCYGg9TrcJokLBG4KFA6d795g0xkBkiESGlo=
786-
golang.org/x/tools v0.34.0/go.mod h1:pAP9OwEaY1CAW3HOmg3hLZC5Z0CCmzjAF2UQMSqNARg=
783+
golang.org/x/tools v0.35.0 h1:mBffYraMEf7aa0sB+NuKnuCy8qI/9Bughn8dC2Gu5r0=
784+
golang.org/x/tools v0.35.0/go.mod h1:NKdj5HkL/73byiZSJjqJgKn3ep7KjFkBOkR/Hps3VPw=
787785
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
788786
golang.org/x/xerrors v0.0.0-20191011141410-1b5146add898/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
789787
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
@@ -894,6 +892,8 @@ gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntN
894892
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
895893
gopkg.in/dnaeon/go-vcr.v3 v3.2.0 h1:Rltp0Vf+Aq0u4rQXgmXgtgoRDStTnFN83cWgSGSoRzM=
896894
gopkg.in/dnaeon/go-vcr.v3 v3.2.0/go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag=
895+
gopkg.in/dnaeon/go-vcr.v4 v4.0.5 h1:I0hpTIvD5rII+8LgYGrHMA2d4SQPoL6u7ZvJakWKsiA=
896+
gopkg.in/dnaeon/go-vcr.v4 v4.0.5/go.mod h1:dRos81TkW9C1WJt6tTaE+uV2Lo8qJT3AG2b35+CB/nQ=
897897
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
898898
gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
899899
gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=

internal/acctest/acctest.go

Lines changed: 29 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,25 @@
11
package acctest
22

33
import (
4+
"flag"
5+
"net/http"
46
"os"
5-
"strconv"
67
"strings"
78
"testing"
89
"time"
910

1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
12+
"github.com/scaleway/scaleway-sdk-go/scw"
13+
"github.com/scaleway/scaleway-sdk-go/vcr"
1114
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
1215
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
1316
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
1417
"github.com/stretchr/testify/require"
1518
)
1619

20+
// UpdateCassettes will update all cassettes of a given test
21+
var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") == "true", "Record Cassettes")
22+
1723
func PreCheck(_ *testing.T) {}
1824

1925
type TestTools struct {
@@ -23,6 +29,26 @@ type TestTools struct {
2329
Cleanup func()
2430
}
2531

32+
func NewRecordedClient(t *testing.T, pkgFolder string, update bool) (client *http.Client, cleanup func(), err error) {
33+
t.Helper()
34+
35+
r, err := vcr.NewHTTPRecorder(t, pkgFolder, update)
36+
if err != nil {
37+
return nil, nil, err
38+
}
39+
40+
retryOptions := transport.RetryableTransportOptions{}
41+
if !update {
42+
retryOptions.RetryWaitMax = scw.TimeDurationPtr(0)
43+
}
44+
45+
return &http.Client{
46+
Transport: transport.NewRetryableTransportWithOptions(r, retryOptions),
47+
}, func() {
48+
require.NoError(t, r.Stop()) // Make sure recorder is stopped once done with it
49+
}, nil
50+
}
51+
2652
func NewTestTools(t *testing.T) *TestTools {
2753
t.Helper()
2854

@@ -33,8 +59,8 @@ func NewTestTools(t *testing.T) *TestTools {
3359
t.Fatalf("cannot detect working directory for testing")
3460
}
3561

36-
// Create a http client with recording capabilities
37-
httpClient, cleanup, err := getHTTPRecoder(t, folder, *UpdateCassettes)
62+
// Create an HTTP client with recording capabilities
63+
httpClient, cleanup, err := NewRecordedClient(t, folder, *UpdateCassettes)
3864
require.NoError(t, err)
3965

4066
// Create meta that will be passed in the provider config
@@ -62,46 +88,6 @@ func NewTestTools(t *testing.T) *TestTools {
6288
}
6389
}
6490

65-
// Test Generated name has format: "{prefix}-{generated_number}
66-
// example: test-acc-scaleway-project-3723338038624371236
67-
func extractTestGeneratedNamePrefix(name string) string {
68-
// {prefix}-{generated}
69-
// ^
70-
dashIndex := strings.LastIndex(name, "-")
71-
72-
generated := name[dashIndex+1:]
73-
_, generatedToIntErr := strconv.ParseInt(generated, 10, 64)
74-
75-
if dashIndex == -1 || generatedToIntErr != nil {
76-
// some are only {name}
77-
return name
78-
}
79-
80-
// {prefix}
81-
return name[:dashIndex]
82-
}
83-
84-
// Generated names have format: "tf-{prefix}-{generated1}-{generated2}"
85-
// example: tf-sg-gifted-yonath
86-
func extractGeneratedNamePrefix(name string) string {
87-
if strings.Count(name, "-") < 3 {
88-
return name
89-
}
90-
// tf-{prefix}-gifted-yonath
91-
name = strings.TrimPrefix(name, "tf-")
92-
93-
// {prefix}-gifted-yonath
94-
// ^
95-
dashIndex := strings.LastIndex(name, "-")
96-
name = name[:dashIndex]
97-
// {prefix}-gifted
98-
// ^
99-
dashIndex = strings.LastIndex(name, "-")
100-
name = name[:dashIndex]
101-
102-
return name
103-
}
104-
10591
// IsTestResource returns true if given resource identifier is from terraform test
10692
// identifier should be resource name but some resource don't have names
10793
// return true if identifier match regex "tf[-_]test"

internal/acctest/acctest_test.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ import (
77
"strings"
88
"testing"
99

10-
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
11-
"gopkg.in/dnaeon/go-vcr.v3/cassette"
10+
"github.com/scaleway/scaleway-sdk-go/vcr"
11+
"gopkg.in/dnaeon/go-vcr.v4/pkg/cassette"
1212
)
1313

1414
var barMemberCreationBody = `{
@@ -488,7 +488,7 @@ var testBodyMatcherCases = []struct {
488488

489489
func TestCassetteMatcher(t *testing.T) {
490490
for i, test := range testBodyMatcherCases {
491-
shouldMatch := acctest.CassetteMatcher(test.requestBody, *test.cassetteBody)
491+
shouldMatch := vcr.CassetteMatcher(test.requestBody, *test.cassetteBody)
492492
if shouldMatch != test.shouldMatch {
493493
t.Errorf("test %d: expected %v, got %v", i, test.shouldMatch, shouldMatch)
494494
t.Errorf("requestBody: %s", test.requestBody.Body)

0 commit comments

Comments
 (0)