Skip to content

Commit eb5279f

Browse files
committed
test: fix concurrent map write of TestValidateFormType
1 parent 5648efb commit eb5279f

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

provider/formtype_test.go

+5-4
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"regexp"
77
"strconv"
88
"strings"
9+
"sync"
910
"testing"
1011

1112
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
@@ -53,7 +54,7 @@ func TestValidateFormType(t *testing.T) {
5354
// formTypesChecked keeps track of all checks run. It will be used to
5455
// ensure all combinations of form_type and option_type are tested.
5556
// All untested options are assumed to throw an error.
56-
formTypesChecked := make(map[string]struct{})
57+
var formTypesChecked sync.Map
5758

5859
expectType := func(expected provider.ParameterFormType, opts formTypeCheck) formTypeTestCase {
5960
ftname := opts.formType
@@ -240,12 +241,12 @@ func TestValidateFormType(t *testing.T) {
240241
for _, c := range cases {
241242
t.Run(c.name, func(t *testing.T) {
242243
t.Parallel()
243-
if _, ok := formTypesChecked[c.config.String()]; ok {
244+
if _, ok := formTypesChecked.Load(c.config.String()); ok {
244245
t.Log("Duplicated form type check, delete this extra test case")
245246
t.Fatalf("form type %q already checked", c.config.String())
246247
}
247248

248-
formTypesChecked[c.config.String()] = struct{}{}
249+
formTypesChecked.Store(c.config.String(), struct{}{})
249250
formTypeTest(t, c)
250251
})
251252
}
@@ -282,7 +283,7 @@ func TestValidateFormType(t *testing.T) {
282283
}
283284

284285
for _, check := range requiredChecks {
285-
if _, alreadyChecked := formTypesChecked[check.String()]; alreadyChecked {
286+
if _, alreadyChecked := formTypesChecked.Load(check.String()); alreadyChecked {
286287
continue
287288
}
288289

0 commit comments

Comments
 (0)