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

Report status code before schema #338

Merged
merged 9 commits into from May 21, 2019

Conversation

tsiq-karold
Copy link
Collaborator

Closes #302

Before merging this, I'd like some feedback. Prior to this PR, any HttpValidationHandler errors are reported even if status code fails or user expectations fail. This is confusing in the case where you expect a request to succeed but it fails and the failure response is of a different schema to what you'd expect; it's confusing because you get a schema validation failure and the fact the request failed is not reported.

We have two options. The behaviour this PR introduces is to only run HttpValidationHandlers if everything else is fine. So generally you'll get a status code error or user expectation error and only if both of those are fine will you get a schema error.

Do you think it would be better to report in this order:

  1. status code mismatch
  2. schema failures
  3. user expectations

I suspect that's generally better because if the schema is incorrect the odds of the user expectations passing are reduced anyway and could send someone down a rabbit hole. Unfortunately, this probably requires substantially more refactoring.

Thoughts?

Copy link
Member

@MykolaGolubyev MykolaGolubyev left a comment

Choose a reason for hiding this comment

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

It makes sense to me on high level. Thank you for fixing the confusion in errors.

@@ -7,13 +7,13 @@
}, {
"scenario" : "disable request validation",
"stepsSummary" : {
"numberOfFailed" : 2
"numberOfSuccessful" : 3
Copy link
Member

Choose a reason for hiding this comment

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

do we still need a failed case?

@@ -982,6 +983,75 @@ class HttpGroovyTest implements HttpConfiguration {
http.lastValidationResult.errorMessage.should == ~/java.lang.IllegalArgumentException: Request header is null/
}

@Test
void "implicit status code mismatch reported before additional validators"() {
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") }
Copy link
Member

Choose a reason for hiding this comment

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

wonder if we should use the withAdditional... pattern we use for some other handler like classes

}

@Test
void "assertion and additional validation errors"() {
Copy link
Member

Choose a reason for hiding this comment

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

style of the test name mismatches the other ones.


@Test
void "additional validator errors reported if status code is correct"() {
HttpValidationHandlers.register { result -> throw new AssertionError((Object)"schema validation error") }
Copy link
Member

Choose a reason for hiding this comment

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

if (as per other comment) we don't introduce a withAdditional like method, then maybe we should extract the repetitive code in this test to a private static method wtihAdditionalFailedHandler('schema validation error') {...}

statusCode.should == 404
id.should == 'foo'
}
} should throwException(AssertionError, ~/expected: "foo"/)
Copy link
Member

Choose a reason for hiding this comment

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

not clear by this check if the schema validation error is not part of the exception.

@@ -23,6 +23,15 @@
public class HttpValidationHandlers {
private static final List<HttpValidationHandler> configurations = ServiceLoaderUtils.load(HttpValidationHandler.class);

public static void register(HttpValidationHandler handler) {
Copy link
Member

Choose a reason for hiding this comment

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

Most of the times I call these methods simply add. But I may have slipped a few ones like register. Should we rename to add?

configurations.add(handler);
}

public static void reset() {
Copy link
Member

Choose a reason for hiding this comment

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

Would prefer to maintain as fewer resets like methods as possible.

try {
code {
http.get("/notfound") {}
} should throwException(AssertionError, ~/(?s)header.statusCode.*404.*200/)
Copy link
Member

Choose a reason for hiding this comment

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

order is not clear based on the assertion

@tsiq-karold
Copy link
Collaborator Author

I think I've addressed all your comments @MykolaGolubyev , please review again.

@MykolaGolubyev
Copy link
Member

beautiful!
Do we still need to filter resources in pom.xml? If not, let's remove it to avoid confusion?

@tsiq-karold
Copy link
Collaborator Author

I wondered about that and then forgot to check. Looks safe to remove though, commit coming up.

@tsiq-karold tsiq-karold merged commit 4594c00 into master May 21, 2019
@tsiq-karold tsiq-karold deleted the report-status-code-before-schema branch May 21, 2019 12:19
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.

Assertion failure reporting precedence
2 participants