Skip to content

Commit 3d8a4b8

Browse files
authored
chore: add support for wsl (#2917)
* chore: add support for wsl * Fix
1 parent ae13910 commit 3d8a4b8

File tree

319 files changed

+1359
-9
lines changed

Some content is hidden

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

319 files changed

+1359
-9
lines changed

.golangci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ linters:
7979
- usetesting # Reports uses of functions with replacement inside the testing package. [auto-fix]
8080
- wastedassign # wastedassign finds wasted assignment statements. [fast: false, auto-fix: false]
8181
- whitespace # Tool for detection of leading and trailing whitespace [fast: true, auto-fix: true]
82+
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]
8283
- zerologlint # Detects the wrong usage of `zerolog` that a user forgets to dispatch with `Send` or `Msg` [fast: false, auto-fix: false]
8384

8485
disable:
@@ -101,7 +102,6 @@ linters:
101102
- nestif # Reports deeply nested if statements [fast: true, auto-fix: false]
102103
- nilnil # Checks that there is no simultaneous return of `nil` error and an invalid value. [fast: false, auto-fix: false]
103104
- varnamelen # checks that the length of a variable's name matches its scope [fast: false, auto-fix: false]
104-
- wsl # Whitespace Linter - Forces you to use empty lines! [fast: true, auto-fix: false]
105105

106106
linters-settings:
107107
goconst:

