Skip to content

Commit ac43b52

Browse files
committed
[yaml-tests] Update test suite names, fix delete_indices, improve error reporting
1 parent cacc3cd commit ac43b52

File tree

8 files changed

+88
-26
lines changed

8 files changed

+88
-26
lines changed

CONTRIBUTING.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,10 +79,10 @@ The `Elasticsearch` category of steps are specifically defined for this project
7979

8080
- `STACK_VERSION`: Elasticsearch version like `7.9.0` or can be
8181
a snapshot release like `7.x-SNAPSHOT`
82-
- `TEST_SUITE`: Elasticsearch distribution of `oss` or `xpack`
82+
- `TEST_SUITE`: Elasticsearch distribution of `free` or `platinum`
8383

8484
```sh
85-
cargo make test-yaml --env STACK_VERSION=7.9.0 --env TEST_SUITE=oss
85+
cargo make test-yaml --env STACK_VERSION=7.9.0 --env TEST_SUITE=free
8686
```
8787

8888
### Packages
@@ -198,4 +198,4 @@ if wishing to use the MSVC debugger with Rust in VS code, which may be preferred
198198
}
199199
```
200200

201-
3. Add `"debug.allowBreakpointsEverywhere": true` to VS code settings.json
201+
3. Add `"debug.allowBreakpointsEverywhere": true` to VS code settings.json

Makefile.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ default_to_workspace = false
33

44
[env]
55
# Determines the version of Elasticsearch docker container used
6-
STACK_VERSION = "8.0.0-SNAPSHOT"
6+
STACK_VERSION = { value = "8.0.0-SNAPSHOT", condition = { env_not_set = ["STACK_VERSION"] }}
77
# Determines the distribution of docker container used. Either platinum or free
8-
TEST_SUITE = "platinum"
8+
TEST_SUITE = { value = "free", condition = { env_not_set = ["TEST_SUITE"] }}
99
# Set publish flags to dry-run by default, to force user to explicitly define for publishing
1010
CARGO_MAKE_CARGO_PUBLISH_FLAGS = "--dry-run"
1111

yaml_test_runner/src/generator.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ use yaml_rust::{Yaml, YamlLoader};
3636
/// The test suite to compile
3737
#[derive(Debug, PartialEq)]
3838
pub enum TestSuite {
39-
Oss,
39+
Free,
4040
XPack,
4141
}
4242

@@ -121,7 +121,7 @@ impl<'a> YamlTests<'a> {
121121
let (setup_fn, setup_call) = Self::generate_fixture(&self.setup);
122122
let (teardown_fn, teardown_call) = Self::generate_fixture(&self.teardown);
123123
let general_setup_call = match self.suite {
124-
TestSuite::Oss => quote!(client::general_oss_setup().await?;),
124+
TestSuite::Free => quote!(client::general_oss_setup().await?;),
125125
TestSuite::XPack => quote!(client::general_xpack_setup().await?;),
126126
};
127127

@@ -406,9 +406,9 @@ pub fn generate_tests_from_yaml(
406406
}
407407

408408
match top_dir.as_str() {
409-
"oss" => TestSuite::Oss,
409+
"free" => TestSuite::Free,
410410
"xpack" => TestSuite::XPack,
411-
_ => panic!("Unknown test suite"),
411+
_ => panic!("Unknown test suite {:?}", path),
412412
}
413413
};
414414

yaml_test_runner/src/github.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ pub fn download_test_suites(branch: &str, download_dir: &PathBuf) -> Result<(),
6767
let file = entry?;
6868
let path = file.path()?;
6969
if oss_test.is_match(&path) {
70-
write_test_file(download_dir, "oss", file)?;
70+
write_test_file(download_dir, "free", file)?;
7171
} else if xpack_test.is_match(&path) {
7272
write_test_file(download_dir, "xpack", file)?;
7373
}

yaml_test_runner/src/main.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,14 @@ fn branch_suite_and_version_from_elasticsearch(
148148
.danger_accept_invalid_certs(true)
149149
.build()?;
150150

151+
let suite = match std::env::var("TEST_SUITE") {
152+
Err(_) => panic!("Env var TEST_SUITE is not defined"),
153+
Ok(ref s) if s == "free" => TestSuite::Free,
154+
_ => TestSuite::XPack,
155+
};
151156
let mut response = client.get(url).send()?;
152157
let json: Value = response.json()?;
153158
let branch = json["version"]["build_hash"].as_str().unwrap().to_string();
154-
let suite = match json["version"]["build_flavor"].as_str().unwrap() {
155-
"oss" => TestSuite::Oss,
156-
_ => TestSuite::XPack,
157-
};
158159

159160
// any prerelease part needs to be trimmed because the semver crate only allows
160161
// a version with a prerelease to match against predicates, if at least one predicate

yaml_test_runner/src/step/do.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ impl ToTokens for Catch {
3838
fn to_tokens(&self, tokens: &mut Tokens) {
3939
fn http_status_code(status_code: u16, tokens: &mut Tokens) {
4040
tokens.append(quote! {
41-
assert_status_code!(response.status_code(), #status_code);
41+
assert_response_status_code!(response, #status_code);
4242
});
4343
}
4444

yaml_test_runner/tests/common/client.rs

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,35 @@ async fn wait_for_yellow_status(client: &Elasticsearch) -> Result<(), Error> {
247247
}
248248

249249
async fn delete_indices(client: &Elasticsearch) -> Result<(), Error> {
250+
// Hand-crafted request as the indices.delete_data_stream spec doesn't yet have the
251+
// "expand_wildcards" parameter that is needed to delete ILM data streams
252+
//
253+
// Not deleting data streams yields errors like this when trying to delete hidden indices:
254+
// {
255+
// "type":"illegal_argument_exception"
256+
// "reason":"index [.ds-ilm-history-5-2021.02.14-000001] is the write index for data
257+
// stream [ilm-history-5] and cannot be deleted"
258+
// }
259+
//
260+
// Quoting the docs:
261+
// You cannot delete the current write index of a data stream. To delete the index,
262+
// you must roll over the data stream so a new write index is created. You can then use
263+
// the delete index API to delete the previous write index.
264+
//
265+
let delete_response = client
266+
.transport()
267+
.send(
268+
Method::Delete,
269+
"/_data_stream/*",
270+
elasticsearch::http::headers::HeaderMap::new(),
271+
Some(&[("expand_wildcards", "hidden")]),
272+
None::<()>, // body
273+
None, // timeout
274+
)
275+
.await?;
276+
277+
assert_response_success!(delete_response);
278+
250279
let delete_response = client
251280
.indices()
252281
.delete(IndicesDeleteParts::Index(&["*"]))

yaml_test_runner/tests/common/macros.rs

Lines changed: 43 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,27 +17,59 @@
1717
* under the License.
1818
*/
1919
/// Asserts that a [Response] has a status code >=200 and <300
20+
2021
#[macro_export]
2122
macro_rules! assert_response_success {
2223
($response:ident) => {{
23-
assert!(
24-
$response.status_code().is_success(),
25-
"expected response to be successful but was {}",
26-
$response.status_code().as_u16()
27-
);
24+
let status_code = $response.status_code();
25+
if !status_code.is_success() {
26+
let text = $response
27+
.text()
28+
.await
29+
.unwrap_or("[no response]".to_string());
30+
panic!(
31+
"expected response to be successful but was {}. Response: {}",
32+
status_code, text
33+
);
34+
}
2835
}};
2936
}
3037

3138
/// Asserts that a [Response] has a status code >=200 and <300 or matches the passed status
3239
#[macro_export]
3340
macro_rules! assert_response_success_or {
3441
($response:ident, $status:expr) => {{
35-
assert!(
36-
$response.status_code().is_success() || $response.status_code().as_u16() == $status,
37-
"expected response to be successful or {} but was {}",
38-
$status,
39-
$response.status_code().as_u16()
40-
);
42+
let status_code = $response.status_code();
43+
if !status_code.is_success() && status_code.as_u16() != $status {
44+
let text = $response
45+
.text()
46+
.await
47+
.unwrap_or("[no response]".to_string());
48+
panic!(
49+
"expected response to be successful or {} but was {}",
50+
$status,
51+
status_code.as_u16()
52+
);
53+
}
54+
}};
55+
}
56+
57+
/// Asserts that a [Response] has a status that matches the passed status
58+
#[macro_export]
59+
macro_rules! assert_response_status_code {
60+
($response:ident, $status:expr) => {{
61+
let status_code = $response.status_code();
62+
if status_code.as_u16() != $status {
63+
let text = $response
64+
.text()
65+
.await
66+
.unwrap_or("[no response]".to_string());
67+
panic!(
68+
"expected response to be {} but was {}",
69+
$status,
70+
status_code.as_u16()
71+
);
72+
}
4173
}};
4274
}
4375

0 commit comments

Comments
 (0)