Skip to content

Commit e7650fa

Browse files
authored
Replace tenv and exportloopref linters with usetesting and copyloopvar (#232)
1 parent 157a416 commit e7650fa

40 files changed

+183
-208
lines changed

.golangci.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
issues:
2-
max-per-linter: 0
2+
max-issues-per-linter: 0
33
max-same-issues: 0
44

55
linters:
66
disable-all: true
77
enable:
8+
- copyloopvar
89
- durationcheck
910
- errcheck
10-
- exportloopref
1111
- forcetypeassert
1212
- gofmt
1313
- gosimple
@@ -19,10 +19,10 @@ linters:
1919
- paralleltest
2020
- predeclared
2121
- staticcheck
22-
- tenv
2322
- unconvert
2423
- unparam
2524
- unused
25+
- usetesting
2626

2727
run:
2828
# Prevent false positive timeouts in CI

go.mod

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
module github.com/hashicorp/terraform-plugin-codegen-openapi
22

3-
go 1.22.7
4-
toolchain go1.23.1
3+
go 1.23.0
4+
5+
toolchain go1.24.0
56

67
require (
78
github.com/google/go-cmp v0.6.0

internal/cmd/generate_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010

1111
"github.com/google/go-cmp/cmp"
1212
"github.com/hashicorp/cli"
13+
1314
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/cmd"
1415
)
1516

@@ -48,7 +49,7 @@ func TestGenerate_WithConfig(t *testing.T) {
4849
},
4950
}
5051
for name, testCase := range testCases {
51-
name, testCase := name, testCase
52+
5253
t.Run(name, func(t *testing.T) {
5354
t.Parallel()
5455

internal/config/parse_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,7 +186,7 @@ data_sources:
186186
},
187187
}
188188
for name, testCase := range testCases {
189-
name, testCase := name, testCase
189+
190190
t.Run(name, func(t *testing.T) {
191191
t.Parallel()
192192

@@ -448,7 +448,7 @@ data_sources:
448448
},
449449
}
450450
for name, testCase := range testCases {
451-
name, testCase := name, testCase
451+
452452
errRegex := regexp.MustCompile(testCase.expectedErrRegex)
453453

454454
t.Run(name, func(t *testing.T) {

internal/explorer/config_explorer_test.go

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,10 @@ import (
88
"fmt"
99
"testing"
1010

11+
"gopkg.in/yaml.v3"
12+
1113
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/config"
1214
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
13-
"gopkg.in/yaml.v3"
1415

1516
"github.com/google/go-cmp/cmp"
1617
"github.com/google/go-cmp/cmp/cmpopts"
@@ -321,13 +322,12 @@ func Test_ConfigExplorer_FindResources(t *testing.T) {
321322
}
322323

323324
for name, testCase := range testCases {
324-
name, testCase := name, testCase
325325

326326
t.Run(name, func(t *testing.T) {
327327
t.Parallel()
328328

329-
explorer := explorer.NewConfigExplorer(high.Document{Paths: &high.Paths{PathItems: testCase.pathItems}}, testCase.config)
330-
got, err := explorer.FindResources()
329+
configExplorer := explorer.NewConfigExplorer(high.Document{Paths: &high.Paths{PathItems: testCase.pathItems}}, testCase.config)
330+
got, err := configExplorer.FindResources()
331331

332332
if testCase.expectedErr != nil {
333333
if err == nil {
@@ -515,13 +515,12 @@ func Test_ConfigExplorer_FindDataSources(t *testing.T) {
515515
}
516516

517517
for name, testCase := range testCases {
518-
name, testCase := name, testCase
519518

520519
t.Run(name, func(t *testing.T) {
521520
t.Parallel()
522521

523-
explorer := explorer.NewConfigExplorer(high.Document{Paths: &high.Paths{PathItems: testCase.pathItems}}, testCase.config)
524-
got, err := explorer.FindDataSources()
522+
configExplorer := explorer.NewConfigExplorer(high.Document{Paths: &high.Paths{PathItems: testCase.pathItems}}, testCase.config)
523+
got, err := configExplorer.FindDataSources()
525524

526525
if testCase.expectedErr != nil {
527526
if err == nil {
@@ -576,7 +575,6 @@ func Test_ConfigExplorer_FindProvider(t *testing.T) {
576575
}
577576

578577
for name, testCase := range testCases {
579-
name, testCase := name, testCase
580578

581579
t.Run(name, func(t *testing.T) {
582580
t.Parallel()
@@ -586,8 +584,8 @@ func Test_ConfigExplorer_FindProvider(t *testing.T) {
586584
t.Fatal(err)
587585
}
588586

589-
explorer := explorer.NewConfigExplorer(oasModel, testCase.config)
590-
got, err := explorer.FindProvider()
587+
configExplorer := explorer.NewConfigExplorer(oasModel, testCase.config)
588+
got, err := configExplorer.FindProvider()
591589

592590
if err != nil {
593591
t.Fatalf("was not expecting error, got: %s", err)

internal/explorer/explorer_utils_test.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,11 @@ import (
88
"testing"
99

1010
"github.com/google/go-cmp/cmp"
11-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util"
11+
"github.com/google/go-cmp/cmp/cmpopts"
1212
"github.com/pb33f/libopenapi/datamodel/high/base"
1313
high "github.com/pb33f/libopenapi/datamodel/high/v3"
14+
15+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/util"
1416
)
1517

1618
func TestReadOpParameters_Resource(t *testing.T) {
@@ -324,7 +326,6 @@ func TestReadOpParameters_Resource(t *testing.T) {
324326
},
325327
}
326328
for name, testCase := range testCases {
327-
name, testCase := name, testCase
328329
t.Run(name, func(t *testing.T) {
329330
t.Parallel()
330331

@@ -335,7 +336,7 @@ func TestReadOpParameters_Resource(t *testing.T) {
335336

336337
mergedParameters := resource.ReadOpParameters()
337338

338-
if diff := cmp.Diff(mergedParameters, testCase.want, cmp.AllowUnexported(base.Schema{}, base.SchemaProxy{}, sync.Mutex{}, high.Parameter{})); diff != "" {
339+
if diff := cmp.Diff(mergedParameters, testCase.want, cmpopts.IgnoreUnexported(sync.Mutex{}), cmp.AllowUnexported(base.Schema{}, base.SchemaProxy{}, high.Parameter{})); diff != "" {
339340
t.Errorf("unexpected difference for resource: %s", diff)
340341
}
341342
})
@@ -653,7 +654,7 @@ func TestReadOpParameters_DataSource(t *testing.T) {
653654
},
654655
}
655656
for name, testCase := range testCases {
656-
name, testCase := name, testCase
657+
657658
t.Run(name, func(t *testing.T) {
658659
t.Parallel()
659660

@@ -664,7 +665,7 @@ func TestReadOpParameters_DataSource(t *testing.T) {
664665

665666
mergedParameters := dataSource.ReadOpParameters()
666667

667-
if diff := cmp.Diff(mergedParameters, testCase.want, cmp.AllowUnexported(base.Schema{}, base.SchemaProxy{}, sync.Mutex{}, high.Parameter{})); diff != "" {
668+
if diff := cmp.Diff(mergedParameters, testCase.want, cmpopts.IgnoreUnexported(sync.Mutex{}), cmp.AllowUnexported(base.Schema{}, base.SchemaProxy{}, high.Parameter{})); diff != "" {
668669
t.Errorf("unexpected difference for data source: %s", diff)
669670
}
670671
})

internal/explorer/guesstimator_explorer_test.go

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,6 @@ func Test_GuesstimatorExplorer_FindResources(t *testing.T) {
9696
}
9797

9898
for name, testCase := range testCases {
99-
name, testCase := name, testCase
10099

101100
t.Run(name, func(t *testing.T) {
102101
t.Parallel()
@@ -196,7 +195,6 @@ func Test_GuesstimatorExplorer_FindDataSources(t *testing.T) {
196195
}
197196

198197
for name, testCase := range testCases {
199-
name, testCase := name, testCase
200198

201199
t.Run(name, func(t *testing.T) {
202200
t.Parallel()

internal/mapper/attrmapper/bool_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"testing"
88

99
"github.com/google/go-cmp/cmp"
10-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
11-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1210
"github.com/hashicorp/terraform-plugin-codegen-spec/datasource"
1311
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
1412
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
13+
14+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
15+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1516
)
1617

1718
func TestResourceBoolAttribute_Merge(t *testing.T) {
@@ -113,7 +114,7 @@ func TestResourceBoolAttribute_Merge(t *testing.T) {
113114
},
114115
}
115116
for name, testCase := range testCases {
116-
name, testCase := name, testCase
117+
117118
t.Run(name, func(t *testing.T) {
118119
t.Parallel()
119120

@@ -155,7 +156,7 @@ func TestResourceBoolAttribute_ApplyOverride(t *testing.T) {
155156
},
156157
}
157158
for name, testCase := range testCases {
158-
name, testCase := name, testCase
159+
159160
t.Run(name, func(t *testing.T) {
160161
t.Parallel()
161162

@@ -267,7 +268,7 @@ func TestDataSourceBoolAttribute_Merge(t *testing.T) {
267268
},
268269
}
269270
for name, testCase := range testCases {
270-
name, testCase := name, testCase
271+
271272
t.Run(name, func(t *testing.T) {
272273
t.Parallel()
273274

@@ -309,7 +310,7 @@ func TestDataSourceBoolAttribute_ApplyOverride(t *testing.T) {
309310
},
310311
}
311312
for name, testCase := range testCases {
312-
name, testCase := name, testCase
313+
313314
t.Run(name, func(t *testing.T) {
314315
t.Parallel()
315316

internal/mapper/attrmapper/data_source_attributes_test.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ import (
77
"testing"
88

99
"github.com/google/go-cmp/cmp"
10-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
11-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1210
"github.com/hashicorp/terraform-plugin-codegen-spec/datasource"
1311
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
12+
13+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
14+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1415
)
1516

1617
func TestDataSourceAttributes_Merge(t *testing.T) {
@@ -187,7 +188,7 @@ func TestDataSourceAttributes_Merge(t *testing.T) {
187188
},
188189
}
189190
for name, testCase := range testCases {
190-
name, testCase := name, testCase
191+
191192
t.Run(name, func(t *testing.T) {
192193
t.Parallel()
193194

@@ -355,7 +356,7 @@ func TestDataSourceAttributes_ApplyOverrides(t *testing.T) {
355356
},
356357
}
357358
for name, testCase := range testCases {
358-
name, testCase := name, testCase
359+
359360
t.Run(name, func(t *testing.T) {
360361
t.Parallel()
361362

internal/mapper/attrmapper/float64_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"testing"
88

99
"github.com/google/go-cmp/cmp"
10-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
11-
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1210
"github.com/hashicorp/terraform-plugin-codegen-spec/datasource"
1311
"github.com/hashicorp/terraform-plugin-codegen-spec/resource"
1412
"github.com/hashicorp/terraform-plugin-codegen-spec/schema"
13+
14+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/explorer"
15+
"github.com/hashicorp/terraform-plugin-codegen-openapi/internal/mapper/attrmapper"
1516
)
1617

1718
func TestResourceFloat64Attribute_Merge(t *testing.T) {
@@ -113,7 +114,7 @@ func TestResourceFloat64Attribute_Merge(t *testing.T) {
113114
},
114115
}
115116
for name, testCase := range testCases {
116-
name, testCase := name, testCase
117+
117118
t.Run(name, func(t *testing.T) {
118119
t.Parallel()
119120

@@ -155,7 +156,7 @@ func TestResourceFloat64Attribute_ApplyOverride(t *testing.T) {
155156
},
156157
}
157158
for name, testCase := range testCases {
158-
name, testCase := name, testCase
159+
159160
t.Run(name, func(t *testing.T) {
160161
t.Parallel()
161162

@@ -267,7 +268,7 @@ func TestDataSourceFloat64Attribute_Merge(t *testing.T) {
267268
},
268269
}
269270
for name, testCase := range testCases {
270-
name, testCase := name, testCase
271+
271272
t.Run(name, func(t *testing.T) {
272273
t.Parallel()
273274

@@ -309,7 +310,7 @@ func TestDataSourceFloat64Attribute_ApplyOverride(t *testing.T) {
309310
},
310311
}
311312
for name, testCase := range testCases {
312-
name, testCase := name, testCase
313+
313314
t.Run(name, func(t *testing.T) {
314315
t.Parallel()
315316

0 commit comments

Comments
 (0)