Skip to content

Commit 1e58740

Browse files
committed
Fail yaml tests and docs snippets that get unexpected warnings
Adds `warnings` syntax to the yaml test that allows you to expect a `Warning` header that looks like: ``` - do: warnings: - '[index] is deprecated' - quotes are not required because yaml - but this argument is always a list, never a single string - no matter how many warnings you expect get: index: test type: test id: 1 ``` These are accessible from the docs with: ``` // TEST[warning:some warning] ``` This should help to force you to update the docs if you deprecate something. You *must* add the warnings marker to the docs or the build will fail. While you are there you *should* update the docs to add deprecation warnings visible in the rendered results.
1 parent 4598c36 commit 1e58740

File tree

26 files changed

+347
-57
lines changed

26 files changed

+347
-57
lines changed

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/RestTestsFromSnippetsTask.groovy

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
119119
current.println(" reason: $test.skipTest")
120120
}
121121
if (test.setup != null) {
122+
// Insert a setup defined outside of the docs
122123
String setup = setups[test.setup]
123124
if (setup == null) {
124125
throw new InvalidUserDataException("Couldn't find setup "
@@ -136,13 +137,23 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
136137
response.contents.eachLine { current.println(" $it") }
137138
}
138139

139-
void emitDo(String method, String pathAndQuery,
140-
String body, String catchPart, boolean inSetup) {
140+
void emitDo(String method, String pathAndQuery, String body,
141+
String catchPart, List warnings, boolean inSetup) {
141142
def (String path, String query) = pathAndQuery.tokenize('?')
142143
current.println(" - do:")
143144
if (catchPart != null) {
144145
current.println(" catch: $catchPart")
145146
}
147+
if (false == warnings.isEmpty()) {
148+
current.println(" warnings:")
149+
for (String warning in warnings) {
150+
// Escape " because we're going to quote the warning
151+
String escaped = warning.replaceAll('"', '\\\\"')
152+
/* Quote the warning in case it starts with [ which makes
153+
* it look too much like an array. */
154+
current.println(" - \"$escaped\"")
155+
}
156+
}
146157
current.println(" raw:")
147158
current.println(" method: $method")
148159
current.println(" path: \"$path\"")
@@ -200,7 +211,8 @@ public class RestTestsFromSnippetsTask extends SnippetsTask {
200211
// Leading '/'s break the generated paths
201212
pathAndQuery = pathAndQuery.substring(1)
202213
}
203-
emitDo(method, pathAndQuery, body, catchPart, inSetup)
214+
emitDo(method, pathAndQuery, body, catchPart, snippet.warnings,
215+
inSetup)
204216
}
205217
}
206218

buildSrc/src/main/groovy/org/elasticsearch/gradle/doc/SnippetsTask.groovy

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,9 @@ public class SnippetsTask extends DefaultTask {
3737
private static final String CATCH = /catch:\s*((?:\/[^\/]+\/)|[^ \]]+)/
3838
private static final String SKIP = /skip:([^\]]+)/
3939
private static final String SETUP = /setup:([^ \]]+)/
40+
private static final String WARNING = /warning:(.+)/
4041
private static final String TEST_SYNTAX =
41-
/(?:$CATCH|$SUBSTITUTION|$SKIP|(continued)|$SETUP) ?/
42+
/(?:$CATCH|$SUBSTITUTION|$SKIP|(continued)|$SETUP|$WARNING) ?/
4243

