From 3aa2264f1c9521e01bdacdb5c98b309429919cfd Mon Sep 17 00:00:00 2001 From: "christian.lutnik" Date: Tue, 14 Jan 2025 11:24:00 +0100 Subject: [PATCH 1/5] feat: Add evaluation details to finally hook stage #403 Signed-off-by: christian.lutnik --- .../assets/gherkin/evaluation.feature | 39 +++++++++++++++++-- 1 file changed, 36 insertions(+), 3 deletions(-) diff --git a/specification/assets/gherkin/evaluation.feature b/specification/assets/gherkin/evaluation.feature index 20ae4682..2832a05d 100644 --- a/specification/assets/gherkin/evaluation.feature +++ b/specification/assets/gherkin/evaluation.feature @@ -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 provider is registered with cache disabled # basic evaluation Scenario: Resolves boolean value @@ -48,6 +48,19 @@ Feature: Flag evaluation Then the resolved object details value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively And the variant should be "template", and the reason should be "STATIC" + Scenario: Passes evaluation details to finally hooks + When a hook is added to the client + And a boolean flag with key "boolean-flag" is evaluated with details and default value "false" + Then non-error hooks should be called + And "after, finally after" hook should have evaluation details + | flag_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 | + # context-aware evaluation Scenario: Resolves based on context When context contains keys "fn", "ln", "age", "customer" with values "Sulisław", "Świętopełk", 29, "false" @@ -57,11 +70,31 @@ Feature: Flag evaluation # errors Scenario: Flag not found - When a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh" + When a hook is added to the client + And a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh" Then the default string value should be returned And the reason should indicate an error and the error code should indicate a missing flag with "FLAG_NOT_FOUND" + And error hooks should be called + And "finally after" hook should have evaluation details + | 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 - When a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13 + When a hook is added to the client + And a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13 Then the default integer value should be returned And the reason should indicate an error and the error code should indicate a type mismatch with "TYPE_MISMATCH" + And error hooks should be called + And "finally after" hook should have evaluation details + | 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 but got | \ No newline at end of file From a31ed8336a1d650978ecbdca2b0006f9cb46af7b Mon Sep 17 00:00:00 2001 From: "christian.lutnik" Date: Tue, 14 Jan 2025 12:55:27 +0100 Subject: [PATCH 2/5] fixup! feat: Add evaluation details to finally hook stage #403 Signed-off-by: christian.lutnik --- specification/assets/gherkin/evaluation.feature | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/specification/assets/gherkin/evaluation.feature b/specification/assets/gherkin/evaluation.feature index 2832a05d..38f25667 100644 --- a/specification/assets/gherkin/evaluation.feature +++ b/specification/assets/gherkin/evaluation.feature @@ -48,11 +48,11 @@ Feature: Flag evaluation Then the resolved object details value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively And the variant should be "template", and the reason should be "STATIC" - Scenario: Passes evaluation details to finally hooks + Scenario: Passes evaluation details to after and finally hooks When a hook is added to the client And a boolean flag with key "boolean-flag" is evaluated with details and default value "false" - Then non-error hooks should be called - And "after, finally after" hook should have evaluation details + Then "before" hooks should be called + And "after, finally after" hooks should be called with evaluation details | flag_type | key | value | | string | flag_key | boolean-flag | | boolean | value | true | @@ -74,8 +74,8 @@ Feature: Flag evaluation And a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh" Then the default string value should be returned And the reason should indicate an error and the error code should indicate a missing flag with "FLAG_NOT_FOUND" - And error hooks should be called - And "finally after" hook should have evaluation details + Then "before, error" hooks should be called + And "finally after" hooks should be called with evaluation details | type | key | value | | string | flag_key | missing-flag | | string | value | uh-oh | @@ -89,8 +89,8 @@ Feature: Flag evaluation And a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13 Then the default integer value should be returned And the reason should indicate an error and the error code should indicate a type mismatch with "TYPE_MISMATCH" - And error hooks should be called - And "finally after" hook should have evaluation details + Then "before, error" hooks should be called + And "finally after" hooks should be called with evaluation details | type | key | value | | string | flag_key | wrong-flag | | integer | value | 13 | From 3a47b13cc3b8e95bcec86e7578e5fdd2215e38ba Mon Sep 17 00:00:00 2001 From: "christian.lutnik" Date: Thu, 16 Jan 2025 13:56:55 +0100 Subject: [PATCH 3/5] fixup! feat: Add evaluation details to finally hook stage #403 Signed-off-by: christian.lutnik --- .../assets/gherkin/evaluation.feature | 37 +------------ specification/assets/gherkin/hooks.feature | 52 +++++++++++++++++++ 2 files changed, 54 insertions(+), 35 deletions(-) create mode 100644 specification/assets/gherkin/hooks.feature diff --git a/specification/assets/gherkin/evaluation.feature b/specification/assets/gherkin/evaluation.feature index 38f25667..e12ef54c 100644 --- a/specification/assets/gherkin/evaluation.feature +++ b/specification/assets/gherkin/evaluation.feature @@ -48,19 +48,6 @@ Feature: Flag evaluation Then the resolved object details value should be contain fields "showImages", "title", and "imagesPerPage", with values "true", "Check out these pics!" and 100, respectively And the variant should be "template", and the reason should be "STATIC" - Scenario: Passes evaluation details to after and finally hooks - When a hook is added to the client - And a boolean flag with key "boolean-flag" is evaluated with details and default value "false" - Then "before" hooks should be called - And "after, finally after" hooks should be called with evaluation details - | flag_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 | - # context-aware evaluation Scenario: Resolves based on context When context contains keys "fn", "ln", "age", "customer" with values "Sulisław", "Świętopełk", 29, "false" @@ -70,31 +57,11 @@ Feature: Flag evaluation # errors Scenario: Flag not found - When a hook is added to the client - And a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh" + When a non-existent string flag with key "missing-flag" is evaluated with details and a default value "uh-oh" Then the default string value should be returned And the reason should indicate an error and the error code should indicate a missing flag with "FLAG_NOT_FOUND" - Then "before, error" hooks should be called - And "finally after" hooks should be called with evaluation details - | 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 - When a hook is added to the client - And a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13 + When a string flag with key "wrong-flag" is evaluated as an integer, with details and a default value 13 Then the default integer value should be returned And the reason should indicate an error and the error code should indicate a type mismatch with "TYPE_MISMATCH" - Then "before, error" hooks should be called - And "finally after" hooks should be called with evaluation details - | 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 but got | \ No newline at end of file diff --git a/specification/assets/gherkin/hooks.feature b/specification/assets/gherkin/hooks.feature new file mode 100644 index 00000000..341a7816 --- /dev/null +++ b/specification/assets/gherkin/hooks.feature @@ -0,0 +1,52 @@ +@hooks +Feature: Evaluation details through hooks + +# This test suite contains scenarios to test the functionality of hooks. + + Background: + Given a provider is registered with cache disabled + + 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 "before" hooks should be called + And "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 "before" hooks should be called + And "error" hooks should be called + And "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 "before" hooks should be called + And "error" hooks should be called + And "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 but got | \ No newline at end of file From 2dff5ea549704f2e9e11162acc10b64eec00c91b Mon Sep 17 00:00:00 2001 From: "christian.lutnik" Date: Thu, 16 Jan 2025 15:37:19 +0100 Subject: [PATCH 4/5] fixup! feat: Add evaluation details to finally hook stage #403 Signed-off-by: christian.lutnik --- .../assets/gherkin/evaluation.feature | 2 +- specification/assets/gherkin/hooks.feature | 18 +++++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/specification/assets/gherkin/evaluation.feature b/specification/assets/gherkin/evaluation.feature index e12ef54c..0c8f41ee 100644 --- a/specification/assets/gherkin/evaluation.feature +++ b/specification/assets/gherkin/evaluation.feature @@ -3,7 +3,7 @@ Feature: Flag evaluation # This test suite contains scenarios to test the flag evaluation API. Background: - Given a provider is registered with cache disabled + Given a stable provider # basic evaluation Scenario: Resolves boolean value diff --git a/specification/assets/gherkin/hooks.feature b/specification/assets/gherkin/hooks.feature index 341a7816..18cf57bb 100644 --- a/specification/assets/gherkin/hooks.feature +++ b/specification/assets/gherkin/hooks.feature @@ -4,14 +4,14 @@ Feature: Evaluation details through hooks # This test suite contains scenarios to test the functionality of hooks. Background: - Given a provider is registered with cache disabled + 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 "before" hooks should be called - And "after, finally after" hooks should be called with evaluation 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 | @@ -25,9 +25,9 @@ Feature: Evaluation details through hooks 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 "before" hooks should be called - And "error" hooks should be called - And "finally after" hooks should be called with evaluation 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 | @@ -40,9 +40,9 @@ Feature: Evaluation details through hooks 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 "before" hooks should be called - And "error" hooks should be called - And "finally after" hooks should be called with evaluation 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 | From 89dfff106ca9852484cfbe3784f8c42d72f741db Mon Sep 17 00:00:00 2001 From: "christian.lutnik" Date: Fri, 17 Jan 2025 11:32:50 +0100 Subject: [PATCH 5/5] fixup! feat: Add evaluation details to finally hook stage #403 Signed-off-by: christian.lutnik --- specification/assets/gherkin/hooks.feature | 3 --- 1 file changed, 3 deletions(-) diff --git a/specification/assets/gherkin/hooks.feature b/specification/assets/gherkin/hooks.feature index 18cf57bb..e793a5bc 100644 --- a/specification/assets/gherkin/hooks.feature +++ b/specification/assets/gherkin/hooks.feature @@ -18,7 +18,6 @@ Feature: Evaluation details through hooks | string | variant | on | | string | reason | STATIC | | string | error_code | None | - | string | error_message | None | # errors Scenario: Flag not found @@ -34,7 +33,6 @@ Feature: Evaluation details through hooks | 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 @@ -49,4 +47,3 @@ Feature: Evaluation details through hooks | string | variant | None | | string | reason | ERROR | | string | error_code | ErrorCode.TYPE_MISMATCH | - | string | error_message | Expected type but got | \ No newline at end of file