Skip to content

Commit 81cc163

Browse files
diegobernardesbmoffatt
authored andcommitted
Fix the use of a variable on range scope (#238)
As is, the code isn't wrong, but if concurrency is introduced in the tests, this gonna be a problem.
1 parent 319e4b3 commit 81cc163

File tree

6 files changed

+12
-1
lines changed

6 files changed

+12
-1
lines changed

events/attributevalue_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ func TestAccessWithWrongTypePanics(t *testing.T) {
211211
}
212212

213213
for _, testCase := range testCases {
214+
testCase := testCase
214215
var av DynamoDBAttributeValue
215216
err := json.Unmarshal([]byte(testCase.input), &av)
216217
assert.Nil(t, err)

events/chime_bot_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ package events
44
import (
55
"encoding/json"
66
"testing"
7+
"time"
78

89
"github.com/aws/aws-lambda-go/events/test"
910
"github.com/stretchr/testify/assert"
10-
"time"
1111
)
1212

1313
func TestChimeBotEventMarshaling(t *testing.T) {
@@ -116,6 +116,7 @@ func TestChimeBotEventMarshaling(t *testing.T) {
116116
}
117117

118118
for name, test := range tests {
119+
test := test
119120
t.Run(name, func(t *testing.T) {
120121
var testEvent ChimeBotEvent
121122
if err := json.Unmarshal([]byte(test.inputJSON), &testEvent); err != nil {

events/cloudwatch_logs_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ func TestCloudwatchLogs(t *testing.T) {
2525
},
2626
},
2727
} {
28+
test := test
2829
t.Run(test.name, func(t *testing.T) {
2930
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
3031

@@ -71,6 +72,7 @@ func TestCloudwatchLogsParse(t *testing.T) {
7172
},
7273
},
7374
} {
75+
test := test
7476
t.Run(test.name, func(t *testing.T) {
7577
inputJson := tst.ReadJSONFromFile(t, test.eventJson)
7678

events/code_commit_test.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ func TestCodeCommitReference(t *testing.T) {
3333
}
3434

3535
for _, c := range cases {
36+
c := c
3637
t.Run(c.Name, func(t *testing.T) {
3738
test.AssertJsonBytes(t, c.Input, &CodeCommitReference{})
3839
})
@@ -69,6 +70,7 @@ func TestCodeCommitCodeCommit(t *testing.T) {
6970
}
7071

7172
for _, c := range cases {
73+
c := c
7274
t.Run(c.Name, func(t *testing.T) {
7375
test.AssertJsonBytes(t, c.Input, &CodeCommitCodeCommit{})
7476
})
@@ -128,6 +130,7 @@ func TestCodeCommitRecord(t *testing.T) {
128130
}
129131

130132
for _, c := range cases {
133+
c := c
131134
t.Run(c.Name, func(t *testing.T) {
132135
test.AssertJsonBytes(t, c.Input, &CodeCommitRecord{})
133136
})
@@ -150,6 +153,7 @@ func TestCodeCommitEvent(t *testing.T) {
150153
}
151154

152155
for _, c := range cases {
156+
c := c
153157
t.Run(c.Name, func(t *testing.T) {
154158
test.AssertJsonBytes(t, c.Input, &CodeCommitEvent{})
155159
})

events/ses_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ func TestSESEventMarshaling(t *testing.T) {
1919
}
2020

2121
for _, tc := range tests {
22+
tc := tc
2223
t.Run(tc.file, func(t *testing.T) {
2324
inputJSON := test.ReadJSONFromFile(t, tc.file)
2425

lambda/handler_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ func TestInvalidHandlers(t *testing.T) {
7272
},
7373
}
7474
for i, testCase := range testCases {
75+
testCase := testCase
7576
t.Run(fmt.Sprintf("testCase[%d] %s", i, testCase.name), func(t *testing.T) {
7677
lambdaHandler := NewHandler(testCase.handler)
7778
_, err := lambdaHandler.Invoke(context.TODO(), make([]byte, 0))
@@ -188,6 +189,7 @@ func TestInvokes(t *testing.T) {
188189
},
189190
}
190191
for i, testCase := range testCases {
192+
testCase := testCase
191193
t.Run(fmt.Sprintf("testCase[%d] %s", i, testCase.name), func(t *testing.T) {
192194
lambdaHandler := NewHandler(testCase.handler)
193195
response, err := lambdaHandler.Invoke(context.TODO(), []byte(testCase.input))

0 commit comments

Comments
 (0)