Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add gherkin tests to verify evaluation details in finally hooks #290

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion specification/assets/gherkin/evaluation.feature
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Feature: Flag evaluation
# This test suite contains scenarios to test the flag evaluation API.

Background:
Given a provider is registered
Given a stable provider

# basic evaluation
Scenario: Resolves boolean value
Expand Down
52 changes: 52 additions & 0 deletions specification/assets/gherkin/hooks.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
@hooks
Feature: Evaluation details through hooks

# This test suite contains scenarios to test the functionality of hooks.

Background:
Given a stable provider

Scenario: Passes evaluation details to after and finally hooks
Given a client with added hook
And a boolean-flag with key "boolean-flag" and a default value "false"
When the flag was evaluated with details
Then the "before" hook should have been executed
And the "after, finally after" hooks should be called with evaluation details
| data_type | key | value |
| string | flag_key | boolean-flag |
| boolean | value | true |
| string | variant | on |
| string | reason | STATIC |
| string | error_code | None |
| string | error_message | None |

# errors
Scenario: Flag not found
Given a client with added hook
And a string-flag with key "missing-flag" and a default value "uh-oh"
When the flag was evaluated with details
Then the "before" hook should have been executed
And the "error" hook should have been executed
And the "finally after" hooks should be called with evaluation details
| data_type | key | value |
| string | flag_key | missing-flag |
| string | value | uh-oh |
| string | variant | None |
| string | reason | ERROR |
| string | error_code | ErrorCode.FLAG_NOT_FOUND |
| string | error_message | Flag 'missing-flag' not found |

Scenario: Type error
Given a client with added hook
And a string-flag with key "wrong-flag" and a default value "13"
When the flag was evaluated with details
Then the "before" hook should have been executed
And the "error" hook should have been executed
And the "finally after" hooks should be called with evaluation details
| data_type | key | value |
| string | flag_key | wrong-flag |
| integer | value | 13 |
| string | variant | None |
| string | reason | ERROR |
| string | error_code | ErrorCode.TYPE_MISMATCH |
| string | error_message | Expected type <class 'int'> but got <class 'str'> |
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to define the error message?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, the error message might be very implementation specific, so I agree with you. @aepfli @toddbaert what do you think?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

open for both approaches, i do think that normalized error message could be handy, but we should remove any language specific synatx. eg "Expected type Integer but got String" so we can easier map this in other languages to a desired message. But i like the idea of standardized messages throughout the sdks.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with the standardized error messages. However, I do think this would be a nontrivial change. Should we do this in a follow up issue? Then I would remove the error message from this PR

Loading