Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
e239b27
bump go-vcr.v4 + move matching logic to the sdk-go
Mia-Cross Aug 28, 2025
df90a80
ns ok: webhosting
Mia-Cross Aug 28, 2025
adf678c
ns ok: vc + vpcgw
Mia-Cross Aug 28, 2025
90edb12
ns ok: rdb + registry + sdb
Mia-Cross Aug 28, 2025
06c9f61
ns ok: jobs + keymanager + marketplace + mnq
Mia-Cross Aug 28, 2025
13c1769
ns ok: edge-services + file + flexible-ip + inference
Mia-Cross Aug 28, 2025
5626bf4
ns ok: autoscaling + az + billing + domain
Mia-Cross Aug 28, 2025
0a5c76e
ns ok: applesilicon + baremetal
Mia-Cross Aug 29, 2025
39d38e0
ns ok: iot + k8s + mongodb
Mia-Cross Sep 1, 2025
5537d5d
ns ok: ipam + redis + secret
Mia-Cross Sep 1, 2025
c74e542
ns ok: lb + tem
Mia-Cross Sep 1, 2025
f583701
ns ok: container + function
Mia-Cross Sep 1, 2025
be2a850
ns ok: block + cockpit + object
Mia-Cross Sep 3, 2025
02d4c94
ns ok: account + iam + instance
Mia-Cross Sep 5, 2025
b14191d
customize vcr with additional hooks
Mia-Cross Sep 22, 2025
b16b175
baremetal ok
Mia-Cross Sep 23, 2025
1330c0c
flexibleip ok
Mia-Cross Sep 23, 2025
78cb01e
vpcgw ok
Mia-Cross Sep 23, 2025
9286be2
vpc ok ? (route=ok, ds-vpc-pn-vpc-id=flaky)
Mia-Cross Sep 23, 2025
dedfcb1
secret ok
Mia-Cross Sep 23, 2025
580d5f6
registry ok
Mia-Cross Sep 23, 2025
5b4d7b9
rdb ok
Mia-Cross Sep 23, 2025
e174665
k8s ok
Mia-Cross Sep 23, 2025
e4b231c
object ok
Mia-Cross Sep 23, 2025
665f58c
mnq ok
Mia-Cross Sep 23, 2025
b0591dc
lb ok
Mia-Cross Sep 23, 2025
74c7d79
ipam ok
Mia-Cross Sep 23, 2025
1d2ff3a
instance ok
Mia-Cross Sep 23, 2025
9020cad
iam ok
Mia-Cross Sep 23, 2025
d73b86c
container ok
Mia-Cross Sep 23, 2025
0300072
fix drift mongodb
Mia-Cross Sep 23, 2025
b154842
tfproviderlint
Mia-Cross Sep 23, 2025
f9b035b
rdb ok
Mia-Cross Sep 24, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
2 changes: 1 addition & 1 deletion cmd/vcr-compressor/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/scaleway/scaleway-sdk-go/api/k8s/v1"
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
"gopkg.in/dnaeon/go-vcr.v3/cassette"
"gopkg.in/dnaeon/go-vcr.v4/pkg/cassette"
)

