Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 34 additions & 1 deletion core/testing.go
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,23 @@ func createTestClient(
// because they will be executed without waiting.
var DefaultRetryInterval *time.Duration

var foldersUsingVCRv4 = []string{
"instance",
}

func folderUsesVCRv4(fullFolderPath string) bool {
fullPathSplit := strings.Split(fullFolderPath, "/")

folder := fullPathSplit[len(fullPathSplit)-1]
for _, migratedFolder := range foldersUsingVCRv4 {
if migratedFolder == folder {
return true
}
}

return false
}

// Run a CLI integration test. See TestConfig for configuration option
func Test(config *TestConfig) func(t *testing.T) {
return func(t *testing.T) {
Expand Down Expand Up @@ -348,7 +365,23 @@ func Test(config *TestConfig) func(t *testing.T) {
ctx = interactive.InjectMockResponseToContext(ctx, config.PromptResponseMocks)
}

httpClient, cleanup, err := getHTTPRecoder(t, *UpdateCassettes)
folder, err := os.Getwd()
if err != nil {
t.Fatalf("cannot detect working directory for testing")
}

// Create an HTTP client with recording capabilities
var (
httpClient *http.Client
cleanup func()
)

if folderUsesVCRv4(folder) {
httpClient, cleanup, err = newHTTPRecorder(t, folder, *UpdateCassettes)
} else {
httpClient, cleanup, err = getHTTPRecoder(t, *UpdateCassettes)
}

require.NoError(t, err)
defer cleanup()

Expand Down
14 changes: 14 additions & 0 deletions core/testing_recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import (

"github.com/dnaeon/go-vcr/cassette"
"github.com/dnaeon/go-vcr/recorder"
"github.com/scaleway/scaleway-sdk-go/vcr"
"github.com/stretchr/testify/assert"
)

Expand Down Expand Up @@ -155,3 +156,16 @@ func getHTTPRecoder(t *testing.T, update bool) (client *http.Client, cleanup fun
assert.NoError(t, r.Stop()) // Make sure recorder is stopped once done with it
}, nil
}

func newHTTPRecorder(t *testing.T, folder string, update bool) (*http.Client, func(), error) {
t.Helper()

r, err := vcr.NewHTTPRecorder(t, folder, update, &SocketPassthroughTransport{})
if err != nil {
return nil, nil, err
}

return &http.Client{Transport: &retryableHTTPTransport{transport: r}}, func() {
assert.NoError(t, r.Stop()) // Make sure recorder is stopped once done with it
}, nil
}
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ require (
github.com/go-logr/logr v1.4.3 // indirect
github.com/go-logr/stdr v1.2.2 // indirect
github.com/go-viper/mapstructure/v2 v2.4.0 // indirect
github.com/goccy/go-yaml v1.18.0 // indirect
github.com/gofrs/flock v0.12.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/golang-jwt/jwt/v4 v4.5.2 // indirect
Expand Down Expand Up @@ -207,6 +208,7 @@ require (
google.golang.org/genproto/googleapis/rpc v0.0.0-20250721164621-a45f3dfb1074 // indirect
google.golang.org/grpc v1.74.2 // indirect
google.golang.org/protobuf v1.36.9 // indirect
gopkg.in/dnaeon/go-vcr.v4 v4.0.5 // indirect
gopkg.in/warnings.v0 v0.1.2 // indirect
gopkg.in/yaml.v2 v2.4.0 // indirect
gotest.tools/gotestsum v1.12.3 // indirect
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ func Test_ServerTerminate(t *testing.T) {
_, err := api.GetIP(&instanceSDK.GetIPRequest{
IP: server.PublicIP.ID,
})
require.ErrorAs(t, err, new(*scw.PermissionsDeniedError))
require.ErrorAs(t, err, new(*scw.ResourceNotFoundError))
},
),
DisableParallel: true,
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
🎲🎲🎲 EXIT CODE: 0 🎲🎲🎲
🟩🟩🟩 STDOUT️ 🟩🟩🟩️
Server.ID e127680a-3606-4118-b785-d76e87c16931
Server.Name cli-srv-eager-tereshkova
Server.Organization d3520a52-2c75-4ba0-bda8-82dd087f07f2
Server.Project d3520a52-2c75-4ba0-bda8-82dd087f07f2
Server.ID 8b0cc204-0bd7-4ddb-b57e-f0cd4378ab0f
Server.Name cli-srv-funny-curran
Server.Organization fa1e3217-dc80-42ac-85c3-3f034b78b552
Server.Project fa1e3217-dc80-42ac-85c3-3f034b78b552
Server.AllowedActions.0 poweron
Server.AllowedActions.1 backup
Server.CommercialType POP2-2C-8G
Server.CreationDate few seconds ago
Server.DynamicIPRequired false
Server.RoutedIPEnabled true
Server.EnableIPv6 false
Server.Hostname cli-srv-eager-tereshkova
Server.Image.ID 63d40353-5519-46d0-9172-ccf4885954e1
Server.Hostname cli-srv-funny-curran
Server.Image.ID 6d3c053e-c728-4294-b23a-560b62a4d592
Server.Image.Name Ubuntu 22.04 Jammy Jellyfish
Server.Image.Arch x86_64
Server.Image.CreationDate few seconds ago
Expand All @@ -21,34 +21,35 @@ Server.Image.ExtraVolumes 0
Server.Image.FromServer -
Server.Image.Organization 51b656e3-4865-41e8-adbc-0c45bdd780db
Server.Image.Public true
Server.Image.RootVolume 905845fc-a6eb-4401-8e9d-5810071b7119
Server.Image.RootVolume 36b4ce54-c67a-4f68-ab74-839515834352
Server.Image.State available
Server.Image.Project 51b656e3-4865-41e8-adbc-0c45bdd780db
Server.Image.Zone fr-par-1
Server.Protected false
Server.MacAddress de:00:00:b5:91:c3
Server.MacAddress de:00:00:d0:04:a1
Server.ModificationDate few seconds ago
Server.State archived
Server.BootType local
Server.Volumes.0.ID 26f21c8e-6de6-443e-8d64-d039c9e2dfa6
Server.Volumes.0.ID d98ba8fa-0e20-45df-99de-ed186191d104
Server.Volumes.0.VolumeType sbs_volume
Server.Volumes.0.State available
Server.Volumes.0.Boot false
Server.Volumes.0.Zone fr-par-1
Server.SecurityGroup.ID 1c1fc99f-b2de-408d-9eb0-da801a3e2744
Server.SecurityGroup.ID da505169-540e-4c2b-b0da-c854139224e0
Server.SecurityGroup.Name Default security group
Server.StateDetail -
Server.Arch x86_64
Server.Zone fr-par-1
Server.Filesystems.0.FilesystemID aab9e768-c1e9-407a-829c-4be5a38787dd
Server.Filesystems.0.FilesystemID 76ec2ddd-9383-4898-bf7d-d3cbf2daac0f
Server.Filesystems.0.State available
Server.EndOfService false
🟩🟩🟩 JSON STDOUT 🟩🟩🟩
{
"server": {
"id": "e127680a-3606-4118-b785-d76e87c16931",
"name": "cli-srv-eager-tereshkova",
"organization": "d3520a52-2c75-4ba0-bda8-82dd087f07f2",
"project": "d3520a52-2c75-4ba0-bda8-82dd087f07f2",
"id": "8b0cc204-0bd7-4ddb-b57e-f0cd4378ab0f",
"name": "cli-srv-funny-curran",
"organization": "fa1e3217-dc80-42ac-85c3-3f034b78b552",
"project": "fa1e3217-dc80-42ac-85c3-3f034b78b552",
"allowed_actions": [
"poweron",
"backup"
Expand All @@ -59,9 +60,9 @@ Server.EndOfService false
"dynamic_ip_required": false,
"routed_ip_enabled": true,
"enable_ipv6": false,
"hostname": "cli-srv-eager-tereshkova",
"hostname": "cli-srv-funny-curran",
"image": {
"id": "63d40353-5519-46d0-9172-ccf4885954e1",
"id": "6d3c053e-c728-4294-b23a-560b62a4d592",
"name": "Ubuntu 22.04 Jammy Jellyfish",
"arch": "x86_64",
"creation_date": "1970-01-01T00:00:00.0Z",
Expand All @@ -72,7 +73,7 @@ Server.EndOfService false
"organization": "51b656e3-4865-41e8-adbc-0c45bdd780db",
"public": true,
"root_volume": {
"id": "905845fc-a6eb-4401-8e9d-5810071b7119",
"id": "36b4ce54-c67a-4f68-ab74-839515834352",
"name": "",
"size": 0,
"volume_type": "sbs_snapshot"
Expand All @@ -86,15 +87,15 @@ Server.EndOfService false
"private_ip": null,
"public_ip": null,
"public_ips": [],
"mac_address": "de:00:00:b5:91:c3",
"mac_address": "de:00:00:d0:04:a1",
"modification_date": "1970-01-01T00:00:00.0Z",
"state": "stopped",
"location": null,
"ipv6": null,
"boot_type": "local",
"volumes": {
"0": {
"id": "26f21c8e-6de6-443e-8d64-d039c9e2dfa6",
"id": "d98ba8fa-0e20-45df-99de-ed186191d104",
"name": null,
"export_uri": null,
"organization": null,
Expand All @@ -103,14 +104,14 @@ Server.EndOfService false
"volume_type": "sbs_volume",
"creation_date": null,
"modification_date": null,
"state": null,
"state": "available",
"project": null,
"boot": false,
"zone": "fr-par-1"
}
},
"security_group": {
"id": "1c1fc99f-b2de-408d-9eb0-da801a3e2744",
"id": "da505169-540e-4c2b-b0da-c854139224e0",
"name": "Default security group"
},
"maintenances": [],
Expand All @@ -123,7 +124,7 @@ Server.EndOfService false
"admin_password_encrypted_value": null,
"filesystems": [
{
"filesystem_id": "aab9e768-c1e9-407a-829c-4be5a38787dd",
"filesystem_id": "76ec2ddd-9383-4898-bf7d-d3cbf2daac0f",
"state": "available"
}
],
Expand Down
Loading
Loading