2013-06-27 06:55:07 -04:00
|
|
|
Test Suite:
|
|
|
|
===========
|
|
|
|
|
2013-09-18 09:54:58 -04:00
|
|
|
A YAML test file consists of:
|
|
|
|
* an optional `setup` section, followed by
|
|
|
|
* one or more test sections
|
|
|
|
|
|
|
|
For instance:
|
|
|
|
|
|
|
|
setup:
|
|
|
|
- do: ....
|
|
|
|
- do: ....
|
|
|
|
|
|
|
|
---
|
|
|
|
"First test":
|
|
|
|
- do: ...
|
|
|
|
- match: ...
|
|
|
|
|
|
|
|
---
|
|
|
|
"Second test":
|
|
|
|
- do: ...
|
|
|
|
- match: ...
|
|
|
|
|
|
|
|
|
|
|
|
A `setup` section contains a list of commands to run before each test
|
|
|
|
section in order to setup the same environment for each test section.
|
|
|
|
|
|
|
|
A test section represents an independent test, containing multiple `do`
|
|
|
|
statements and assertions. The contents of a test section must be run in
|
|
|
|
order, but individual test sections may be run in any order, as follows:
|
|
|
|
|
|
|
|
1. run `setup` (if any)
|
|
|
|
2. reset the `response` var and the `stash` (see below)
|
|
|
|
2. run test contents
|
|
|
|
3. run teardown
|
|
|
|
|
|
|
|
The `teardown` should delete all indices and all templates.
|
2013-06-27 06:55:07 -04:00
|
|
|
|
|
|
|
Dot notation:
|
|
|
|
-------------
|
2013-06-28 11:42:00 -04:00
|
|
|
Dot notation is used for (1) method calls and (2) hierarchical data structures. For
|
2013-06-27 06:55:07 -04:00
|
|
|
instance, a method call like `cluster.health` would do the equivalent of:
|
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
client.cluster.health(...params...)
|
2013-06-27 06:55:07 -04:00
|
|
|
|
|
|
|
A test against `_tokens.1.token` would examine the `token` key, in the second element
|
|
|
|
of the `tokens` array, inside the `response` var (see below):
|
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
$val = $response->{tokens}[1]{token} # Perl syntax roolz!
|
2013-06-27 06:55:07 -04:00
|
|
|
|
|
|
|
If one of the levels (eg `tokens`) does not exist, it should return an undefined value.
|
2013-07-01 10:03:03 -04:00
|
|
|
If no field name is given (ie the empty string) then return the current
|
|
|
|
$val -- used for testing the whole response body.
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2013-07-21 18:51:35 -04:00
|
|
|
Use \. to specify paths that actually contain '.' in the key name, for example
|
|
|
|
in the `indices.get_settings` API.
|
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
Skipping tests:
|
|
|
|
---------------
|
2013-09-18 09:54:58 -04:00
|
|
|
If a test section should only be run on certain versions of Elasticsearch,
|
|
|
|
then the first entry in the section (after the title) should be called
|
|
|
|
`skip`, and should contain the range of versions to be
|
2013-07-23 14:24:46 -04:00
|
|
|
skipped, and the reason why the tests are skipped. For instance:
|
2013-06-28 11:42:00 -04:00
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
"Parent":
|
|
|
|
- skip:
|
2015-04-19 09:49:21 -04:00
|
|
|
version: "0.20.1 - 0.90.2"
|
2013-06-28 11:42:00 -04:00
|
|
|
reason: Delete ignores the parent param
|
|
|
|
|
|
|
|
- do:
|
|
|
|
... test definitions ...
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
|
2013-07-23 14:24:46 -04:00
|
|
|
All tests in the file following the skip statement should be skipped if:
|
|
|
|
`min <= current <= max`.
|
2013-06-28 11:42:00 -04:00
|
|
|
|
2015-04-19 09:49:21 -04:00
|
|
|
The `version` range can leave either bound empty, which means "open ended".
|
|
|
|
For instance:
|
|
|
|
....
|
|
|
|
"Parent":
|
|
|
|
- skip:
|
|
|
|
version: "1.0.0.Beta1 - "
|
|
|
|
reason: Delete ignores the parent param
|
2013-06-28 11:42:00 -04:00
|
|
|
|
2015-04-19 09:49:21 -04:00
|
|
|
- do:
|
|
|
|
... test definitions ...
|
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2014-01-31 08:55:30 -05:00
|
|
|
The skip section can also be used to list new features that need to be
|
|
|
|
supported in order to run a test. This way the up-to-date runners will
|
|
|
|
run the test, while the ones that don't support the feature yet can
|
|
|
|
temporarily skip it, and avoid having lots of test failures in the meantime.
|
2014-01-31 12:03:24 -05:00
|
|
|
Once all runners have implemented the feature, it can be declared supported
|
|
|
|
by default, thus the related skip sections can be removed from the tests.
|
2014-01-31 08:55:30 -05:00
|
|
|
|
|
|
|
....
|
|
|
|
"Parent":
|
|
|
|
- skip:
|
|
|
|
features: regex
|
|
|
|
|
|
|
|
- do:
|
|
|
|
... test definitions ...
|
|
|
|
....
|
|
|
|
|
|
|
|
The `features` field can either be a string or an array of strings.
|
|
|
|
The skip section requires to specify either a `version` or a `features` list.
|
|
|
|
|
2013-06-27 06:55:07 -04:00
|
|
|
Required operators:
|
|
|
|
-------------------
|
|
|
|
|
|
|
|
=== `do`
|
|
|
|
|
|
|
|
The `do` operator calls a method on the client. For instance:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
- do:
|
|
|
|
cluster.health:
|
|
|
|
level: shards
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
The response from the `do` operator should be stored in the `response` var, which
|
2013-06-27 06:55:07 -04:00
|
|
|
is reset (1) at the beginning of a file or (2) on the next `do`.
|
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
If the arguments to `do` include `catch`, then we are expecting an error, which should
|
2013-06-27 06:55:07 -04:00
|
|
|
be caught and tested. For instance:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
- do:
|
|
|
|
catch: missing
|
|
|
|
get:
|
|
|
|
index: test
|
|
|
|
type: test
|
|
|
|
id: 1
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
|
|
|
The argument to `catch` can be any of:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
[horizontal]
|
2013-06-28 11:42:00 -04:00
|
|
|
`missing`:: a 404 response from ES
|
2013-07-23 13:20:40 -04:00
|
|
|
`conflict`:: a 409 response from ES
|
|
|
|
`request`:: a generic error response from ES
|
2013-06-27 06:55:07 -04:00
|
|
|
`param`:: a client-side error indicating an unknown parameter has been passed
|
|
|
|
to the method
|
|
|
|
`/foo bar/`:: the text of the error message matches this regular expression
|
|
|
|
|
|
|
|
If `catch` is specified, then the `response` var must be cleared, and the test
|
|
|
|
should fail if no error is thrown.
|
|
|
|
|
|
|
|
=== `set`
|
|
|
|
|
|
|
|
For some tests, it is necessary to extract a value from the previous `response`, in
|
2013-06-28 11:42:00 -04:00
|
|
|
order to reuse it in a subsequent `do` and other tests. For instance, when
|
2013-06-27 06:55:07 -04:00
|
|
|
testing indexing a document without a specified ID:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
- do:
|
|
|
|
index:
|
|
|
|
index: test
|
|
|
|
type: test
|
|
|
|
- set: { _id: id } # stash the value of `response._id` as `id`
|
|
|
|
- do:
|
|
|
|
get:
|
|
|
|
index: test
|
|
|
|
type: test
|
|
|
|
id: $id # replace `$id` with the stashed value
|
2013-06-27 06:55:07 -04:00
|
|
|
- match: { _id: $id } # the returned `response._id` matches the stashed `id`
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2014-01-31 05:49:41 -05:00
|
|
|
The last response obtained gets always stashed automatically as a string, called `body`.
|
|
|
|
This is useful when needing to test apis that return text rather than json (e.g. cat api),
|
|
|
|
as it allows to treat the whole body as an ordinary string field.
|
|
|
|
|
2015-02-02 10:12:16 -05:00
|
|
|
Stashed values can be used in property names, eg:
|
|
|
|
|
|
|
|
....
|
|
|
|
- do:
|
|
|
|
cluster.state: {}
|
|
|
|
|
|
|
|
- set: {master_node: master}
|
|
|
|
|
|
|
|
- do:
|
|
|
|
nodes.info:
|
|
|
|
metric: [ transport ]
|
|
|
|
|
|
|
|
- is_true: nodes.$master.transport.profiles
|
|
|
|
....
|
|
|
|
|
|
|
|
|
2014-01-31 05:49:41 -05:00
|
|
|
Note that not only expected values can be retrieved from the stashed values (as in the
|
|
|
|
example above), but the same goes for actual values:
|
|
|
|
|
|
|
|
....
|
2015-02-02 10:12:16 -05:00
|
|
|
- match: { $body: /^.+$/ } # the returned `body` matches the provided regex if the body is text
|
|
|
|
- match: { $body: {} } # the returned `body` matches the JSON object if the body is JSON
|
2014-01-31 05:49:41 -05:00
|
|
|
....
|
|
|
|
|
2013-06-27 06:55:07 -04:00
|
|
|
The stash should be reset at the beginning of each test file.
|
|
|
|
|
2013-07-01 09:58:23 -04:00
|
|
|
=== `is_true`
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
The specified key exists and has a true value (ie not `0`, `false`, `undefined`, `null`
|
2013-06-27 06:55:07 -04:00
|
|
|
or the empty string), eg:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-07-01 09:58:23 -04:00
|
|
|
- is_true: fields._parent # the _parent key exists in the fields hash and is "true"
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2013-07-01 09:58:23 -04:00
|
|
|
=== `is_false`
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
The specified key doesn't exist or has a false value (ie `0`, `false`, `undefined`,
|
2013-06-27 06:55:07 -04:00
|
|
|
`null` or the empty string), eg:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
|
|
|
- is_false: fields._source # the _source key doesn't exist in the fields hash or is "false"
|
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
|
|
|
=== `match`
|
|
|
|
|
2013-06-28 11:42:00 -04:00
|
|
|
Used to compare two variables (could be scalars, arrays or hashes). The two variables
|
2013-06-27 06:55:07 -04:00
|
|
|
should be identical, eg:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
|
|
|
- match: { _source: { foo: bar }}
|
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2014-01-31 05:49:41 -05:00
|
|
|
Supports also regular expressions with flag X for more readability (accepts whitespaces and comments):
|
|
|
|
|
|
|
|
....
|
|
|
|
- match:
|
|
|
|
$body: >
|
|
|
|
/^ epoch \s+ timestamp \s+ count \s+ \n
|
|
|
|
\d+ \s+ \d{2}:\d{2}:\d{2} \s+ \d+ \s+ \n $/
|
|
|
|
....
|
|
|
|
|
2013-06-27 06:55:07 -04:00
|
|
|
=== `lt` and `gt`
|
|
|
|
|
|
|
|
Compares two numeric values, eg:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
- lt: { fields._ttl: 10000 } # the `_ttl` value is less than 10,000
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|
2014-03-06 19:02:39 -05:00
|
|
|
=== `lte` and `gte`
|
|
|
|
|
|
|
|
Compares two numeric values, eg:
|
|
|
|
|
|
|
|
....
|
|
|
|
- lte: { fields._ttl: 10000 } # the `_ttl` value is less than or equal to 10,000
|
|
|
|
....
|
|
|
|
|
2013-06-27 06:55:07 -04:00
|
|
|
=== `length`
|
|
|
|
|
|
|
|
This depends on the datatype of the value being examined, eg:
|
|
|
|
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-28 11:42:00 -04:00
|
|
|
- length: { _id: 22 } # the `_id` string is 22 chars long
|
|
|
|
- length: { _tokens: 3 } # the `_tokens` array has 3 elements
|
|
|
|
- length: { _source: 5 } # the `_source` hash has 5 keys
|
2013-07-02 05:28:50 -04:00
|
|
|
....
|
2013-06-27 06:55:07 -04:00
|
|
|
|