Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(tests): testifylint automated fixes #13396

Merged
merged 1 commit into from
Jul 27, 2024
Merged

Conversation

Joibel
Copy link
Member

@Joibel Joibel commented Jul 26, 2024

This is part of a series of test tidies started by #13365.

The aim is to enable the testifylint golangci-lint checker.

This patch is just the automated fixes (testifylint --fix) excluding the removal of the t.Parallel from cron_test.go.


Some fixes like

assert.True(t, len(pods.Items) > 0, "pod was not created successfully")

went to

assert.Positive(t, pods.Items, "pod was not created successfully")

and I have manually converted these to

assert.NotEmpty(t, pods.Items, "pod was not created successfully")

test/e2e/agent_test.go also needed 0->time.Duration(0) for one assert.Equal.


Note to maintainers: Please feel free to apply fixes yourself to this PR

@Joibel Joibel assigned Joibel and unassigned Joibel Jul 26, 2024
@Joibel Joibel changed the title chore: testifylint automated fixes chore(tests): testifylint automated fixes Jul 26, 2024
This is part of a series of test tidies started by #13365.

The aim is to enable the testifylint golangci-lint checker.

This patch is just the automated fixes excluding the removal of the
t.Parallel from `cron_test.go`.

Some fixes like

```go
assert.True(t, len(pods.Items) > 0, "pod was not created successfully")
```

went to

```go
assert.Positive(t, pods.Items, "pod was not created successfully")
```

and I have manually converted these to

```go
assert.NotEmpty(t, pods.Items, "pod was not created successfully")
```

`test/e2e/agent_test.go` also needed `0`->`time.Duration(0)` for one `assert.Equal`.

Signed-off-by: Alan Clucas <[email protected]>
@Joibel Joibel force-pushed the testifylint-automated-fix branch from fcdc510 to 879d23a Compare July 26, 2024 15:11
@agilgur5 agilgur5 changed the title chore(tests): testifylint automated fixes refactor(tests): testifylint automated fixes Jul 27, 2024
@agilgur5 agilgur5 added the area/build Build or GithubAction/CI issues label Jul 27, 2024
Copy link

@agilgur5 agilgur5 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, these all look like great changes to me, hopefully we can get the tool into CI soon.

The nicer assertions make the code easier to read and, perhaps more importantly, will make test failures much easier to read.

errors/errors_test.go Show resolved Hide resolved
test/e2e/argo_server_test.go Show resolved Hide resolved
workflow/controller/operator_agent_test.go Show resolved Hide resolved
@agilgur5 agilgur5 merged commit da3cf74 into main Jul 27, 2024
30 checks passed
@agilgur5 agilgur5 deleted the testifylint-automated-fix branch July 27, 2024 16:05
@Joibel
Copy link
Member Author

Joibel commented Jul 27, 2024

LGTM, these all look like great changes to me, hopefully we can get the tool into CI soon.

Switching it on is as simple as adding it to .golangci.yaml.

--- a/.golangci.yml
+++ b/.golangci.yml
@@ -33,6 +33,7 @@ linters:
     - rowserrcheck
     - sqlclosecheck
     - staticcheck
+    - testifylint
     - typecheck
     - unparam
     - unused

The remaining work (outside of all the require PRs) is:

  • test/e2e assert->require (I have started on this)
  • a minor number of float-compare: use assert.InEpsilon (or InDelta) fixes
  • fixing t.Parallel() in test_cron.go (testify/suite doesn't actually allow parallel as discussed and the linter understands this). Temporary removal to get the linter switched on is fine.
  • enable linter

The temporary downside is that merged PRs from CI that happened before the linter enablement may fail the linter after merge. We'll just have to deal with it as it happens.

@agilgur5
Copy link

agilgur5 commented Jul 27, 2024

Temporary removal to get the linter switched on is fine.

could also temporarily add a lint ignore

  • test/e2e assert->require (I have started on this)

You mentioned testifylint in those PRs, so it actually has a check for this? nice

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/build Build or GithubAction/CI issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants