Skip to content
This repository has been archived by the owner on Mar 11, 2021. It is now read-only.

capture range variable for parallel testing #2346

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions workitem/enum_type_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ func TestEnumType_GetDefaultValue(t *testing.T) {
}, 222},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.expectedOutput, tt.enum.GetDefaultValue())
Expand All @@ -139,7 +140,7 @@ func TestEnumType_SetDefaultValue(t *testing.T) {
Values: []interface{}{"first", "second", "third"},
},
"second",
&w.EnumType{
w.EnumType{
SimpleType: w.SimpleType{Kind: w.KindEnum},
BaseType: w.SimpleType{Kind: w.KindString},
Values: []interface{}{"first", "second", "third"},
Expand All @@ -153,7 +154,7 @@ func TestEnumType_SetDefaultValue(t *testing.T) {
Values: []interface{}{"first", "second", "third"},
},
nil,
&w.EnumType{
w.EnumType{
SimpleType: w.SimpleType{Kind: w.KindEnum},
BaseType: w.SimpleType{Kind: w.KindString},
Values: []interface{}{"first", "second", "third"},
Expand All @@ -180,6 +181,7 @@ func TestEnumType_SetDefaultValue(t *testing.T) {
true},
}
for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
output, err := tt.enum.SetDefaultValue(tt.defVal)
Expand Down Expand Up @@ -272,6 +274,7 @@ func TestEnumType_Validate(t *testing.T) {
}, true},
}
for _, tt := range tests {
tt := tt
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.obj.Validate()
Expand Down Expand Up @@ -407,8 +410,10 @@ func TestEnumType_ConvertFromModel(t *testing.T) {
},
}
for _, test := range tests {
test := test
t.Run(test.name, func(t *testing.T) {
for _, subtt := range test.data {
subtt := subtt
t.Run(subtt.subTestName, func(tt *testing.T) {
val, err := test.enum.ConvertFromModel(subtt.input)
if subtt.wantErr {
Expand Down
6 changes: 6 additions & 0 deletions workitem/link/topology_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ func TestTopology_String(t *testing.T) {
link.TopologyTree: "tree",
}
for in, out := range inOut {
in := in
out := out
t.Run(in.String(), func(t *testing.T) {
t.Parallel()
require.Equal(t, out, in.String())
Expand Down Expand Up @@ -62,6 +64,8 @@ func TestTopology_Scan(t *testing.T) {
}

for i, td := range testDataArr {
i := i
td := td
t.Run(fmt.Sprintf("%d", i), func(t *testing.T) {
t.Parallel()
var l link.Topology
Expand All @@ -87,6 +91,8 @@ func TestTopology_CheckValid(t *testing.T) {
link.Topology("foo"): true,
}
for topo, expectError := range expectErrorArr {
topo := topo
expectError := expectError
t.Run(topo.String(), func(t *testing.T) {
t.Parallel()
err := topo.CheckValid()
Expand Down
14 changes: 8 additions & 6 deletions workitem/list_type_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ func TestListType_SetDefaultValue(t *testing.T) {

tests := []struct {
name string
enum ListType
listType ListType
defVal interface{}
expectedOutput FieldType
wantErr bool
Expand All @@ -143,11 +143,11 @@ func TestListType_SetDefaultValue(t *testing.T) {
SimpleType: SimpleType{Kind: KindList},
ComponentType: SimpleType{Kind: KindString},
},
[]interface{}{"second"},
&ListType{
"second",
ListType{
SimpleType: SimpleType{Kind: KindList},
ComponentType: SimpleType{Kind: KindString},
DefaultValue: []interface{}{"second"},
DefaultValue: "second",
},
false},
{"set default to nil",
Expand All @@ -156,7 +156,7 @@ func TestListType_SetDefaultValue(t *testing.T) {
ComponentType: SimpleType{Kind: KindString},
},
nil,
&ListType{
ListType{
SimpleType: SimpleType{Kind: KindList},
ComponentType: SimpleType{Kind: KindString},
DefaultValue: nil,
Expand All @@ -171,10 +171,12 @@ func TestListType_SetDefaultValue(t *testing.T) {
nil,
true},
}

for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
output, err := tt.enum.SetDefaultValue(tt.defVal)
output, err := tt.listType.SetDefaultValue(tt.defVal)
if tt.wantErr {
require.Error(t, err)
} else {
Expand Down
7 changes: 5 additions & 2 deletions workitem/simple_type_blackbox_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ func TestSimpleType_Validate(t *testing.T) {
{"invalid kind (list)", SimpleType{Kind: KindList, DefaultValue: "foo"}, true},
}
for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
err := tt.obj.Validate()
Expand All @@ -77,6 +78,7 @@ func TestSimpleType_GetDefault(t *testing.T) {
{"ok - string field nil default", SimpleType{Kind: KindString}, nil},
}
for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
require.Equal(t, tt.output, tt.obj.GetDefaultValue())
Expand All @@ -98,12 +100,12 @@ func TestSimpleType_SetDefaultValue(t *testing.T) {
{"set default to allowed value",
SimpleType{Kind: KindString},
"foo",
&SimpleType{Kind: KindString, DefaultValue: "foo"},
SimpleType{Kind: KindString, DefaultValue: "foo"},
false},
{"set default to nil",
SimpleType{Kind: KindString},
nil,
&SimpleType{Kind: KindString, DefaultValue: nil},
SimpleType{Kind: KindString, DefaultValue: nil},
false},
{"set default to not-allowed value",
SimpleType{Kind: KindString},
Expand All @@ -112,6 +114,7 @@ func TestSimpleType_SetDefaultValue(t *testing.T) {
true},
}
for _, tt := range tests {
tt := tt // capture range variable
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
output, err := tt.enum.SetDefaultValue(tt.defVal)
Expand Down