Skip to content

Commit 155e514

Browse files
authored
Merge branch 'master' into feat/datawarehouse_integration
2 parents 3a2603e + 67f6b70 commit 155e514

File tree

103 files changed

+200524
-263058
lines changed

Some content is hidden

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

103 files changed

+200524
-263058
lines changed

cmd/vcr-compressor/main.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package main
33
import (
44
"log"
55
"os"
6+
"strings"
67

78
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
89
)
@@ -13,8 +14,19 @@ func main() {
1314
}
1415

1516
path := os.Args[1]
17+
folder := strings.Split(path, "/")[2]
18+
19+
var (
20+
report acctest.CompressReport
21+
err error
22+
)
23+
24+
if acctest.FolderUsesVCRv4(folder) {
25+
report, err = acctest.CompressCassetteV4(path)
26+
} else {
27+
report, err = acctest.CompressCassetteV3(path)
28+
}
1629

17-
report, err := acctest.CompressCassette(path)
1830
if err != nil {
1931
log.Fatalf("%s", err)
2032
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ require (
1010
github.com/aws/aws-sdk-go-v2/service/s3 v1.88.1
1111
github.com/aws/aws-sdk-go-v2/service/sns v1.38.5
1212
github.com/aws/aws-sdk-go-v2/service/sqs v1.42.8
13-
github.com/aws/smithy-go v1.23.0
13+
github.com/aws/smithy-go v1.23.1
1414
github.com/docker/docker v28.4.0+incompatible
1515
github.com/dustin/go-humanize v1.0.1
1616
github.com/google/go-cmp v0.7.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -109,8 +109,8 @@ github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.1 h1:5fm5RTONng73/QA73LhCNR7U
109109
github.com/aws/aws-sdk-go-v2/service/ssooidc v1.35.1/go.mod h1:xBEjWD13h+6nq+z4AkqSfSvqRKFgDIQeaMguAJndOWo=
110110
github.com/aws/aws-sdk-go-v2/service/sts v1.38.6 h1:p3jIvqYwUZgu/XYeI48bJxOhvm47hZb5HUQ0tn6Q9kA=
111111
github.com/aws/aws-sdk-go-v2/service/sts v1.38.6/go.mod h1:WtKK+ppze5yKPkZ0XwqIVWD4beCwv056ZbPQNoeHqM8=
112-
github.com/aws/smithy-go v1.23.0 h1:8n6I3gXzWJB2DxBDnfxgBaSX6oe0d/t10qGz7OKqMCE=
113-
github.com/aws/smithy-go v1.23.0/go.mod h1:t1ufH5HMublsJYulve2RKmHDC15xu1f26kHCp/HgceI=
112+
github.com/aws/smithy-go v1.23.1 h1:sLvcH6dfAFwGkHLZ7dGiYF7aK6mg4CgKA/iDKjLDt9M=
113+
github.com/aws/smithy-go v1.23.1/go.mod h1:LEj2LM3rBRQJxPZTB4KuzZkaZYnZPnvgIhb4pu07mx0=
114114
github.com/bflad/gopaniccheck v0.1.0 h1:tJftp+bv42ouERmUMWLoUn/5bi/iQZjHPznM00cP/bU=
115115
github.com/bflad/gopaniccheck v0.1.0/go.mod h1:ZCj2vSr7EqVeDaqVsWN4n2MwdROx1YL+LFo47TSWtsA=
116116
github.com/bflad/tfproviderdocs v0.12.1 h1:MlHjrSa+pz1RxaCdvUWj+ZI5IwKMF7tjL4JTLg+dlTs=

internal/acctest/acctest.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,10 @@ type TestTools struct {
3535

3636
var foldersUsingVCRv4 = []string{
3737
"instance",
38+
"k8s",
3839
}
3940

40-
func folderUsesVCRv4(fullFolderPath string) bool {
41+
func FolderUsesVCRv4(fullFolderPath string) bool {
4142
fullPathSplit := strings.Split(fullFolderPath, "/")
4243

4344
folder := fullPathSplit[len(fullPathSplit)-1]
@@ -120,7 +121,7 @@ func NewTestTools(t *testing.T) *TestTools {
120121
cleanup func()
121122
)
122123

123-
if folderUsesVCRv4(folder) {
124+
if FolderUsesVCRv4(folder) {
124125
httpClient, cleanup, err = NewRecordedClient(t, folder, *UpdateCassettes)
125126
} else {
126127
httpClient, cleanup, err = getHTTPRecoder(t, folder, *UpdateCassettes)

internal/acctest/compress_cassettes_test.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package acctest_test
22

33
import (
4+
"strings"
45
"testing"
56

67
"github.com/scaleway/terraform-provider-scaleway/v2/internal/acctest"
@@ -16,7 +17,18 @@ func TestAccCassettes_Compressed(t *testing.T) {
1617

1718
for path := range paths {
1819
g.Go(func() error {
19-
report, errCompression := acctest.CompressCassette(path)
20+
var (
21+
report acctest.CompressReport
22+
errCompression error
23+
)
24+
25+
folder := strings.Split(path, "/")[2]
26+
if acctest.FolderUsesVCRv4(folder) {
27+
report, errCompression = acctest.CompressCassetteV4(path)
28+
} else {
29+
report, errCompression = acctest.CompressCassetteV3(path)
30+
}
31+
2032
require.NoError(t, errCompression)
2133
require.Zero(t, report.SkippedInteraction, "Issue with cassette: %s", report.Path)
2234

internal/acctest/vcr_compress.go

Lines changed: 93 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,8 @@ import (
1818
"github.com/scaleway/scaleway-sdk-go/api/rdb/v1"
1919
"github.com/scaleway/scaleway-sdk-go/api/redis/v1"
2020
tem "github.com/scaleway/scaleway-sdk-go/api/tem/v1alpha1"
21-
"gopkg.in/dnaeon/go-vcr.v3/cassette"
21+
cassetteV3 "gopkg.in/dnaeon/go-vcr.v3/cassette"
22+
cassetteV4 "gopkg.in/dnaeon/go-vcr.v4/pkg/cassette"
2223
)
2324

2425
var transientStates = map[string]bool{
@@ -113,13 +114,101 @@ func (report *CompressReport) Print() {
113114
}
114115
}
115116

116-
func CompressCassette(path string) (CompressReport, error) {
117-
inputCassette, err := cassette.Load(path)
117+
func CompressCassetteV3(path string) (CompressReport, error) {
118+
inputCassette, err := cassetteV3.Load(path)
118119
if err != nil {
119120
log.Fatalf("Error while reading file : %v\n", err)
120121
}
121122

122-
outputCassette := cassette.New(path)
123+
outputCassette := cassetteV3.New(path)
124+
transitioning := false
125+
126+
report := CompressReport{
127+
SkippedInteraction: 0,
128+
Path: path,
129+
ErrorLogs: []string{},
130+
Logs: []string{},
131+
}
132+
133+
for i := range len(inputCassette.Interactions) {
134+
interaction := inputCassette.Interactions[i]
135+
responseBody := interaction.Response.Body
136+
requestMethod := interaction.Request.Method
137+
138+
if requestMethod != "GET" {
139+
transitioning = false
140+
141+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not a GET request. Recording it\n", i, path))
142+
outputCassette.AddInteraction(interaction)
143+
144+
continue
145+
}
146+
147+
if responseBody == "" {
148+
report.AddLog(fmt.Sprintf("Interaction %d in test %s got an empty response body. Recording it\n", i, path))
149+
outputCassette.AddInteraction(interaction)
150+
151+
continue
152+
}
153+
154+
var m map[string]any
155+
156+
err := json.Unmarshal([]byte(responseBody), &m)
157+
if err != nil {
158+
report.AddErrorLog(fmt.Sprintf("Interaction %d in test %s have an error with unmarshalling response body: %v. Recording it\n", i, path, err))
159+
outputCassette.AddInteraction(interaction)
160+
161+
continue
162+
}
163+
164+
if m["status"] == nil {
165+
report.AddLog(fmt.Sprintf("Interaction %d in test %s does not contain a status field. Recording it\n", i, path))
166+
outputCassette.AddInteraction(interaction)
167+
168+
continue
169+
}
170+
171+
status := m["status"].(string)
172+
// We test if the state is transient
173+
if _, ok := transientStates[status]; ok {
174+
if transitioning {
175+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is in a transient state while we are already in transitient state. No need to record it: %s\n", i, path, status))
176+
report.SkippedInteraction++
177+
} else {
178+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is in a transient state: %s, Recording it\n", i, path, status))
179+
180+
transitioning = true
181+
182+
outputCassette.AddInteraction(interaction)
183+
}
184+
} else {
185+
if transitioning {
186+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not in a transient state anymore: %s, Recording it\n", i, path, status))
187+
outputCassette.AddInteraction(interaction)
188+
189+
transitioning = false
190+
} else {
191+
report.AddLog(fmt.Sprintf("Interaction %d in test %s is not in a transient state: %s, Recording it\n", i, path, status))
192+
outputCassette.AddInteraction(interaction)
193+
}
194+
}
195+
}
196+
197+
err = outputCassette.Save()
198+
if err != nil {
199+
return report, fmt.Errorf("error while saving file: %w", err)
200+
}
201+
202+
return report, nil
203+
}
204+
205+
func CompressCassetteV4(path string) (CompressReport, error) {
206+
inputCassette, err := cassetteV4.Load(path)
207+
if err != nil {
208+
log.Fatalf("Error while reading file : %v\n", err)
209+
}
210+
211+
outputCassette := cassetteV4.New(path)
123212
transitioning := false
124213

125214
report := CompressReport{

0 commit comments

Comments
 (0)