Skip to content

Commit 840b768

Browse files
committed
Docs: Remove duplicate test setup
The range docs had an introductory section that described how to set up and index *and* a test setup section in `docs/build.gradle` that duplicated that section. This is bad because these section can (and do) drift from one another. This change removes the setup in build.gradle and marks the introductor snippet with `// TESTSETUP` so it is used on all the snippets.
1 parent 7728446 commit 840b768

File tree

3 files changed

+12
-33
lines changed

3 files changed

+12
-33
lines changed

docs/README.asciidoc

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,8 @@ CONSOLE" and "COPY AS CURL" in the documentation and are automatically tested
88
by the command `gradle :docs:check`. To test just the docs from a single page,
99
use e.g. `gradle :docs:check -Dtests.method=*rollover*`.
1010

11-
NOTE: If you have an elasticsearch-extra folder alongside your elasticsearch
12-
folder, you must temporarily rename it when you are testing 6.3 or later branches.
11+
NOTE: If you have an elasticsearch-extra folder alongside your elasticsearch
12+
folder, you must temporarily rename it when you are testing 6.3 or later branches.
1313

1414
By default each `// CONSOLE` snippet runs as its own isolated test. You can
1515
manipulate the test execution in the following ways:
@@ -37,7 +37,8 @@ for its modifiers:
3737
reason why the test shouldn't be run.
3838
* `// TEST[setup:name]`: Run some setup code before running the snippet. This
3939
is useful for creating and populating indexes used in the snippet. The setup
40-
code is defined in `docs/build.gradle`.
40+
code is defined in `docs/build.gradle`. See `// TESTSETUP` below for a
41+
similar feature.
4142
* `// TEST[warning:some warning]`: Expect the response to include a `Warning`
4243
header. If the response doesn't include a `Warning` header with the exact
4344
text then the test fails. If the response includes `Warning` headers that
@@ -69,7 +70,9 @@ for its modifiers:
6970
a test that runs the setup snippet first. See the "painless" docs for a file
7071
that puts this to good use. This is fairly similar to `// TEST[setup:name]`
7172
but rather than the setup defined in `docs/build.gradle` the setup is defined
72-
right in the documentation file.
73+
right in the documentation file. In general, we should prefer `// TESTSETUP`
74+
over `// TEST[setup:name]` because it makes it more clear what steps have to
75+
be taken before the examples will work.
7376
7477
In addition to the standard CONSOLE syntax these snippets can contain blocks
7578
of yaml surrounded by markers like this:

docs/build.gradle

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -220,31 +220,6 @@ buildRestTests.doFirst {
220220
buildRestTests.setups['bank'].replace('#bank_data#', accounts)
221221
}
222222

223-
buildRestTests.setups['range_index'] = '''
224-
- do :
225-
indices.create:
226-
index: range_index
227-
body:
228-
settings:
229-
number_of_shards: 2
230-
number_of_replicas: 1
231-
mappings:
232-
_doc:
233-
properties:
234-
expected_attendees:
235-
type: integer_range
236-
time_frame:
237-
type: date_range
238-
format: yyyy-MM-dd HH:mm:ss||yyyy-MM-dd||epoch_millis
239-
- do:
240-
bulk:
241-
index: range_index
242-
type: _doc
243-
refresh: true
244-
body: |
245-
{"index":{"_id": 1}}
246-
{"expected_attendees": {"gte": 10, "lte": 20}, "time_frame": {"gte": "2015-10-31 12:00:00", "lte": "2015-11-01"}}'''
247-
248223
// Used by index boost doc
249224
buildRestTests.setups['index_boost'] = '''
250225
- do:

docs/reference/mapping/types/range.asciidoc

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ Below is an example of configuring a mapping with various range fields followed
1818
--------------------------------------------------
1919
PUT range_index
2020
{
21+
"settings": {
22+
"number_of_shards": 2
23+
},
2124
"mappings": {
2225
"_doc": {
2326
"properties": {
@@ -33,7 +36,7 @@ PUT range_index
3336
}
3437
}
3538
36-
PUT range_index/_doc/1
39+
PUT range_index/_doc/1?refresh
3740
{
3841
"expected_attendees" : { <2>
3942
"gte" : 10,
@@ -46,6 +49,7 @@ PUT range_index/_doc/1
4649
}
4750
--------------------------------------------------
4851
//CONSOLE
52+
// TESTSETUP
4953

5054
<1> `date_range` types accept the same field parameters defined by the <<date, `date`>> type.
5155
<2> Example indexing a meeting with 10 to 20 attendees.
@@ -68,7 +72,6 @@ GET range_index/_search
6872
}
6973
--------------------------------------------------
7074
// CONSOLE
71-
// TEST[setup:range_index]
7275

7376
The result produced by the above query.
7477

@@ -125,7 +128,6 @@ GET range_index/_search
125128
}
126129
--------------------------------------------------
127130
// CONSOLE
128-
// TEST[setup:range_index]
129131

130132
<1> Range queries work the same as described in <<query-dsl-range-query, range query>>.
131133
<2> Range queries over range <<mapping-types, fields>> support a `relation` parameter which can be one of `WITHIN`, `CONTAINS`,
@@ -191,7 +193,6 @@ PUT range_index/_doc/2
191193
}
192194
--------------------------------------------------
193195
// CONSOLE
194-
// TEST[setup:range_index]
195196

196197
[[range-params]]
197198
==== Parameters for range fields

0 commit comments

Comments
 (0)