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

Use require a lot more than assert in js tests #2564

Merged
merged 9 commits into from
Jun 13, 2022
Merged

Conversation

mstoykov
Copy link
Contributor

@mstoykov mstoykov commented Jun 13, 2022

The js tests had a bunch of places where they were using assert instead of require.

Mostly cases where the test should've not continued such as expecting error or no error. In some places if assert.... was used which also is completely not needed.

I have kept most usage of assert where they will report multiple (and even singular failures sometimes), but I would argue in most cases just using require for everything is likely enough.

There are also a few places where I've added requires that were previously missing.

Finally, there are few places that could've been left as assert but I decided to go for require in order for there to be no assert.Error for example. As I would argue this should always be with require.

Some of those lead to fewer reported failures as previously an if assert ... was followed by more code that could run even if that assert is a failure. But I would argue in all of those cases that is unlikely, and even if that happens this particular failures will likely not help debug the original problem.

@mstoykov
Copy link
Contributor Author

This PR will be squashed upon merging. I have separate commits as that was easier to work with locally.

You can review them all at the same time, but I would recommend disabling whitespace diffing ;)

@github-actions github-actions bot requested review from codebien and na-- June 13, 2022 12:48

f, err := os.Open(logFilename)
assert.NoError(t, err)
f, err = os.Open(logFilename) //nolint:gosec
Copy link
Member

Choose a reason for hiding this comment

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

This is weird 😕 getSimpleRunner() uses afero.NewMemMapFs() by default, so why (and how) are we polluting the real filesystem here? 😕

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We don't use afero in the console code at all - I guess this is a thing we can open a issue about 🤔

f, err := os.OpenFile(filepath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, 0o644) //nolint:gosec

Copy link
Member

Choose a reason for hiding this comment

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

hmm... 🤔 yeah, please open an issue, we should fix this 😞

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Copy link
Contributor

@codebien codebien left a comment

Choose a reason for hiding this comment

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

LGTM

@mstoykov mstoykov merged commit dbdd1b2 into master Jun 13, 2022
@mstoykov mstoykov deleted the jsTestUpdates branch June 13, 2022 13:28
@mstoykov mstoykov added this to the v0.39.0 milestone Jun 14, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants