Skip to content

Commit d231482

Browse files
authored
feat(vcr): move vcr and matching funcs to the sdk (scaleway#2700)
1 parent 31b2cb2 commit d231482

File tree

51 files changed

+8387
-9214
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

51 files changed

+8387
-9214
lines changed

api/container/v1beta1/container_sdk_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99
)
1010

1111
func TestListContainerNamespaceMultipleRegions(t *testing.T) {
12-
client, r, err := httprecorder.CreateRecordedScwClient("container-list-regions")
12+
client, r, err := httprecorder.CreateRecordedScwClient(t)
1313
testhelpers.AssertNoError(t, err)
1414
defer func() {
1515
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it

api/container/v1beta1/testdata/container-list-regions.yaml

Lines changed: 0 additions & 99 deletions
This file was deleted.
Lines changed: 108 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,108 @@
1+
---
2+
version: 2
3+
interactions:
4+
- id: 0
5+
request:
6+
proto: HTTP/1.1
7+
proto_major: 1
8+
proto_minor: 1
9+
content_length: 0
10+
host: api.scaleway.com
11+
form:
12+
order_by:
13+
- created_at_asc
14+
headers:
15+
User-Agent:
16+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.1; linux; amd64)
17+
url: https://api.scaleway.com/containers/v1beta1/regions/nl-ams/namespaces?order_by=created_at_asc
18+
method: GET
19+
response:
20+
proto: HTTP/2.0
21+
proto_major: 2
22+
proto_minor: 0
23+
content_length: 33
24+
body: "{\"namespaces\":[],\"total_count\":0}"
25+
headers:
26+
Content-Length:
27+
- "33"
28+
Content-Type:
29+
- application/json
30+
Date:
31+
- Fri, 05 Sep 2025 16:20:23 GMT
32+
Server:
33+
- Scaleway API Gateway (fr-par-1;edge03)
34+
X-Request-Id:
35+
- 4cbdc71b-714d-4aa1-a0ec-8cfe7f2e66af
36+
status: 200 OK
37+
code: 200
38+
duration: 325.71151ms
39+
- id: 1
40+
request:
41+
proto: HTTP/1.1
42+
proto_major: 1
43+
proto_minor: 1
44+
content_length: 0
45+
host: api.scaleway.com
46+
form:
47+
order_by:
48+
- created_at_asc
49+
headers:
50+
User-Agent:
51+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.1; linux; amd64)
52+
url: https://api.scaleway.com/containers/v1beta1/regions/fr-par/namespaces?order_by=created_at_asc
53+
method: GET
54+
response:
55+
proto: HTTP/2.0
56+
proto_major: 2
57+
proto_minor: 0
58+
content_length: 33
59+
body: "{\"namespaces\":[],\"total_count\":0}"
60+
headers:
61+
Content-Length:
62+
- "33"
63+
Content-Type:
64+
- application/json
65+
Date:
66+
- Fri, 05 Sep 2025 16:20:23 GMT
67+
Server:
68+
- Scaleway API Gateway (fr-par-1;edge03)
69+
X-Request-Id:
70+
- 887587fa-31ab-4a9b-bebe-258add796006
71+
status: 200 OK
72+
code: 200
73+
duration: 386.125699ms
74+
- id: 2
75+
request:
76+
proto: HTTP/1.1
77+
proto_major: 1
78+
proto_minor: 1
79+
content_length: 0
80+
host: api.scaleway.com
81+
form:
82+
order_by:
83+
- created_at_asc
84+
headers:
85+
User-Agent:
86+
- scaleway-sdk-go/v1.0.0-beta.7+dev (go1.24.1; linux; amd64)
87+
url: https://api.scaleway.com/containers/v1beta1/regions/pl-waw/namespaces?order_by=created_at_asc
88+
method: GET
89+
response:
90+
proto: HTTP/2.0
91+
proto_major: 2
92+
proto_minor: 0
93+
content_length: 33
94+
body: "{\"namespaces\":[],\"total_count\":0}"
95+
headers:
96+
Content-Length:
97+
- "33"
98+
Content-Type:
99+
- application/json
100+
Date:
101+
- Fri, 05 Sep 2025 16:20:23 GMT
102+
Server:
103+
- Scaleway API Gateway (fr-par-1;edge03)
104+
X-Request-Id:
105+
- 6961a505-c5d5-4b13-931f-5bb27f40125f
106+
status: 200 OK
107+
code: 200
108+
duration: 435.682722ms

api/instance/v1/image_utils_test.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
)
1111

1212
func TestWaitForImage(t *testing.T) {
13-
client, r, err := httprecorder.CreateRecordedScwClient("image-wait-test")
13+
client, r, err := httprecorder.CreateRecordedScwClient(t)
1414
testhelpers.AssertNoError(t, err)
1515
defer func() {
1616
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it

api/instance/v1/instance_sdk_server_test.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@ package instance
33
import (
44
"testing"
55

6-
"github.com/dnaeon/go-vcr/recorder"
76
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers"
87
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers/httprecorder"
98
"github.com/scaleway/scaleway-sdk-go/scw"
9+
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
1010
)
1111

1212
func TestServerUpdate(t *testing.T) {
13-
client, r, err := httprecorder.CreateRecordedScwClient("server-test")
13+
client, r, err := httprecorder.CreateRecordedScwClient(t)
1414
testhelpers.AssertNoError(t, err)
1515
defer func() {
1616
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it
1717
}()
1818

1919
project, ok := client.GetDefaultProjectID()
20-
if !ok && r.Mode() == recorder.ModeRecording {
20+
if !ok && r.Mode() == recorder.ModeRecordOnly {
2121
t.Fatal("default project ID is required to record this test")
2222
}
2323
instanceAPI := NewAPI(client)
@@ -61,7 +61,7 @@ func TestServerUpdate(t *testing.T) {
6161
testhelpers.Equals(t, commercialType, createServerResponse.Server.CommercialType)
6262
testhelpers.Equals(t, tags, createServerResponse.Server.Tags)
6363
testhelpers.Equals(t, *dynamicIPRequired, createServerResponse.Server.DynamicIPRequired)
64-
if r.Mode() == recorder.ModeRecording {
64+
if r.Mode() == recorder.ModeRecordOnly {
6565
testhelpers.Equals(t, project, createServerResponse.Server.Project)
6666
}
6767
})
@@ -90,7 +90,7 @@ func TestServerUpdate(t *testing.T) {
9090
testhelpers.Assert(t, len(updateServerResponse.Server.Volumes) == 1, "should have exactly one volume because we didn't pass volumes map in the requests.")
9191
testhelpers.Equals(t, newName, updateServerResponse.Server.Name)
9292
testhelpers.Equals(t, updatedTags, updateServerResponse.Server.Tags)
93-
if r.Mode() == recorder.ModeRecording {
93+
if r.Mode() == recorder.ModeRecordOnly {
9494
testhelpers.Equals(t, project, updateServerResponse.Server.Project)
9595
}
9696
})
@@ -125,7 +125,7 @@ func TestServerUpdate(t *testing.T) {
125125
}
126126

127127
func TestCreateServerWithIncorrectBody(t *testing.T) {
128-
client, r, err := httprecorder.CreateRecordedScwClient("server-incorrect-body")
128+
client, r, err := httprecorder.CreateRecordedScwClient(t)
129129
testhelpers.AssertNoError(t, err)
130130
defer func() {
131131
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it
@@ -143,7 +143,7 @@ func TestCreateServerWithIncorrectBody(t *testing.T) {
143143
}
144144

145145
func TestListServerMultipleZones(t *testing.T) {
146-
client, r, err := httprecorder.CreateRecordedScwClient("server-list-zones")
146+
client, r, err := httprecorder.CreateRecordedScwClient(t)
147147
testhelpers.AssertNoError(t, err)
148148
defer func() {
149149
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it

api/instance/v1/instance_utils_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,22 @@ package instance
33
import (
44
"testing"
55

6-
"github.com/dnaeon/go-vcr/recorder"
76
block "github.com/scaleway/scaleway-sdk-go/api/block/v1alpha1"
87
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers"
98
"github.com/scaleway/scaleway-sdk-go/internal/testhelpers/httprecorder"
109
"github.com/scaleway/scaleway-sdk-go/scw"
10+
"gopkg.in/dnaeon/go-vcr.v4/pkg/recorder"
1111
)
1212

1313
func TestInstanceHelpers(t *testing.T) {
14-
client, r, err := httprecorder.CreateRecordedScwClient("utils-test")
14+
client, r, err := httprecorder.CreateRecordedScwClient(t)
1515
testhelpers.AssertNoError(t, err)
1616
defer func() {
1717
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it
1818
}()
1919

2020
project, ok := client.GetDefaultProjectID()
21-
if !ok && r.Mode() == recorder.ModeRecording {
21+
if !ok && r.Mode() == recorder.ModeRecordOnly {
2222
t.Fatal("default project ID is required to record this test")
2323
}
2424
instanceAPI := NewAPI(client)
@@ -124,14 +124,14 @@ func TestInstanceHelpers(t *testing.T) {
124124
}
125125

126126
func TestInstanceHelpers_BlockVolume(t *testing.T) {
127-
client, r, err := httprecorder.CreateRecordedScwClient("utils-test-block")
127+
client, r, err := httprecorder.CreateRecordedScwClient(t)
128128
testhelpers.AssertNoError(t, err)
129129
defer func() {
130130
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it
131131
}()
132132

133133
project, ok := client.GetDefaultProjectID()
134-
if !ok && r.Mode() == recorder.ModeRecording {
134+
if !ok && r.Mode() == recorder.ModeRecordOnly {
135135
t.Fatal("default project ID is required to record this test")
136136
}
137137
instanceAPI := NewAPI(client)

api/instance/v1/security_group_utils_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
)
1313

1414
func TestAPI_UpdateSecurityGroup(t *testing.T) {
15-
client, r, err := httprecorder.CreateRecordedScwClient("security-group-test")
15+
client, r, err := httprecorder.CreateRecordedScwClient(t)
1616
testhelpers.AssertNoError(t, err)
1717
defer func() {
1818
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it
@@ -66,7 +66,7 @@ func TestAPI_UpdateSecurityGroup(t *testing.T) {
6666
}
6767

6868
func TestAPI_UpdateSecurityGroupRule(t *testing.T) {
69-
client, r, err := httprecorder.CreateRecordedScwClient("security-group-rule-test")
69+
client, r, err := httprecorder.CreateRecordedScwClient(t)
7070
testhelpers.AssertNoError(t, err)
7171
defer func() {
7272
testhelpers.AssertNoError(t, r.Stop()) // Make sure recorder is stopped once done with it

0 commit comments

Comments
 (0)