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

test(testutil): fix tests when run with -count=2 #280

Merged
merged 1 commit into from
Aug 18, 2023

Conversation

benhoyt
Copy link
Contributor

@benhoyt benhoyt commented Aug 18, 2023

Currently when you run:

go test -count=2 -v ./internals/testutil/ -check.v

It fails with the following error:

FAIL: exec_test.go:89: fakeCommandSuite.TestFakeShellchecksWhenAvailable

using shellcheck: "/usr/bin/shellcheck"
exec_test.go:106:
    c.Assert(fakeShellcheck.Calls(), check.DeepEquals, [][]string{
        {"shellcheck", "-s", "bash", "-"},
    })
... obtained [][]string = [][]string(nil)
... expected [][]string = [][]string{[]string{"shellcheck", "-s", "bash", "-"}} ... Difference:
...     [][]string[0] != [][]string[1]

Because TestFakeShellchecksWhenAvailable relies on global state. Reset this global state before each run to allow this package's tests to be run more than once (-count=N where N>1).

Currently when you run:

go test -count=2 -v ./internals/testutil/ -check.v

It fails with the following error:

FAIL: exec_test.go:89: fakeCommandSuite.TestFakeShellchecksWhenAvailable

using shellcheck: "/usr/bin/shellcheck"
exec_test.go:106:
    c.Assert(fakeShellcheck.Calls(), check.DeepEquals, [][]string{
        {"shellcheck", "-s", "bash", "-"},
    })
... obtained [][]string = [][]string(nil)
... expected [][]string = [][]string{[]string{"shellcheck", "-s", "bash", "-"}}
... Difference:
...     [][]string[0] != [][]string[1]

Because TestFakeShellchecksWhenAvailable relies on global state. Reset
this global state before each run to allow this package's tests to be
run more than once (-count=N where N>1).
@benhoyt benhoyt changed the title test(testutil): Fix TestFakeShellchecksWhenAvailable when run with -count=2 test(testutil): Fix tests when run with -count=2 Aug 18, 2023
@benhoyt benhoyt changed the title test(testutil): Fix tests when run with -count=2 test(testutil): fix tests when run with -count=2 Aug 18, 2023
@jnsgruk jnsgruk requested review from flotter and anpep August 18, 2023 09:01
Copy link
Member

@jnsgruk jnsgruk left a comment

Choose a reason for hiding this comment

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

Love a one liner fix 😁

Copy link
Contributor

@flotter flotter left a comment

Choose a reason for hiding this comment

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

Looks good to me!

@jnsgruk jnsgruk merged commit 03e42a6 into canonical:master Aug 18, 2023
13 checks passed
@benhoyt benhoyt deleted the fix-shellcheck-tests branch August 20, 2023 22:35
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.

4 participants