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

unit tests change global flag which persists for other unit tests #141

Closed
jeffg-hpe opened this issue Jul 2, 2019 · 2 comments
Closed
Labels

Comments

@jeffg-hpe
Copy link

jeffg-hpe commented Jul 2, 2019

If a unit test modifies the flag Strict , that change persists to other unit tests, resulting in unexpected behavior.

The end result might be a non-issue currently due to what is being tested, but it's non-intuitive for devs adding additional functionality and writing similar tests (see #127).

These unit tests are the only ones that modify Strict:

kubeval/kubeval_test.go-func TestStrictCatchesAdditionalErrors(t *testing.T) {
kubeval/kubeval_test.go:        Strict = true
--
kubeval/kubeval_test.go-func TestValidateMultipleVersions(t *testing.T) {
kubeval/kubeval_test.go:        Strict = true
--
kubeval/kubeval_test.go-func TestDetermineSchema(t *testing.T) {
kubeval/kubeval_test.go:        Strict = false

When I run make test, a different test TestValidInputsWithErrors which does not set Strict, and thus probably expects it to be false, actually runs with Strict = true:

func TestValidateInputsWithErrors(t *testing.T) {
    if Strict {
        t.Errorf("I didn't enable strict mode")
    }
$ make test
...
=== RUN   TestValidateInputsWithErrors
--- FAIL: TestValidateInputsWithErrors (0.31s)
    kubeval_test.go:107: I didn't enable strict mode
...

I'd propose considering fixing this by passing in Strict and similar flags to the Validate, ValidateWithCache, and determineSchema, but that's just a suggestion.

@garethr
Copy link
Collaborator

garethr commented Jul 13, 2019

Agreed. I've been aware of this for a while and haven't had enough time to refactor it out. Passing in the flags is definitely the right approach I think.

@garethr
Copy link
Collaborator

garethr commented Aug 18, 2019

This should be resolved by #158

@garethr garethr closed this as completed Aug 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants