Skip to content

Commit 0688fe5

Browse files
darachLicenser
authored andcommitted
Resolve flaky test harness tests in command and integration suites
Signed-off-by: Darach Ennis <darach@gmail.com>
1 parent c0b8360 commit 0688fe5

File tree

4 files changed

+141
-3
lines changed

4 files changed

+141
-3
lines changed

tremor-cli/src/test/assert.rs

+77
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ pub(crate) struct FileBasedAssert {
104104
pub(crate) contains: Option<Vec<String>>,
105105
pub(crate) doesnt_contain: Option<Vec<String>>,
106106
pub(crate) equals_file: Option<String>,
107+
pub(crate) is_empty: Option<bool>,
108+
pub(crate) is_not_empty: Option<bool>,
107109
}
108110

109111
pub(crate) type Asserts = Vec<FileBasedAssert>;
@@ -329,6 +331,7 @@ fn process_equals_file(
329331
})
330332
}
331333

334+
#[allow(clippy::too_many_lines)]
332335
pub(crate) fn process_filebased_asserts(
333336
prefix: &str,
334337
stdout_path: &Path,
@@ -345,6 +348,8 @@ pub(crate) fn process_filebased_asserts(
345348
contains: None,
346349
doesnt_contain: None,
347350
equals_file: None,
351+
is_empty: None,
352+
is_not_empty: None,
348353
..
349354
} => {
350355
stats.skip();
@@ -355,6 +360,8 @@ pub(crate) fn process_filebased_asserts(
355360
contains,
356361
doesnt_contain,
357362
equals_file,
363+
is_empty,
364+
is_not_empty,
358365
..
359366
} => {
360367
let file = match source {
@@ -394,9 +401,79 @@ pub(crate) fn process_filebased_asserts(
394401
&mut counter,
395402
)?);
396403
}
404+
405+
if let Some(is_empty) = is_empty {
406+
stats.assert();
407+
counter += 1;
408+
let condition = (std::fs::metadata(&file)?.len() == 0) == *is_empty;
409+
stats.report(condition, &file);
410+
status::assert_has(
411+
prefix,
412+
&format!("Assert {counter}"),
413+
&format!(" File `{}` is empty", &file),
414+
None,
415+
condition,
416+
)?;
417+
elements.push(report::TestElement {
418+
description: format!("File `{file}` is empty"),
419+
info: None,
420+
hidden: false,
421+
keyword: report::KeywordKind::Predicate,
422+
result: report::ResultKind {
423+
status: if condition {
424+
report::StatusKind::Passed
425+
} else {
426+
report::StatusKind::Failed
427+
},
428+
duration: 0,
429+
},
430+
});
431+
}
432+
433+
if let Some(is_not_empty) = is_not_empty {
434+
stats.assert();
435+
counter += 1;
436+
let condition = (std::fs::metadata(&file)?.len() != 0) == *is_not_empty;
437+
stats.report(condition, &file);
438+
status::assert_has(
439+
prefix,
440+
&format!("Assert {counter}"),
441+
&format!(" File `{}` is not empty", &file),
442+
None,
443+
condition,
444+
)?;
445+
elements.push(report::TestElement {
446+
description: format!("File `{file}` is not empty"),
447+
info: None,
448+
hidden: false,
449+
keyword: report::KeywordKind::Predicate,
450+
result: report::ResultKind {
451+
status: if condition {
452+
report::StatusKind::Passed
453+
} else {
454+
report::StatusKind::Failed
455+
},
456+
duration: 0,
457+
},
458+
});
459+
}
397460
}
398461
}
399462
}
400463

401464
Ok((stats, elements))
402465
}
466+
467+
#[cfg(test)]
468+
mod test {
469+
use super::*;
470+
471+
#[test]
472+
fn test_contains() -> Result<()> {
473+
let file = "src/test/assert/contains.txt";
474+
let contains = vec!["snot".to_string(), "badger".to_string()];
475+
let result = file_contains(file, &contains, None)?;
476+
assert!(result);
477+
Ok(())
478+
}
479+
}
+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
snot
2+
badger

