Skip to content

Commit

Permalink
feat: Add detailed checks for flag evaluation in hook execution
Browse files Browse the repository at this point in the history
Signed-off-by: André Silva <2493377+askpt@users.noreply.github.com>
  • Loading branch information
askpt committed Feb 26, 2025
1 parent fd9a490 commit e8b0bc2
Showing 1 changed file with 82 additions and 2 deletions.
84 changes: 82 additions & 2 deletions test/OpenFeature.E2ETests/Steps/HooksStepDefinitions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,19 @@ public void ThenTheHookShouldHaveBeenExecuted(string hook)
public void ThenTheHooksShouldBeCalledWithEvaluationDetails(string hook, Table table)
{
this.CheckHookExecution(hook);
// TODO: Check the evaluation details
ScenarioContext.StepIsPending();
var key = table.Rows[0]["value"];
switch (key)
{
case "boolean-flag":
CheckCorrectFlag(table);
break;
case "missing-flag":
CheckMissingFlag(table);
break;
case "wrong-flag":
this.CheckWrongFlag(table);
break;
}
}

[Given(@"a string-flag with key ""(.*)"" and a default value ""(.*)""")]
Expand All @@ -73,6 +84,75 @@ public async Task GivenAString_FlagWithKeyAndADefaultValue(string key, string de
_ = await this._client!.GetStringValueAsync(key, defaultValue).ConfigureAwait(false);
}

private static void CheckCorrectFlag(Table table)
{
Assert.Equal("string", table.Rows[0]["data_type"]);
Assert.Equal("flag_key", table.Rows[0]["key"]);
Assert.Equal("boolean-flag", table.Rows[0]["value"]);

Assert.Equal("boolean", table.Rows[1]["data_type"]);
Assert.Equal("value", table.Rows[1]["key"]);
Assert.Equal("true", table.Rows[1]["value"]);

Assert.Equal("string", table.Rows[2]["data_type"]);
Assert.Equal("variant", table.Rows[2]["key"]);
Assert.Equal("on", table.Rows[2]["value"]);

Assert.Equal("string", table.Rows[3]["data_type"]);
Assert.Equal("reason", table.Rows[3]["key"]);
Assert.Equal("STATIC", table.Rows[3]["value"]);

Assert.Equal("string", table.Rows[4]["data_type"]);
Assert.Equal("error_code", table.Rows[4]["key"]);
Assert.Equal("null", table.Rows[4]["value"]);
}

private static void CheckMissingFlag(Table table)
{
Assert.Equal("string", table.Rows[0]["data_type"]);
Assert.Equal("flag_key", table.Rows[0]["key"]);
Assert.Equal("missing-flag", table.Rows[0]["value"]);

Assert.Equal("string", table.Rows[1]["data_type"]);
Assert.Equal("value", table.Rows[1]["key"]);
Assert.Equal("uh-oh", table.Rows[1]["value"]);

Assert.Equal("string", table.Rows[2]["data_type"]);
Assert.Equal("variant", table.Rows[2]["key"]);
Assert.Equal("null", table.Rows[2]["value"]);

Assert.Equal("string", table.Rows[3]["data_type"]);
Assert.Equal("reason", table.Rows[3]["key"]);
Assert.Equal("ERROR", table.Rows[3]["value"]);

Assert.Equal("string", table.Rows[4]["data_type"]);
Assert.Equal("error_code", table.Rows[4]["key"]);
Assert.Equal("FLAG_NOT_FOUND", table.Rows[4]["value"]);
}

private void CheckWrongFlag(Table table)
{
Assert.Equal("string", table.Rows[0]["data_type"]);
Assert.Equal("flag_key", table.Rows[0]["key"]);
Assert.Equal("wrong-flag", table.Rows[0]["value"]);

Assert.Equal("boolean", table.Rows[1]["data_type"]);
Assert.Equal("value", table.Rows[1]["key"]);
Assert.Equal("false", table.Rows[1]["value"]);

Assert.Equal("string", table.Rows[2]["data_type"]);
Assert.Equal("variant", table.Rows[2]["key"]);
Assert.Equal("null", table.Rows[2]["value"]);

Assert.Equal("string", table.Rows[3]["data_type"]);
Assert.Equal("reason", table.Rows[3]["key"]);
Assert.Equal("ERROR", table.Rows[3]["value"]);

Assert.Equal("string", table.Rows[4]["data_type"]);
Assert.Equal("error_code", table.Rows[4]["key"]);
Assert.Equal("TYPE_MISMATCH", table.Rows[4]["value"]);
}

private void CheckHookExecution(string hook)
{
switch (hook)
Expand Down

0 comments on commit e8b0bc2

Please sign in to comment.