Skip to content

Commit 7f19e6b

Browse files
committed
[DOCS] Add README to Yaml Runner
1 parent fa2631b commit 7f19e6b

File tree

1 file changed

+61
-0
lines changed

1 file changed

+61
-0
lines changed

elasticsearch-api/spec/README.md

Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
# Rest API YAML Spec Runner
2+
3+
The file that traverses the yaml files and loads a **TestFile** object per each of them:
4+
`elasticsearch-api/spec/elasticsearch/api/rest_api_yaml_spec.rb`
5+
6+
You can use the SINGLE_TEST env variable to run just one test, or add code like this on the first line of the tests.each block:
7+
```ruby
8+
next unless file =~ /indices.put_mapping\/all_path_options_with_types.yml/
9+
```
10+
11+
#### TestFile object
12+
Class representing a single test file. Contains setup, teardown and tests.
13+
`../api-spec-testing/test_file.rb`
14+
15+
#### Test object
16+
Every single test in the test file is represented in the Test object.
17+
`../api-spec-testing/test_file/test.rb`
18+
19+
#### TaskGroup objects
20+
21+
Tests are ordered in task groups, an array of TaskGroup objects.
22+
`../api-spec-testing/test_file/task_group.rb`
23+
24+
Task Groups are a representation of a block of actions consisting of 'do' actions and their verifications. e.g.:
25+
```yaml
26+
- do:
27+
index:
28+
index: test-index
29+
id: 1
30+
body: { foo: bar }
31+
32+
- match: { _index: test-index }
33+
- match: { _id: "1"}
34+
- match: { _version: 1}
35+
```
36+
37+
**Before** each test, the spec runner runs `clear_data` on the test_file. This clears indices, index templates, snapshots and repositories. For xpack it also clears roles, users, privileges, datafeeds, ml_jobs and more.
38+
39+
**After** each test, it runs the test file teardown and `clear_data` again.
40+
41+
For each TaskGroup, it sees what's in the task group definition and runs an expectation test.
42+
43+
# Rest YAML tests Helper
44+
45+
`elasticsearch-api/spec/rest_yaml_tests_helper.rb`
46+
47+
- `ADMIN_CLIENT` is defined here.
48+
- `SINGLE_TEST` is defined here.
49+
- Skipped tests are listed here
50+
51+
# Spec Helper
52+
53+
- `DEFAULT_CLIENT` is defined here
54+
55+
# RSpec Matchers
56+
57+
The tests use custom [RSpec Matchers](https://www.rubydoc.info/gems/rspec-expectations/RSpec/Matchers) defined in `api-spec-testing/rspec_matchers.rb`.
58+
59+
# Enable Logging
60+
61+
To enable logging, set the environment `QUIET` to false before running the tests. In CI, this is located in the [Dockerfile](https://github.com/elastic/elasticsearch-ruby/blob/master/.ci/Dockerfile). The environment variable is evaluated in the Rest YAML tests Helper file.

0 commit comments

Comments
 (0)