4344
/**
4445
* Action to take on each snippet. Called with a single parameter, an
@@ -158,6 +159,10 @@ public class SnippetsTask extends DefaultTask {
158159
snippet.setup = it.group(6)
159160
return
160161
}
162+
if (it.group(7) != null) {
163+
snippet.warnings.add(it.group(7))
164+
return
165+
}
161166
throw new InvalidUserDataException(
162167
"Invalid test marker: $line")
163168
}
@@ -230,6 +235,7 @@ public class SnippetsTask extends DefaultTask {
230235
String language = null
231236
String catchPart = null
232237
String setup = null
238+
List warnings = new ArrayList()
233239

234240
@Override
235241
public String toString() {
@@ -254,6 +260,9 @@ public class SnippetsTask extends DefaultTask {
254260
if (setup) {
255261
result += "[setup:$setup]"
256262
}
263+
for (String warning in warnings) {
264+
result += "[warning:$warning]"
265+
}
257266
}
258267
if (testResponse) {
259268
result += '// TESTRESPONSE'

docs/README.asciidoc

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@ are tests even if they don't have `// CONSOLE`.
2828
* `// TEST[setup:name]`: Run some setup code before running the snippet. This
2929
is useful for creating and populating indexes used in the snippet. The setup
3030
code is defined in `docs/build.gradle`.
31+
* `// TEST[warning:some warning]`: Expect the response to include a `Warning`
32+
header. If the response doesn't include a `Warning` header with the exact
33+
text then the test fails. If the response includes `Warning` headers that
34+
aren't expected then the test fails.
3135
* `// TESTRESPONSE`: Matches this snippet against the body of the response of
3236
the last test. If the response is JSON then order is ignored. With
3337
`// TEST[continued]` you can make tests that contain multiple command snippets

docs/plugins/mapper-attachments.asciidoc

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,14 +196,14 @@ PUT /test
196196
"file" : {
197197
"type" : "attachment",
198198
"fields" : {
199-
"content" : {"index" : "no"},
200-
"title" : {"store" : "yes"},
201-
"date" : {"store" : "yes"},
199+
"content" : {"index" : true},
200+
"title" : {"store" : true},
201+
"date" : {"store" : true},
202202
"author" : {"analyzer" : "my_analyzer"},
203-
"keywords" : {"store" : "yes"},
204-
"content_type" : {"store" : "yes"},
205-
"content_length" : {"store" : "yes"},
206-
"language" : {"store" : "yes"}
203+
"keywords" : {"store" : true},
204+
"content_type" : {"store" : true},
205+
"content_length" : {"store" : true},
206+
"language" : {"store" : true}
207207
}
208208
}
209209
}

docs/reference/indices/analyze.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ experimental[The format of the additional detail information is experimental and
127127
GET _analyze
128128
{
129129
"tokenizer" : "standard",
130-
"token_filter" : ["snowball"],
130+
"filter" : ["snowball"],
131131
"text" : "detailed output",
132132
"explain" : true,
133133
"attributes" : ["keyword"] <1>

docs/reference/mapping/params/lat-lon.asciidoc

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
[[lat-lon]]
22
=== `lat_lon`
33

4+
deprecated[5.0.0, ????????]
5+
// https://github.com/elastic/elasticsearch/issues/19792
6+
47
<<geo-queries,Geo-queries>> are usually performed by plugging the value of
58
each <<geo-point,`geo_point`>> field into a formula to determine whether it
69
falls into the required area or not. Unlike most queries, the inverted index
@@ -10,7 +13,7 @@ Setting `lat_lon` to `true` causes the latitude and longitude values to be
1013
indexed as numeric fields (called `.lat` and `.lon`). These fields can be used
1114
by the <<query-dsl-geo-bounding-box-query,`geo_bounding_box`>> and
1215
<<query-dsl-geo-distance-query,`geo_distance`>> queries instead of
13-
performing in-memory calculations.
16+
performing in-memory calculations. So this mapping:
1417

1518
[source,js]
1619
--------------------------------------------------
@@ -27,8 +30,15 @@ PUT my_index
2730
}
2831
}
2932
}
33+
--------------------------------------------------
34+
// TEST[warning:geo_point lat_lon parameter is deprecated and will be removed in the next major release]
35+
<1> Setting `lat_lon` to true indexes the geo-point in the `location.lat` and `location.lon` fields.
36+
37+
Allows these actions:
3038

31-
PUT my_index/my_type/1
39+
[source,js]
40+
--------------------------------------------------
41+
PUT my_index/my_type/1?refresh
3242
{
3343
"location": {
3444
"lat": 41.12,
@@ -46,18 +56,17 @@ GET my_index/_search
4656
"lon": -71
4757
},
4858
"distance": "50km",
49-
"optimize_bbox": "indexed" <2>
59+
"optimize_bbox": "indexed" <1>
5060
}
5161
}
5262
}
5363
--------------------------------------------------
5464
// CONSOLE
55-
<1> Setting `lat_lon` to true indexes the geo-point in the `location.lat` and `location.lon` fields.
56-
<2> The `indexed` option tells the geo-distance query to use the inverted index instead of the in-memory calculation.
65+
// TEST[continued]
66+
<1> The `indexed` option tells the geo-distance query to use the inverted index instead of the in-memory calculation.
5767

5868
Whether the in-memory or indexed operation performs better depends both on
5969
your dataset and on the types of queries that you are running.
6070

6171
NOTE: The `lat_lon` option only makes sense for single-value `geo_point`
6272
fields. It will not work with arrays of geo-points.
63-

docs/reference/query-dsl/function-score-query.asciidoc

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ GET /_search
1818
{
1919
"query": {
2020
"function_score": {
21-
"query": {},
21+
"query": { "match_all": {} },
2222
"boost": "5",
2323
"random_score": {}, <1>
2424
"boost_mode":"multiply"
@@ -40,17 +40,17 @@ GET /_search
4040
{
4141
"query": {
4242
"function_score": {
43-
"query": {},
43+
"query": { "match_all": {} },
4444
"boost": "5", <1>
4545
"functions": [
4646
{
47-
"filter": {},
47+
"filter": { "match": { "test": "bar" } },
4848
"random_score": {}, <2>
4949
"weight": 23
5050
},
5151
{
52-
"filter": {},
53-
"weight": 42
52+
"filter": { "match": { "test": "cat" } },
53+
"weight": 42
5454
}
5555
],
5656
"max_boost": 42,
@@ -170,7 +170,7 @@ you wish to inhibit this, set `"boost_mode": "replace"`
170170
The `weight` score allows you to multiply the score by the provided
171171
`weight`. This can sometimes be desired since boost value set on
172172
specific queries gets normalized, while for this score function it does
173-
not. The number value is of type float.
173+
not. The number value is of type float.
174174

175175
[source,js]
176176
--------------------------------------------------

docs/reference/query-dsl/indices-query.asciidoc

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
[[query-dsl-indices-query]]
22
=== Indices Query
33

4+
deprecated[5.0.0, Search on the '_index' field instead]
5+
46
The `indices` query is useful in cases where a search is executed across
57
multiple indices. It allows to specify a list of index names and an inner
68
query that is only executed for indices matching names on that list.
@@ -20,7 +22,8 @@ GET /_search
2022
}
2123
}
2224
--------------------------------------------------
23-
// CONSOLE
25+
// CONSOLE
26+
// TEST[warning:indices query is deprecated. Instead search on the '_index' field]
2427

2528
You can use the `index` field to provide a single index.
2629

docs/reference/query-dsl/mlt-query.asciidoc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ set of documents. In order to do so, MLT selects a set of representative terms
66
of these input documents, forms a query using these terms, executes the query
77
and returns the results. The user controls the input documents, how the terms
88
should be selected and how the query is formed. `more_like_this` can be
9-
shortened to `mlt` deprecated[5.0.0,use `more_like_this` instead).
9+
shortened to `mlt` deprecated[5.0.0,use `more_like_this` instead].
1010

1111
The simplest use case consists of asking for documents that are similar to a
1212
provided piece of text. Here, we are asking for all movies that have some text
@@ -175,7 +175,7 @@ follows a similar syntax to the `per_field_analyzer` parameter of the
175175
Additionally, to provide documents not necessarily present in the index,
176176
<<docs-termvectors-artificial-doc,artificial documents>> are also supported.
177177

178-
`unlike`::
178+
`unlike`::
179179
The `unlike` parameter is used in conjunction with `like` in order not to
180180
select terms found in a chosen set of documents. In other words, we could ask
181181
for documents `like: "Apple"`, but `unlike: "cake crumble tree"`. The syntax

docs/reference/query-dsl/parent-id-query.asciidoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ GET /my_index/_search
5757
{
5858
"query": {
5959
"has_parent": {
60-
"type": "blog_post",
60+
"parent_type": "blog_post",
6161
"query": {
6262
"term": {
6363
"_id": "1"

0 commit comments

Comments
 (0)