From 5cf81c5cdb16b22cb52373bba573713cb05bc21e Mon Sep 17 00:00:00 2001 From: David Turner Date: Tue, 16 Aug 2022 08:40:17 +0100 Subject: [PATCH 1/2] Add YAML spec docs about matching errors It's not obvious that a YAML test with a `catch` stanza also permits `match` blocks to assert things about the structure of the error response, but this structure may be an important part of the API spec. This commit adds this info to the docs about YAML tests. --- .../resources/rest-api-spec/test/README.asciidoc | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc index 0544ec2bf8a61..044004c46780f 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc @@ -320,8 +320,13 @@ be caught and tested. For instance: catch: missing get: index: test - type: test + type: test id: 1 + + - match: { error.type: "illegal_argument_exception" } + - match: { error.reason: "The request contained an illegal argument" } + - match: { error.caused_by.reason: "The argument was illegal because ..." } + - match: { error.root_cause.0.type: "illegal_argument_exception" } .... The argument to `catch` can be any of: From ae64ef140db730f4c6ec2c6aaf6622c23fb0bc3e Mon Sep 17 00:00:00 2001 From: David Turner Date: Thu, 18 Aug 2022 13:05:33 +0100 Subject: [PATCH 2/2] Assertions are optional --- .../yamlRestTest/resources/rest-api-spec/test/README.asciidoc | 2 ++ 1 file changed, 2 insertions(+) diff --git a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc index 044004c46780f..f2f04e219afdf 100644 --- a/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc +++ b/rest-api-spec/src/yamlRestTest/resources/rest-api-spec/test/README.asciidoc @@ -323,6 +323,8 @@ be caught and tested. For instance: type: test id: 1 +# And, optionally, you can assert on the contents of the precise contents of the error message: + - match: { error.type: "illegal_argument_exception" } - match: { error.reason: "The request contained an illegal argument" } - match: { error.caused_by.reason: "The argument was illegal because ..." }