var transientStates = map[string]bool{
Expand Down
2 changes: 1 addition & 1 deletion cmd/vcr-viewer/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (
"log"
"os"

"gopkg.in/dnaeon/go-vcr.v3/cassette"
"gopkg.in/dnaeon/go-vcr.v4/pkg/cassette"
)

func main() {
Expand Down
5 changes: 3 additions & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,10 @@ require (
github.com/nats-io/jwt/v2 v2.8.0
github.com/nats-io/nats.go v1.45.0
github.com/robfig/cron/v3 v3.0.1
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20250922153756-a46989078274
github.com/stretchr/testify v1.11.1
golang.org/x/crypto v0.42.0
gopkg.in/dnaeon/go-vcr.v3 v3.2.0
gopkg.in/dnaeon/go-vcr.v4 v4.0.5
)

require (
Expand Down Expand Up @@ -81,6 +81,7 @@ require (
github.com/fsnotify/fsnotify v1.8.0 // indirect
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/golang/protobuf v1.5.4 // indirect
github.com/google/shlex v0.0.0-20191202100458-e7afc7fbc510 // indirect
github.com/gookit/color v1.5.1 // indirect
Expand Down
12 changes: 6 additions & 6 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,6 @@ github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc h1:U9qPSI2PIWSS1
github.com/davecgh/go-spew v1.1.2-0.20180830191138-d8f796af33cc/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/distribution/reference v0.5.0 h1:/FUIFXtfc/x2gpa5/VGfiGLuOIdYa1t65IKK2OFGvA0=
github.com/distribution/reference v0.5.0/go.mod h1:BbU0aIcezP1/5jX/8MP0YiH4SdvB5Y4f/wlDRiLyi3E=
github.com/dnaeon/go-vcr v1.2.0 h1:zHCHvJYTMh1N7xnV7zf1m1GPBF9Ad0Jk/whtQ1663qI=
github.com/dnaeon/go-vcr v1.2.0/go.mod h1:R4UdLID7HZT3taECzJs4YgbbH6PIGXB6W/sc5OLb6RQ=
github.com/dnephin/pflag v1.0.7 h1:oxONGlWxhmUct0YzKTgrpQv9AUA1wtPBn7zuSjJqptk=
github.com/dnephin/pflag v1.0.7/go.mod h1:uxE91IoWURlOiTUIA8Mq5ZZkAv3dPUfZNaT80Zm7OQE=
github.com/docker/docker v28.4.0+incompatible h1:KVC7bz5zJY/4AZe/78BIvCnPsLaC9T/zh72xnlrTTOk=
Expand Down Expand Up @@ -202,6 +200,8 @@ github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre
github.com/go-sql-driver/mysql v1.5.0/go.mod h1:DCzpHaOWr8IXmIStZouvnhqoel9Qv2LBy8hT2VhHyBg=
github.com/go-test/deep v1.0.3 h1:ZrJSEWsXzPOxaZnFteGEfooLba+ju3FYIbOrS+rQd68=
github.com/go-test/deep v1.0.3/go.mod h1:wGDj63lr65AM2AQyKZd/NYHGb0R+1RLqB8NKt3aSFNA=
github.com/goccy/go-yaml v1.18.0 h1:8W7wMFS12Pcas7KU+VVkaiCng+kG8QiFeFwzFb+rwuw=
github.com/goccy/go-yaml v1.18.0/go.mod h1:XBurs7gK8ATbW4ZPGKgcbrY1Br56PdM69F7LkFRi1kA=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/groupcache v0.0.0-20190702054246-869f871628b6/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
github.com/golang/groupcache v0.0.0-20191227052852-215e87163ea7/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc=
Expand Down Expand Up @@ -454,8 +454,8 @@ github.com/rogpeppe/go-internal v1.3.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFR
github.com/rogpeppe/go-internal v1.14.1 h1:UQB4HGPB6osV0SQTLymcB4TgvyWu6ZyliaW0tI/otEQ=
github.com/rogpeppe/go-internal v1.14.1/go.mod h1:MaRKkUm5W0goXpeCfT7UZI6fk/L7L7so1lCWt35ZSgc=
github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686 h1:rSbtkU5fMMXbv0qwIH5dBq+TvAYnbClahwPP1KtN9bs=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.34.0.20250721082157-a9b7a7bd9686/go.mod h1:fw6BmcfYRs2BEHYW0c3/rR0JgZHvdx6uMYqpeUJx3Bc=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20250922153756-a46989078274 h1:sYgzyz/awhD1Jy+btI7Nnp0m2fsl4hXn10RuD7rSpWY=
github.com/scaleway/scaleway-sdk-go v1.0.0-beta.35.0.20250922153756-a46989078274/go.mod h1:DVB9HV7nK7TdTRqlpdxw6T0Wxg+aB9xPBEpO3aM2iqQ=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3 h1:n661drycOFuPLCN3Uc8sB6B/s6Z4t2xvBgU1htSHuq8=
github.com/sergi/go-diff v1.3.2-0.20230802210424-5b0b94c5c0d3/go.mod h1:A0bzQcvG0E7Rwjx0REVgAGH58e96+X0MeOfepqsbeW4=
github.com/shopspring/decimal v1.2.0/go.mod h1:DKyhrW/HYNuLGql+MJL6WCR6knT2jwCFRcu2hWCYk4o=
Expand Down Expand Up @@ -896,8 +896,8 @@ gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8
gopkg.in/check.v1 v1.0.0-20180628173108-788fd7840127/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c h1:Hei/4ADfdWqJk1ZMxUNpqntNwaWcugrBjAiHlqqRiVk=
gopkg.in/check.v1 v1.0.0-20201130134442-10cb98267c6c/go.mod h1:JHkPIbrfpd72SG/EVd6muEfDQjcINNoR0C8j2r3qZ4Q=
gopkg.in/dnaeon/go-vcr.v3 v3.2.0 h1:Rltp0Vf+Aq0u4rQXgmXgtgoRDStTnFN83cWgSGSoRzM=
gopkg.in/dnaeon/go-vcr.v3 v3.2.0/go.mod h1:2IMOnnlx9I6u9x+YBsM3tAMx6AlOxnJ0pWxQAzZ79Ag=
gopkg.in/dnaeon/go-vcr.v4 v4.0.5 h1:I0hpTIvD5rII+8LgYGrHMA2d4SQPoL6u7ZvJakWKsiA=
gopkg.in/dnaeon/go-vcr.v4 v4.0.5/go.mod h1:dRos81TkW9C1WJt6tTaE+uV2Lo8qJT3AG2b35+CB/nQ=
gopkg.in/errgo.v2 v2.1.0/go.mod h1:hNsd1EY+bozCKY1Ytp96fpM3vjJbqLJn88ws8XvfDNI=
gopkg.in/ini.v1 v1.66.4 h1:SsAcf+mM7mRZo2nJNGt8mZCjG8ZRaNGMURJw7BsIST4=
gopkg.in/ini.v1 v1.66.4/go.mod h1:pNLf8WUiyNEtQjuu5G5vTm06TEv9tsIgeAvK8hOrP4k=
Expand Down
109 changes: 66 additions & 43 deletions internal/acctest/acctest.go
Original file line number Diff line number Diff line change
@@ -1,19 +1,30 @@
package acctest

import (
"encoding/base64"
"encoding/json"
"encoding/xml"
"flag"
"net/http"
"os"
"strconv"
"strings"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/scaleway/scaleway-sdk-go/scw"
"github.com/scaleway/scaleway-sdk-go/vcr"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/meta"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/provider"
"github.com/scaleway/terraform-provider-scaleway/v2/internal/transport"
"github.com/stretchr/testify/require"
"gopkg.in/dnaeon/go-vcr.v4/pkg/cassette"
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
)

// UpdateCassettes will update all cassettes of a given test
var UpdateCassettes = flag.Bool("cassettes", os.Getenv("TF_UPDATE_CASSETTES") == "true", "Record Cassettes")

func PreCheck(_ *testing.T) {}

type TestTools struct {
Expand All @@ -23,6 +34,58 @@ type TestTools struct {
Cleanup func()
}

// s3Encoder encodes binary payloads as base64 because serialization changed on go-vcr.v4
func s3Encoder(i *cassette.Interaction) error {
if strings.HasSuffix(i.Request.Host, "scw.cloud") {
if i.Request.Body != "" && i.Request.Headers.Get("Content-Type") == "application/octet-stream" {
requestBody := []byte(i.Request.Body)
if !json.Valid(requestBody) {
err := xml.Unmarshal(requestBody, new(any))
if err != nil {
i.Request.Body = base64.StdEncoding.EncodeToString(requestBody)
}
}
}

if i.Response.Body != "" && i.Response.Headers.Get("Content-Type") == "binary/octet-stream" {
responseBody := []byte(i.Response.Body)
if !json.Valid(responseBody) {
err := xml.Unmarshal(responseBody, new(any))
if err != nil {
i.Response.Body = base64.StdEncoding.EncodeToString(responseBody)
}
}
}
}

return nil
}

func NewRecordedClient(t *testing.T, pkgFolder string, update bool) (client *http.Client, cleanup func(), err error) {
t.Helper()

s3EncoderHook := vcr.AdditionalHook{
HookFunc: s3Encoder,
Kind: recorder.AfterCaptureHook,
}

r, err := vcr.NewHTTPRecorder(t, pkgFolder, update, nil, s3EncoderHook)
if err != nil {
return nil, nil, err
}

retryOptions := transport.RetryableTransportOptions{}
if !update {
retryOptions.RetryWaitMax = scw.TimeDurationPtr(0)
}

return &http.Client{
Transport: transport.NewRetryableTransportWithOptions(r, retryOptions),
}, func() {
require.NoError(t, r.Stop()) // Make sure recorder is stopped once done with it
}, nil
}

func NewTestTools(t *testing.T) *TestTools {
t.Helper()

Expand All @@ -33,8 +96,8 @@ func NewTestTools(t *testing.T) *TestTools {
t.Fatalf("cannot detect working directory for testing")
}

// Create a http client with recording capabilities
httpClient, cleanup, err := getHTTPRecoder(t, folder, *UpdateCassettes)
// Create an HTTP client with recording capabilities
httpClient, cleanup, err := NewRecordedClient(t, folder, *UpdateCassettes)
require.NoError(t, err)

// Create meta that will be passed in the provider config
Expand Down Expand Up @@ -62,46 +125,6 @@ func NewTestTools(t *testing.T) *TestTools {
}
}

// Test Generated name has format: "{prefix}-{generated_number}
// example: test-acc-scaleway-project-3723338038624371236
func extractTestGeneratedNamePrefix(name string) string {
// {prefix}-{generated}
// ^
dashIndex := strings.LastIndex(name, "-")

generated := name[dashIndex+1:]
_, generatedToIntErr := strconv.ParseInt(generated, 10, 64)

if dashIndex == -1 || generatedToIntErr != nil {
// some are only {name}
return name
}

// {prefix}
return name[:dashIndex]
}

// Generated names have format: "tf-{prefix}-{generated1}-{generated2}"
// example: tf-sg-gifted-yonath
func extractGeneratedNamePrefix(name string) string {
if strings.Count(name, "-") < 3 {
return name
}
// tf-{prefix}-gifted-yonath
name = strings.TrimPrefix(name, "tf-")

// {prefix}-gifted-yonath
// ^
dashIndex := strings.LastIndex(name, "-")
name = name[:dashIndex]
// {prefix}-gifted
// ^
dashIndex = strings.LastIndex(name, "-")
name = name[:dashIndex]

return name
}

// IsTestResource returns true if given resource identifier is from terraform test
// identifier should be resource name but some resource don't have names
// return true if identifier match regex "tf[-_]test"
Expand Down
6 changes: 3 additions & 3 deletions internal/acctest/acctest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"strings"
"testing"

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

var barMemberCreationBody = `{
Expand Down Expand Up @@ -488,7 +488,7 @@ var testBodyMatcherCases = []struct {

func TestCassetteMatcher(t *testing.T) {
for i, test := range testBodyMatcherCases {
shouldMatch := acctest.CassetteMatcher(test.requestBody, *test.cassetteBody)
shouldMatch := vcr.CassetteMatcher(test.requestBody, *test.cassetteBody)
if shouldMatch != test.shouldMatch {
t.Errorf("test %d: expected %v, got %v", i, test.shouldMatch, shouldMatch)
t.Errorf("requestBody: %s", test.requestBody.Body)
Expand Down
Loading
Loading