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
+7 -9
View File
@@ -50,17 +50,15 @@ func TestServer(t *testing.T) {
go func() {
errC <- root.ExecuteContext(ctx)
}()
var client *codersdk.Client
var rawURL string
require.Eventually(t, func() bool {
rawURL, err := cfg.URL().Read()
if err != nil {
return false
}
accessURL, err := url.Parse(rawURL)
assert.NoError(t, err)
client = codersdk.New(accessURL)
return true
rawURL, err = cfg.URL().Read()
return err == nil && rawURL != ""
}, time.Minute, 50*time.Millisecond)
accessURL, err := url.Parse(rawURL)
require.NoError(t, err)
client := codersdk.New(accessURL)
_, err = client.CreateFirstUser(ctx, codersdk.CreateFirstUserRequest{
Email: "some@one.com",
Username: "example",