Skip to content

Commit

Permalink
rename the second expect field & add changelog
Browse files Browse the repository at this point in the history
Signed-off-by: saravanan palanisamy <[email protected]>
  • Loading branch information
saravanan30erd committed Oct 21, 2020
1 parent 5e7ce91 commit e196962
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 15 deletions.
25 changes: 19 additions & 6 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

[Unreleased]: https://github.com/chaostoolkit/chaostoolkit-lib/compare/1.15.0...HEAD

### Added

- New field `expect_one_of` in `jsonpath` tolerance. Sometimes the json payload
values will be dynamic, e.g. field `status` in response payload may provide
any values(either `ok` or `error` or `info`). Using `expect` field, we can
mention only one value as expected value but sometimes steady state can be
met with one or more values. e.g. you want to define two values either `ok` or
`info` as expected value. In these cases, you can use both `expect` and
`expect_one_of` to define both expected values.[#191][191]

[191]: https://github.com/chaostoolkit/chaostoolkit-lib/pull/191


## [1.15.0][] - 2020-09-11

[1.15.0]: https://github.com/chaostoolkit/chaostoolkit-lib/compare/1.14.1...1.15.0
Expand Down Expand Up @@ -136,7 +149,7 @@
was interrupted from a control. With the strategies, you can now decide
that they are always applied, never or only when the experiment deviated.
This is a flag passed to the settings as follows:

```
runtime:
rollbacks:
Expand Down Expand Up @@ -215,13 +228,13 @@
### Added

- Optional default value for environment variable in configuration
- Warn the user for an action process returning a non-zero exit code
- Warn the user for an action process returning a non-zero exit code
- Support for process path relative to homedir ~
- Indicate path in validation when path is not found nor executable [#159][159]

### Changed

- Changed the method's one-step minimum requirement.
- Changed the method's one-step minimum requirement.
An experiment with an empty method (without any activities) is now valid.

[159]: https://github.com/chaostoolkit/chaostoolkit-lib/issues/159
Expand Down Expand Up @@ -333,7 +346,7 @@

### Changed

- Fix to ensure a control's `configuration` parameter is populated when it the
- Fix to ensure a control's `configuration` parameter is populated when it the
control is being `configured` [#114][114]
- Load and apply global controls, those declared in the settings, from the
`run_experiment` function rather than out of band [#116][116]
Expand Down Expand Up @@ -400,7 +413,7 @@
#### Added

- a new tolerance type called `range` to support scenarios such as:

value type is:
```
{
Expand Down Expand Up @@ -765,7 +778,7 @@

### Changed

- Log a message when loading the configuration
- Log a message when loading the configuration
- Raise `InvalidExperiment` when a configuration or secret references a key
in the environment and that key does not exist (it may not be set however)
[#40][40]. This bails the experiment at validation time so before it runs.
Expand Down
14 changes: 7 additions & 7 deletions chaoslib/hypothesis.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,19 +335,19 @@ def _(tolerance: dict, value: Any, configuration: Configuration = None,
result = values == expect

if "expect" in tolerance and result is False:
expect_alt = tolerance.get("expect_alt")
if "expect_alt" in tolerance:
if not isinstance(expect_alt, list):
result = values == [expect_alt]
expect_one_of = tolerance.get("expect_one_of")
if "expect_one_of" in tolerance:
if not isinstance(expect_one_of, list):
result = values == [expect_one_of]
else:
result = values == expect_alt
result = values == expect_one_of

if result is False:
if "expect" in tolerance and "expect_alt" in tolerance:
if "expect" in tolerance and "expect_one_of" in tolerance:
logger.debug(
"jsonpath found '{}' but expected '{}' or '{}'".format(
str(values), str(tolerance["expect"]),
str(tolerance["expect_alt"])))
str(tolerance["expect_one_of"])))
elif "expect" in tolerance:
logger.debug(
"jsonpath found '{}' but expected '{}'".format(
Expand Down
4 changes: 2 additions & 2 deletions tests/test_tolerance.py
Original file line number Diff line number Diff line change
Expand Up @@ -143,7 +143,7 @@ def test_tolerance_jsonpath_must_match_expected_value():
"type": "jsonpath",
"path": "$.foo[?(@.baz)].baz",
"expect": [["hello", "bonjour"]],
"expect_alt": [["hello", "joe"]]
"expect_one_of": [["hello", "joe"]]
}
ensure_hypothesis_tolerance_is_valid(t)
assert within_tolerance(
Expand All @@ -168,7 +168,7 @@ def test_tolerance_jsonpath_must_match_expected_value():
"type": "jsonpath",
"path": "$.foo[?(@.baz)].baz",
"expect": [[["hello"], ["bonjour"]]],
"expect_alt": [[["hello"], ["joe"]]]
"expect_one_of": [[["hello"], ["joe"]]]
}
ensure_hypothesis_tolerance_is_valid(t)
assert within_tolerance(
Expand Down

0 comments on commit e196962

Please sign in to comment.