-
Notifications
You must be signed in to change notification settings - Fork 23
test(e2e): Update e2e tests to support newer spec submodule #604
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
base: main
Are you sure you want to change the base?
Changes from 12 commits
b92e939
3727780
77aa26d
0869166
c8c39ea
c0ee595
f5c2c76
c8e0648
034f15a
072f812
b8469be
fa6072f
56bf219
d0e3580
f5470eb
3924c28
4c43260
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,4 @@ | ||
| using System.Text.Json; | ||
| using OpenFeature.E2ETests.Utils; | ||
| using OpenFeature.Model; | ||
| using OpenFeature.Providers.Memory; | ||
|
|
@@ -17,43 +18,69 @@ public BaseStepDefinitions(State state) | |
| [Given(@"a stable provider")] | ||
| public async Task GivenAStableProvider() | ||
| { | ||
| var memProvider = new InMemoryProvider(E2EFlagConfig); | ||
| var options = new JsonSerializerOptions() | ||
| { | ||
| PropertyNameCaseInsensitive = true | ||
| }; | ||
| options.Converters.Add(new FlagDictionaryJsonConverter()); | ||
|
|
||
| var json = File.ReadAllText(Path.Combine("Features", "test-flags.json")); | ||
| var flags = JsonSerializer.Deserialize<Dictionary<string, Flag>>(json, options) | ||
| ?? new Dictionary<string, Flag>(); | ||
|
|
||
| var memProvider = new InMemoryProvider(flags); | ||
| await Api.Instance.SetProviderAsync(memProvider).ConfigureAwait(false); | ||
| this.State.Client = Api.Instance.GetClient("TestClient", "1.0.0"); | ||
| } | ||
|
|
||
| [Given(@"a Boolean-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a Boolean-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| [Given(@"a boolean-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a boolean-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
|
||
| public void GivenABoolean_FlagWithKeyAndADefaultValue(string key, string defaultType) | ||
| { | ||
| var flagState = new FlagState(key, defaultType, FlagType.Boolean); | ||
| this.State.Flag = flagState; | ||
| } | ||
|
|
||
| [Given(@"a Float-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a Float-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| [Given(@"a float-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a float-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| public void GivenAFloat_FlagWithKeyAndADefaultValue(string key, string defaultType) | ||
| { | ||
| var flagState = new FlagState(key, defaultType, FlagType.Float); | ||
| this.State.Flag = flagState; | ||
| } | ||
|
|
||
| [Given(@"a Integer-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a Integer-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| [Given(@"a integer-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a integer-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| public void GivenAnInteger_FlagWithKeyAndADefaultValue(string key, string defaultType) | ||
| { | ||
| var flagState = new FlagState(key, defaultType, FlagType.Integer); | ||
| this.State.Flag = flagState; | ||
| } | ||
|
|
||
| [Given(@"a String-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a String-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| [Given(@"a string-flag with key ""(.*)"" and a default value ""(.*)""")] | ||
| [Given(@"a string-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| public void GivenAString_FlagWithKeyAndADefaultValue(string key, string defaultType) | ||
| { | ||
| var flagState = new FlagState(key, defaultType, FlagType.String); | ||
| this.State.Flag = flagState; | ||
| } | ||
|
|
||
| [Given(@"a Object-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| [Given(@"a object-flag with key ""(.*)"" and a fallback value ""(.*)""")] | ||
| public void GivenAObject_FlagWithKeyAndADefaultValue(string key, string defaultType) | ||
| { | ||
| var flagState = new FlagState(key, defaultType, FlagType.Object); | ||
| this.State.Flag = flagState; | ||
| } | ||
|
|
||
| [Given("a stable provider with retrievable context is registered")] | ||
| public async Task GivenAStableProviderWithRetrievableContextIsRegistered() | ||
| { | ||
|
|
@@ -111,18 +138,28 @@ public async Task WhenTheFlagWasEvaluatedWithDetails() | |
| { | ||
| case FlagType.Boolean: | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client! | ||
| .GetBooleanDetailsAsync(flag.Key, bool.Parse(flag.DefaultValue)).ConfigureAwait(false); | ||
| .GetBooleanDetailsAsync(flag.Key, bool.Parse(flag.DefaultValue), this.State.EvaluationContext) | ||
| .ConfigureAwait(false); | ||
| break; | ||
| case FlagType.Float: | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client! | ||
| .GetDoubleDetailsAsync(flag.Key, double.Parse(flag.DefaultValue)).ConfigureAwait(false); | ||
| .GetDoubleDetailsAsync(flag.Key, double.Parse(flag.DefaultValue), this.State.EvaluationContext) | ||
| .ConfigureAwait(false); | ||
| break; | ||
| case FlagType.Integer: | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client! | ||
| .GetIntegerDetailsAsync(flag.Key, int.Parse(flag.DefaultValue)).ConfigureAwait(false); | ||
| .GetIntegerDetailsAsync(flag.Key, int.Parse(flag.DefaultValue), this.State.EvaluationContext) | ||
| .ConfigureAwait(false); | ||
| break; | ||
| case FlagType.String: | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client!.GetStringDetailsAsync(flag.Key, flag.DefaultValue) | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client! | ||
| .GetStringDetailsAsync(flag.Key, flag.DefaultValue, this.State.EvaluationContext) | ||
| .ConfigureAwait(false); | ||
| break; | ||
| case FlagType.Object: | ||
| var defaultStructure = JsonStructureLoader.ParseJsonValue(flag.DefaultValue); | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client! | ||
| .GetObjectDetailsAsync(flag.Key, new Value(defaultStructure), this.State.EvaluationContext) | ||
| .ConfigureAwait(false); | ||
| break; | ||
| } | ||
|
|
@@ -176,83 +213,6 @@ private void InitializeContext(string level, EvaluationContext context) | |
| } | ||
| } | ||
|
|
||
| private static readonly IDictionary<string, Flag> E2EFlagConfig = new Dictionary<string, Flag> | ||
| { | ||
| { | ||
| "metadata-flag", new Flag<bool>( | ||
| variants: new Dictionary<string, bool> { { "on", true }, { "off", false } }, | ||
| defaultVariant: "on", | ||
| flagMetadata: new ImmutableMetadata(new Dictionary<string, object> | ||
| { | ||
| { "string", "1.0.2" }, { "integer", 2 }, { "float", 0.1 }, { "boolean", true } | ||
| }) | ||
| ) | ||
| }, | ||
| { | ||
| "boolean-flag", new Flag<bool>( | ||
| variants: new Dictionary<string, bool> { { "on", true }, { "off", false } }, | ||
| defaultVariant: "on" | ||
| ) | ||
| }, | ||
| { | ||
| "string-flag", new Flag<string>( | ||
| variants: new Dictionary<string, string>() { { "greeting", "hi" }, { "parting", "bye" } }, | ||
| defaultVariant: "greeting" | ||
| ) | ||
| }, | ||
| { | ||
| "integer-flag", new Flag<int>( | ||
| variants: new Dictionary<string, int>() { { "one", 1 }, { "ten", 10 } }, | ||
| defaultVariant: "ten" | ||
| ) | ||
| }, | ||
| { | ||
| "float-flag", new Flag<double>( | ||
| variants: new Dictionary<string, double>() { { "tenth", 0.1 }, { "half", 0.5 } }, | ||
| defaultVariant: "half" | ||
| ) | ||
| }, | ||
| { | ||
| "object-flag", new Flag<Value>( | ||
| variants: new Dictionary<string, Value>() | ||
| { | ||
| { "empty", new Value() }, | ||
| { | ||
| "template", new Value(Structure.Builder() | ||
| .Set("showImages", true) | ||
| .Set("title", "Check out these pics!") | ||
| .Set("imagesPerPage", 100).Build() | ||
| ) | ||
| } | ||
| }, | ||
| defaultVariant: "template" | ||
| ) | ||
| }, | ||
| { | ||
| "context-aware", new Flag<string>( | ||
| variants: new Dictionary<string, string>() { { "internal", "INTERNAL" }, { "external", "EXTERNAL" } }, | ||
| defaultVariant: "external", | ||
| (context) => | ||
| { | ||
| if (context.GetValue("fn").AsString == "Sulisław" | ||
| && context.GetValue("ln").AsString == "Świętopełk" | ||
| && context.GetValue("age").AsInteger == 29 | ||
| && context.GetValue("customer").AsBoolean == false) | ||
| { | ||
| return "internal"; | ||
| } | ||
| else return "external"; | ||
| } | ||
| ) | ||
| }, | ||
| { | ||
| "wrong-flag", new Flag<string>( | ||
| variants: new Dictionary<string, string>() { { "one", "uno" }, { "two", "dos" } }, | ||
| defaultVariant: "one" | ||
| ) | ||
| } | ||
| }; | ||
|
|
||
| public class BeforeHook : Hook | ||
| { | ||
| private readonly EvaluationContext context; | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -255,4 +255,18 @@ public void Giventhereasonshouldindicateanerrorandtheerrorcodeshouldindicateatyp | |
| Assert.Equal(Reason.Error, result?.Reason); | ||
| Assert.Equal(errorCode, result?.ErrorType.GetDescription()); | ||
| } | ||
|
|
||
| [When(@"a non-existent string flag with key ""(.*)"" is evaluated with details and a fallback value ""(.*)""")] | ||
| public async Task WhenANon_ExistentStringFlagWithKeyIsEvaluatedWithDetailsAndAFallbackValue(string flagKey, string defaultValue) | ||
| { | ||
| this.State.Flag = new FlagState(flagKey, defaultValue.ToString(), FlagType.String); | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client!.GetStringDetailsAsync(flagKey, defaultValue).ConfigureAwait(false); | ||
| } | ||
|
|
||
| [When(@"a string flag with key ""(.*)"" is evaluated as an integer, with details and a fallback value (.*)")] | ||
| public async Task WhenAStringFlagWithKeyIsEvaluatedAsAnIntegerWithDetailsAndAFallbackValue(string flagKey, int defaultValue) | ||
| { | ||
| this.State.Flag = new FlagState(flagKey, defaultValue.ToString(), FlagType.Integer); | ||
| this.State.FlagEvaluationDetailsResult = await this.State.Client!.GetIntegerDetailsAsync(flagKey, defaultValue).ConfigureAwait(false); | ||
| } | ||
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.