internal/acctest/acctest.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ type TestTools struct {
2626

2727
func NewTestTools(t *testing.T) *TestTools {
2828
t.Helper()
29+
2930
ctx := context.Background()
3031

3132
folder, err := os.Getwd()
@@ -142,6 +143,7 @@ func compareJSONBodies(expected, actual map[string]interface{}) bool {
142143
// We do not want to generate new cassettes for each new features
143144
continue
144145
}
146+
145147
if !compareJSONFields(expectedValue, actual[key]) {
146148
return false
147149
}

internal/acctest/checks.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,16 @@ func CheckResourceIDChanged(resourceName string, resourceID *string) resource.Te
1818
if resourceID == nil || *resourceID == "" {
1919
return errors.New("resourceID was not set")
2020
}
21+
2122
rs, ok := s.RootModule().Resources[resourceName]
2223
if !ok {
2324
return fmt.Errorf("resource was not found: %s", resourceName)
2425
}
26+
2527
if *resourceID == rs.Primary.ID {
2628
return errors.New("resource ID persisted when it should have changed")
2729
}
30+
2831
*resourceID = rs.Primary.ID
2932

3033
return nil
@@ -39,9 +42,11 @@ func CheckResourceIDPersisted(resourceName string, resourceID *string) resource.
3942
if !ok {
4043
return fmt.Errorf("resource was not found: %s", resourceName)
4144
}
45+
4246
if *resourceID != "" && *resourceID != rs.Primary.ID {
4347
return errors.New("resource ID changed when it should have persisted")
4448
}
49+
4550
*resourceID = rs.Primary.ID
4651

4752
return nil
@@ -84,10 +89,12 @@ func CheckResourceAttrFunc(name string, key string, test func(string) error) res
8489
if !ok {
8590
return fmt.Errorf("resource not found: %s", name)
8691
}
92+
8793
value, ok := rs.Primary.Attributes[key]
8894
if !ok {
8995
return fmt.Errorf("key not found: %s", key)
9096
}
97+
9198
err := test(value)
9299
if err != nil {
93100
return fmt.Errorf("test for %s %s did not pass test: %s", name, key, err)

internal/acctest/domain.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func init() {
3333

3434
// check if the test domain is not a Scaleway reserved domain
3535
isReserved := false
36+
3637
for _, reservedDomain := range reservedDomains {
3738
if reservedDomain.MatchString(TestDomain) {
3839
isReserved = true

internal/acctest/fixtures.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ func CreateFakeIAMManager(tt *TestTools) (*account.Project, *iam.APIKey, FakeSid
6464
iamPolicyName := sdkacctest.RandomWithPrefix("test-acc-scaleway-iam-policy")
6565

6666
projectAPI := account.NewProjectAPI(tt.Meta.ScwClient())
67+
6768
project, err := projectAPI.CreateProject(&account.ProjectAPICreateProjectRequest{
6869
Name: projectName,
6970
})
@@ -74,13 +75,15 @@ func CreateFakeIAMManager(tt *TestTools) (*account.Project, *iam.APIKey, FakeSid
7475

7576
return nil, nil, nil, err
7677
}
78+
7779
terminateFunctions = append(terminateFunctions, func() error {
7880
return projectAPI.DeleteProject(&account.ProjectAPIDeleteProjectRequest{
7981
ProjectID: project.ID,
8082
})
8183
})
8284

8385
iamAPI := iam.NewAPI(tt.Meta.ScwClient())
86+
8487
iamApplication, err := iamAPI.CreateApplication(&iam.CreateApplicationRequest{
8588
Name: iamApplicationName,
8689
})
@@ -91,6 +94,7 @@ func CreateFakeIAMManager(tt *TestTools) (*account.Project, *iam.APIKey, FakeSid
9194

9295
return nil, nil, nil, err
9396
}
97+
9498
terminateFunctions = append(terminateFunctions, func() error {
9599
return iamAPI.DeleteApplication(&iam.DeleteApplicationRequest{
96100
ApplicationID: iamApplication.ID,
@@ -114,6 +118,7 @@ func CreateFakeIAMManager(tt *TestTools) (*account.Project, *iam.APIKey, FakeSid
114118

115119
return nil, nil, nil, err
116120
}
121+
117122
terminateFunctions = append(terminateFunctions, func() error {
118123
return iamAPI.DeletePolicy(&iam.DeletePolicyRequest{
119124
PolicyID: iamPolicy.ID,
@@ -131,6 +136,7 @@ func CreateFakeIAMManager(tt *TestTools) (*account.Project, *iam.APIKey, FakeSid
131136

132137
return nil, nil, nil, err
133138
}
139+
134140
terminateFunctions = append(terminateFunctions, func() error {
135141
return iamAPI.DeleteAPIKey(&iam.DeleteAPIKeyRequest{
136142
AccessKey: iamAPIKey.AccessKey,
@@ -163,6 +169,7 @@ func CreateFakeSideProject(tt *TestTools) (*account.Project, *iam.APIKey, FakeSi
163169
iamPolicyName := sdkacctest.RandomWithPrefix("test-acc-scaleway-iam-policy")
164170

165171
projectAPI := account.NewProjectAPI(tt.Meta.ScwClient())
172+
166173
project, err := projectAPI.CreateProject(&account.ProjectAPICreateProjectRequest{
167174
Name: projectName,
168175
})
@@ -173,13 +180,15 @@ func CreateFakeSideProject(tt *TestTools) (*account.Project, *iam.APIKey, FakeSi
173180

174181
return nil, nil, nil, err
175182
}
183+
176184
terminateFunctions = append(terminateFunctions, func() error {
177185
return projectAPI.DeleteProject(&account.ProjectAPIDeleteProjectRequest{
178186
ProjectID: project.ID,
179187
})
180188
})
181189

182190
iamAPI := iam.NewAPI(tt.Meta.ScwClient())
191+
183192
iamApplication, err := iamAPI.CreateApplication(&iam.CreateApplicationRequest{
184193
Name: iamApplicationName,
185194
})
@@ -190,6 +199,7 @@ func CreateFakeSideProject(tt *TestTools) (*account.Project, *iam.APIKey, FakeSi
190199

191200
return nil, nil, nil, err
192201
}
202+
193203
terminateFunctions = append(terminateFunctions, func() error {
194204
return iamAPI.DeleteApplication(&iam.DeleteApplicationRequest{
195205
ApplicationID: iamApplication.ID,
@@ -213,6 +223,7 @@ func CreateFakeSideProject(tt *TestTools) (*account.Project, *iam.APIKey, FakeSi
213223

214224
return nil, nil, nil, err
215225
}
226+
216227
terminateFunctions = append(terminateFunctions, func() error {
217228
return iamAPI.DeletePolicy(&iam.DeletePolicyRequest{
218229
PolicyID: iamPolicy.ID,
@@ -230,6 +241,7 @@ func CreateFakeSideProject(tt *TestTools) (*account.Project, *iam.APIKey, FakeSi
230241

231242
return nil, nil, nil, err
232243
}
244+
233245
terminateFunctions = append(terminateFunctions, func() error {
234246
return iamAPI.DeleteAPIKey(&iam.DeleteAPIKeyRequest{
235247
AccessKey: iamAPIKey.AccessKey,

internal/acctest/sweepers.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
func Sweep(f func(scwClient *scw.Client) error) error {
1212
ctx := context.Background()
13+
1314
m, err := meta.NewMeta(ctx, &meta.Config{
1415
TerraformVersion: "terraform-tests",
1516
})
@@ -26,6 +27,7 @@ func SweepZones(zones []scw.Zone, f func(scwClient *scw.Client, zone scw.Zone) e
2627
if err != nil {
2728
return err
2829
}
30+
2931
err = f(client, zone)
3032
if err != nil {
3133
logging.L.Warningf("error running sweepZones, ignoring: %s", err)
@@ -52,6 +54,7 @@ func SweepRegions(regions []scw.Region, f func(scwClient *scw.Client, region scw
5254
// functions for a given zone
5355
func sharedClientForZone(zone scw.Zone) (*scw.Client, error) {
5456
ctx := context.Background()
57+
5558
m, err := meta.NewMeta(ctx, &meta.Config{
5659
TerraformVersion: "terraform-tests",
5760
ForceZone: zone,

internal/acctest/validate_cassettes_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,11 @@ func exceptionsCassettesCases() map[string]struct{} {
3434
func getTestFiles() (map[string]struct{}, error) {
3535
filesMap := make(map[string]struct{})
3636
exceptions := exceptionsCassettesCases()
37+
3738
err := filepath.WalkDir("../services", func(path string, _ fs.DirEntry, _ error) error {
3839
isCassette := strings.Contains(path, "cassette")
3940
_, isException := exceptions[path]
41+
4042
if isCassette && !isException {
4143
filesMap[fileNameWithoutExtSuffix(path)] = struct{}{}
4244
}
@@ -74,6 +76,7 @@ func checkErrorCode(c *cassette.Cassette) error {
7476

7577
func checkErrCodeExcept(i *cassette.Interaction, c *cassette.Cassette, codes ...int) bool {
7678
exceptions := exceptionsCassettesCases()
79+
7780
_, isException := exceptions[c.File]
7881
if isException {
7982
return isException
@@ -82,6 +85,7 @@ func checkErrCodeExcept(i *cassette.Interaction, c *cassette.Cassette, codes ...
8285
if strings.Contains(i.Response.Body, mnq.AWSErrNonExistentQueue) && i.Response.Code == 400 {
8386
return true
8487
}
88+
8589
if i.Response.Code >= 400 {
8690
for _, httpCode := range codes {
8791
if i.Response.Code == httpCode {

internal/acctest/vcr.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ var BodyMatcherIgnore = []string{
4848
// getTestFilePath returns a valid filename path based on the go test name and suffix. (Take care of non fs friendly char)
4949
func getTestFilePath(t *testing.T, pkgFolder string, suffix string) string {
5050
t.Helper()
51+
5152
specialChars := regexp.MustCompile(`[\\?%*:|"<>. ]`)
5253

5354
// Replace nested tests separators.
@@ -91,6 +92,7 @@ func compareFormBodies(expected, actual url.Values) bool {
9192
// We do not want to generate new cassettes for each new features
9293
continue
9394
}
95+
9496
if !compareJSONFields(expectedValue, actual[key]) {
9597
return false
9698
}
@@ -125,6 +127,7 @@ func cassetteBodyMatcher(actualRequest *http.Request, cassetteRequest cassette.R
125127
if err != nil {
126128
panic(fmt.Errorf("cassette body matcher: failed to copy actualRequest body: %w", err)) // lintignore: R009
127129
}
130+
128131
actualRawBody, err := io.ReadAll(actualBody)
129132
if err != nil {
130133
panic(fmt.Errorf("cassette body matcher: failed to read actualRequest body: %w", err)) // lintignore: R009
@@ -186,10 +189,12 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
186189
actualURL := actual.URL
187190
actualURLValues := actualURL.Query()
188191
expectedURLValues := expectedURL.Query()
192+
189193
for _, query := range QueryMatcherIgnore {
190194
actualURLValues.Del(query)
191195
expectedURLValues.Del(query)
192196
}
197+
193198
actualURL.RawQuery = actualURLValues.Encode()
194199
expectedURL.RawQuery = expectedURLValues.Encode()
195200

@@ -199,6 +204,7 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
199204
if !strings.HasSuffix(expectedURL.Host, "scw.cloud") {
200205
return false
201206
}
207+
202208
actualS3Host := strings.Split(actualURL.Host, ".")
203209
expectedS3Host := strings.Split(expectedURL.Host, ".")
204210

@@ -212,6 +218,7 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
212218
if strings.Contains(actualBucket, "-") {
213219
actualBucket = actualBucket[:strings.LastIndex(actualBucket, "-")]
214220
}
221+
215222
if strings.Contains(expectedBucket, "-") {
216223
expectedBucket = expectedBucket[:strings.LastIndex(expectedBucket, "-")]
217224
}
@@ -230,20 +237,24 @@ func cassetteMatcher(actual *http.Request, expected cassette.Request) bool {
230237

231238
func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error {
232239
var jsonBody map[string]interface{}
240+
233241
err := json.Unmarshal([]byte(i.Response.Body), &jsonBody)
234242
if err != nil {
235243
//nolint:nilerr
236244
return nil
237245
}
246+
238247
for key, value := range SensitiveFields {
239248
if _, ok := jsonBody[key]; ok {
240249
jsonBody[key] = value
241250
}
242251
}
252+
243253
anonymizedBody, err := json.Marshal(jsonBody)
244254
if err != nil {
245255
return fmt.Errorf("failed to marshal anonymized body: %w", err)
246256
}
257+
247258
i.Response.Body = string(anonymizedBody)
248259

249260
return nil
@@ -257,6 +268,7 @@ func cassetteSensitiveFieldsAnonymizer(i *cassette.Interaction) error {
257268
// closed and saved after the requests.
258269
func getHTTPRecoder(t *testing.T, pkgFolder string, update bool) (client *http.Client, cleanup func(), err error) {
259270
t.Helper()
271+
260272
recorderMode := recorder.ModeReplayOnly
261273
if update {
262274
recorderMode = recorder.ModeRecordOnly

internal/datasource/schemas.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ func NewRegionalID(idI interface{}, fallBackRegion scw.Region) string {
3838
// source: https://github.com/hashicorp/terraform-provider-google/blob/main/google/tpgresource/datasource_helpers.go
3939
func SchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.Schema {
4040
ds := make(map[string]*schema.Schema, len(rs))
41+
4142
for k, v := range rs {
4243
dv := &schema.Schema{
4344
Computed: true,
@@ -69,6 +70,7 @@ func SchemaFromResourceSchema(rs map[string]*schema.Schema) map[string]*schema.S
6970
// Elem of all other types are copied as-is
7071
dv.Elem = v.Elem
7172
}
73+
7274
ds[k] = dv
7375
}
7476

internal/datasource/search.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
// It returns the first matching element and an error if either no match is found or multiple matches are found.
1212
func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, error) { //nolint:ireturn
1313
var found T
14+
1415
var foundFlag bool
1516

1617
for _, elem := range slice {
@@ -21,6 +22,7 @@ func FindExact[T any](slice []T, finder func(T) bool, searchName string) (T, err
2122

2223
return zero, fmt.Errorf("multiple elements found with the name %s", searchName)
2324
}
25+
2426
found = elem
2527
foundFlag = true
2628
}

internal/dsf/list.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ func GetStringListsFromState(key string, d *schema.ResourceData) ([]string, []st
3535
for i, v := range oldList.([]interface{}) {
3636
oldListStr[i] = fmt.Sprint(v)
3737
}
38+
3839
for i, v := range newList.([]interface{}) {
3940
newListStr[i] = fmt.Sprint(v)
4041
}

internal/dsf/time.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,10 @@ func Duration(_, oldValue, newValue string, _ *schema.ResourceData) bool {
1010
if oldValue == newValue {
1111
return true
1212
}
13+
1314
d1, err1 := time.ParseDuration(oldValue)
1415
d2, err2 := time.ParseDuration(newValue)
16+
1517
if err1 != nil || err2 != nil {
1618
return false
1719
}
@@ -23,8 +25,10 @@ func TimeRFC3339(_, oldValue, newValue string, _ *schema.ResourceData) bool {
2325
if oldValue == newValue {
2426
return true
2527
}
28+
2629
t1, err1 := time.Parse(time.RFC3339, oldValue)
2730
t2, err2 := time.Parse(time.RFC3339, newValue)
31+
2832
if err1 != nil || err2 != nil {
2933
return false
3034
}

internal/locality/ids.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@ func ExpandID(id interface{}) string {
1212

1313
func ExpandIDs(data interface{}) []string {
1414
expandedIDs := make([]string, 0, len(data.([]interface{})))
15+
1516
for _, s := range data.([]interface{}) {
1617
if s == nil {
1718
s = ""
1819
}
20+
1921
expandedID := ExpandID(s.(string))
2022
expandedIDs = append(expandedIDs, expandedID)
2123
}

0 commit comments

Comments
 (0)