From d9ac8fccf02603851930885fbea3af4c254e230e Mon Sep 17 00:00:00 2001 From: Muhammad Faizan Date: Tue, 12 Mar 2024 13:13:07 +0100 Subject: [PATCH] updated eventing code guidelines (#901) --- concepts/eventing-code-guidelines.md | 16 ---------------- 1 file changed, 16 deletions(-) diff --git a/concepts/eventing-code-guidelines.md b/concepts/eventing-code-guidelines.md index 0ec86fbf6..55434f12e 100644 --- a/concepts/eventing-code-guidelines.md +++ b/concepts/eventing-code-guidelines.md @@ -825,22 +825,6 @@ func TestTwoDimensions(t *testing.T) { } ``` -
- Reason for variable reassignment (tc := tc) - -The loop iteration variable in Go is a single variable. The closure for the second t.Run is executed inside a goroutine. -If there are multiple entries in the `cloudEvents` struct, `ce` references the last entry in `cloudEvents` in every iteration. The problem occurs because the closure referring to `tc` and `ce` is not executed in **sync** with the **for loop** (because of t.parallel). -To prevent this problem, `ce` and `tc` must be copied (`ce := ce`). -The linter [scopelint](https://github.com/golangci/golangci-lint/blob/master/pkg/golinters/scopelint.go) warns about the possible problem whenever `ce` or `tc` is used. - ->**CAUTION:** If you add `// nolint:scopelint` to silence scopelint, you might not notice when `ce` or `tc` references the wrong entry in the test case list. - -**See Also**: -- [Go Wiki - Common Mistakes](https://github.com/golang/go/wiki/CommonMistakes#using-goroutines-on-loop-iterator-variables) -- [Example when using t.Parallel and for loops in table-driven tests](https://gist.github.com/posener/92a55c4cd441fc5e5e85f27bca008721) - -
-
Reason for using nested t.Run