fix: Remove use of require in require.Eventually in tests (#3110)

* fix: Remove use of `require` in `require.Eventually` in tests

Because require uses `t.FailNow()` and `require.Eventually` runs the
function in a goroutine, which is not allowed.

* feat: Add ruleguard for require.Eventually

Co-authored-by: Cian Johnston <cian@coder.com>
This commit is contained in:
Mathias Fredriksson
2022-07-22 20:02:49 +03:00
committed by GitHub
co-authored by Cian Johnston
parent 3bb760576b
commit 51dd1fde3b
10 changed files with 74 additions and 46 deletions
+15 -4
View File
@@ -59,6 +59,17 @@ func doNotCallTFailNowInsideGoroutine(m dsl.Matcher) {
Where(m["require"].Text == "require").
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
// require.Eventually runs the function in a goroutine.
m.Match(`
require.Eventually(t, func() bool {
$*_
$require.$_($*_)
$*_
}, $*_)`).
At(m["require"]).
Where(m["require"].Text == "require").
Report("Do not call functions that may call t.FailNow in a goroutine, as this can cause data races (see testing.go:834)")
m.Match(`
go func($*_){
$*_
@@ -90,10 +101,10 @@ func InTx(m dsl.Matcher) {
At(m["f"]).
Report("Do not use the database directly within the InTx closure. Use '$y' instead of '$x'.")
//When using a tx closure, ensure that if you pass the db to another
//function inside the closure, it is the tx.
//This will miss more complex cases such as passing the db as apart
//of another struct.
// When using a tx closure, ensure that if you pass the db to another
// function inside the closure, it is the tx.
// This will miss more complex cases such as passing the db as apart
// of another struct.
m.Match(`
$x.InTx(func($y database.Store) error {
$*_