tremor-cli/tests/cli/command.yml

+11
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,17 @@ suites:
199199
- "Error:"
200200
- "3 | emit event.baz"
201201
- " | ^^^ Trying to access a non existing event key `baz`\n\n"
202+
- name: setup for tremor new creates
203+
command: rm -rf test
204+
tags:
205+
- run
206+
- new
207+
status: 0
208+
expects:
209+
- source: stdout
210+
is_empty: true
211+
- source: stderr
212+
is_empty: true
202213
- name: tremor new creates
203214
command: tremor new test
204215
tags:

tremor-cli/tests/integration/elastic-verify-gd/assert.yaml

+51-3
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,58 @@ status: 0
22
name: elastic-verify-gd
33
asserts:
44
- source: err.log
5-
equals_file: expected_err.json
5+
contains:
6+
- |
7+
{"action":"index","correlation":"tons","index":"my_little_index","payload":{"action":null,"cause":"this one has a different type underneath the same key and thus will fail elastic","snot":"tons","tremor":12},"success":false}
8+
- source: err.log
9+
contains:
10+
- |
11+
{"action":"index","correlation":"baz","index":"my_little_index","payload":{"action":null,"cause":"this one has a different type underneath the same key and thus will fail elastic","snot":"baz","tremor":12},"success":false}
12+
- source: ok.log
13+
contains:
14+
- |
15+
{"action":"index","correlation":"badger","index":"my_little_index","payload":{"action":null,"snot":"badger"},"success":true}
16+
- source: ok.log
17+
contains:
18+
- |
19+
{"action":"index","correlation":"foo","index":"my_little_index","payload":{"action":null,"snot":"foo"},"success":true}
20+
- source: ok.log
21+
contains:
22+
- |
23+
{"action":"index","correlation":"racoon","index":"my_little_index","payload":{"action":null,"snot":"racoon","tremor":[true,true,true,false]},"success":true}
24+
- source: ok.log
25+
contains:
26+
- |
27+
{"action":"index","correlation":"bar","index":"my_little_index","payload":{"action":null,"snot":"bar","tremor":[true,true,true,false]},"success":true}
28+
- source: ok.log
29+
contains:
30+
- |
31+
{"action":"delete","correlation":"badger","index":"my_little_index","payload":{"action":"delete","doc_id":"badger","snot":"badger"},"success":true}
32+
- source: ok.log
33+
contains:
34+
- |
35+
{"action":"delete","correlation":"fop","index":"my_little_index","payload":{"action":"delete","doc_id":"badger","snot":"fop"},"success":true}
36+
- source: ok.log
37+
contains:
38+
- |
39+
{"action":"index","correlation":"badger","index":"my_little_index","payload":{"action":"index","doc_id":"badger","snot":"badger"},"success":true}
40+
- source: ok.log
41+
contains:
42+
- |
43+
{"action":"index","correlation":"snoop","index":"my_little_index","payload":{"action":"index","doc_id":"badger","snot":"snoop"},"success":true}
44+
- source: ok.log
45+
contains:
46+
- |
47+
{"action":"update","correlation":"badger","index":"my_little_index","payload":{"action":"update","doc_id":"badger","snot":"badger"},"success":true}
648
- source: ok.log
7-
equals_file: expected_ok.json
49+
contains:
50+
- |
51+
{"action":"update","correlation":"dogg","index":"my_little_index","payload":{"action":"update","doc_id":"badger","snot":"dogg"},"success":true}
52+
- source: ok.log
53+
contains:
54+
- |
55+
{"action":"index","correlation":"badger","index":"my_little_index","payload":{"action":null,"snot":"badger"},"success":true}
856
- source: fg.err.log
957
contains:
1058
- |
11-
All required CB events received.
59+
All required CB events received.

0 commit comments

Comments
 (0)