Skip to content

Commit

Permalink
tests: added new steps to test new matching behavior (exact_match)
Browse files Browse the repository at this point in the history
Signed-off-by: lbrady <[email protected]>
  • Loading branch information
liambrady committed Jul 17, 2023
1 parent 2fa7bd4 commit 4472bda
Show file tree
Hide file tree
Showing 2 changed files with 205 additions and 0 deletions.
20 changes: 20 additions & 0 deletions tests/mutest/mutest_matchwait.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,16 @@
0.25,
expect_fail=False,
)
wait_step(
"r1",
'sleep .5 && echo -e "exact\nmatch"',
"exact\nmatch",
"Look for exact match",
1,
0.25,
expect_fail=False,
exact_match=True,
)

section("Test negative (expect_fail) match_step calls")

Expand Down Expand Up @@ -73,3 +83,13 @@
interval=0.25,
expect_fail=True,
)
wait_step(
"host1",
'sleep .5 && echo -e "exact\nmatch"',
"not exact",
"Look for no exact match",
1,
0.25,
expect_fail=True,
exact_match=True,
)
185 changes: 185 additions & 0 deletions tests/mutest/mutest_matchwait_json.py
Original file line number Diff line number Diff line change
Expand Up @@ -130,3 +130,188 @@
wait_step_json(
"r1", """echo 'not json'""", '{ "name": "other" }', "Look for chopps", 1, 0.25, True
)

section("Test json exact matching (exact_match == True)")

match_step_json(
"r1",
"""echo '[{ "name": "other" }]'""",
'[{ "name": "chopps"}]',
"Look for no chopps",
expect_fail=True,
exact_match=True,
)
wait_step_json(
"r1",
"""echo '[{ "name": "other" }]'""",
'[{ "name": "chopps"}]',
"Look for no chopps",
1,
expect_fail=True,
exact_match=True,
)
match_step_json(
"r1",
"""echo '[{ "name": "chopps" }]'""",
'[{ "name": "chopps"}]',
"Look for chopps",
exact_match=True,
)
wait_step_json(
"r1",
"""echo '[{ "name": "chopps" }]'""",
'[{ "name": "chopps"}]',
"Look for chopps",
1,
exact_match=True,
)

section("Test json matching rules (exact_match == False)")

json1 = '{"foo":"foo"}'
json2 = '{"foo":"foo", "bar":"bar"}'

_, ret = match_step_json(
"r1",
f"echo '{json2}'",
json1,
"Data within output object present",
)
test_step(
ret == {'foo': 'foo', 'bar': 'bar'},
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json1}'",
json2,
"Data within output object not present",
expect_fail=True,
)
test_step(
ret == {'dictionary_item_removed': ["root['bar']"]},
" Correct return value",
)
# The return type should be a mix of dicts and lists. Not custom DeepDiff types!
test_step(
type(ret['dictionary_item_removed']) is list,
" Correct return value type",
)

json1 = '[{"foo":"foo"}]'
json2 = '[{"foo":"foo"}, {"bar":"bar"}]'
json3 = '[{"bar":"bar"}, {"foo":"foo"}]'

_, ret = match_step_json(
"r1",
f"echo '{json2}'",
json1,
"Objects within output array present",
)
test_step(
ret == [{'foo': 'foo'}, {'bar': 'bar'}],
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json1}'",
json2,
"Objects within output array not present",
expect_fail=True,
)
test_step(
ret == {'iterable_item_removed': {'root[1]': {'bar': 'bar'}}},
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json2}'",
json3,
"Both objects within output array present",
)
test_step(
ret == [{'foo': 'foo'}, {'bar': 'bar'}],
" Correct return value",
)

json1 = '["foo"]'
json2 = '["foo", "bar"]'
json3 = '["bar", "foo"]'

_, ret = match_step_json(
"r1",
f"echo '{json2}'",
json1,
"Data in different arrays don't match",
expect_fail=True,
)
test_step(
ret == {'iterable_item_added': {'root[1]': 'bar'}},
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json1}'",
json2,
"Data in different arrays don't match",
expect_fail=True,
)
test_step(
ret == {'iterable_item_removed': {'root[1]': 'bar'}},
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json2}'",
json3,
"Data in equivalent arrays match"
)
test_step(
ret == ['foo', 'bar'],
" Correct return value",
)

json1 = '{"level1": ["level2", {"level3": ["level4"]}]}'
json2 = '{"level1": ["level2", {"level3": ["level4"], "l3": "l4"}]}'
json3 = '{"level1": ["level2", {"level3": ["level4", {"level5": "l6"}]}]}'
json4 = '{"level1": ["level2", {"level3": ["level4", "l4"]}]}'

_, ret = match_step_json(
"r1",
f"echo '{json2}'",
json1,
"Data within output object present (nested)",
)
test_step(
ret == {'level1': ['level2', {'level3': ['level4'], 'l3': 'l4'}]},
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json3}'",
json1,
"Objects within output array present (nested)",
)
test_step(
ret == {'level1': ['level2', {'level3': ['level4', {'level5': 'l6'}]}]},
" Correct return value",
)
_, ret = match_step_json(
"r1",
f"echo '{json4}'",
json1,
"Data in different arrays don't match (nested)",
expect_fail=True
)
test_step(
ret == {'iterable_item_added': {"root['level1'][1]['level3'][1]": 'l4'}},
" Correct return value",
)
match_step_json(
"r1",
"""echo '{}'""",
'{ "name": "chopps"}',
"empty json output doesn't match",
expect_fail=True,
exact_match=False,
)

0 comments on commit 4472bda

Please sign in to comment.