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

validate/validate_test: Better error messages for unexpected JSON Schema errors #475

Conversation

wking
Copy link
Contributor

@wking wking commented Sep 14, 2017

Instead of raising messages like:

  Error:  Not equal:
          expected: <nil>(<nil>)
          actual:
            *multierror.Error(*multierror.Error{Errors:[]error{(*errors.errorString)(0xc42037adc0)},
            ErrorFormat:(multierror.ErrorFormatFunc)(nil)})

raise messages like:

  * linux.rootfsPropagation: linux.rootfsPropagation must be one of
      the following: "private", "shared", "slave", "unbindable"

…ema errors

Instead of raising messages like:

  Error:  Not equal:
          expected: <nil>(<nil>)
          actual:
            *multierror.Error(*multierror.Error{Errors:[]error{(*errors.errorString)(0xc42037adc0)},
            ErrorFormat:(multierror.ErrorFormatFunc)(nil)})

raise messages like:

  * linux.rootfsPropagation: linux.rootfsPropagation must be one of
      the following: "private", "shared", "slave", "unbindable"

Signed-off-by: W. Trevor King <[email protected]>
@Mashimiao Mashimiao added this to the v0.2.0 milestone Sep 15, 2017
if errs == nil {
return
}
t.Fatalf("expected no error, but got: %s", errs.Error())

Choose a reason for hiding this comment

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

I don't understand the code change. I can't see any relations between the change with your comment.

Copy link
Contributor Author

@wking wking Sep 15, 2017

Choose a reason for hiding this comment

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

I don't understand the code change.

If tt.error is an empty string, and CheckJSONSchema returns nil, then great, the test passes. This worked fine before, and still works fine after this commit.

If CheckJSONSchema raises an error, the old assert.Equal was rendering the unhelpful actual: *multierror.... With this commit, we get the useful * linux.rootfsPropagation... (or whatever the returned error happens to be.

I can't see any relations between the change with your comment.

The examples in the commit message / PR comment are from working up #476. There's not a great example to use for test-failure messages, because all of the tests in master pass ;).

@Mashimiao
Copy link

Mashimiao commented Sep 15, 2017

LGTM

Approved with PullApprove

1 similar comment
@zhouhao3
Copy link

zhouhao3 commented Sep 18, 2017

LGTM

Approved with PullApprove

@zhouhao3 zhouhao3 merged commit ea53765 into opencontainers:master Sep 18, 2017
@wking wking deleted the json-schema-better-unexpected-error-messages branch September 22, 2017 17: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.

3 participants