-
Notifications
You must be signed in to change notification settings - Fork 0
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
feat: Add client-prereq-events
capability
#242
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,6 +21,12 @@ func doClientSideSummaryEventTests(t *ldtest.T) { | |
t.Run("context kinds", doClientSideSummaryEventContextKindsTest) | ||
t.Run("unknown flag", doClientSideSummaryEventUnknownFlagTest) | ||
t.Run("reset after each flush", doClientSideSummaryEventResetTest) | ||
|
||
t.Run("prerequisites", func(t *ldtest.T) { | ||
t.RequireCapability(servicedef.CapabilityClientPrereqEvents) | ||
t.Run("basic behavior", doClientSideSummaryBasicPrereqTest) | ||
t.Run("emits unknown event", doClientSideSummaryPrereqUnknownFlagTest) | ||
}) | ||
} | ||
|
||
func doClientSideSummaryEventBasicTest(t *ldtest.T) { | ||
|
@@ -276,3 +282,148 @@ func doClientSideSummaryEventResetTest(t *ldtest.T) { | |
)), | ||
) | ||
} | ||
|
||
func doClientSideSummaryBasicPrereqTest(t *ldtest.T) { | ||
topLevelKey := "flag1" | ||
topLevelResult := mockld.ClientSDKFlag{ | ||
Value: ldvalue.String("value1-a"), | ||
Variation: o.Some(0), | ||
FlagVersion: o.Some(1), | ||
Version: 11, | ||
Prerequisites: []string{"prereq1", "prereq2"}, | ||
} | ||
|
||
prereq1Key := "prereq1" | ||
prereq1Result := mockld.ClientSDKFlag{ | ||
Value: ldvalue.String("prereq1"), | ||
Variation: o.Some(0), | ||
FlagVersion: o.Some(1), | ||
Version: 11, | ||
Prerequisites: []string{"prereq3"}, | ||
} | ||
|
||
prereq2Key := "prereq2" | ||
prereq2Result := mockld.ClientSDKFlag{ | ||
Value: ldvalue.String("prereq2"), | ||
Variation: o.Some(0), | ||
FlagVersion: o.Some(1), | ||
Version: 11, | ||
} | ||
|
||
prereq3Key := "prereq3" | ||
prereq3Result := mockld.ClientSDKFlag{ | ||
Value: ldvalue.String("prereq3"), | ||
Variation: o.Some(0), | ||
FlagVersion: o.Some(1), | ||
Version: 11, | ||
} | ||
|
||
contextA := ldcontext.New("user-a") | ||
default1 := ldvalue.String("default1") | ||
default2 := ldvalue.String("default2") | ||
default3 := ldvalue.String("default3") | ||
|
||
dataBuilder := mockld.NewClientSDKDataBuilder() | ||
dataBuilder.Flag(topLevelKey, topLevelResult). | ||
Flag(prereq1Key, prereq1Result). | ||
Flag(prereq2Key, prereq2Result). | ||
Flag(prereq3Key, prereq3Result) | ||
|
||
dataSource := NewSDKDataSource(t, dataBuilder.Build()) | ||
events := NewSDKEventSinkWithGzip(t, t.Capabilities().Has(servicedef.CapabilityEventGzip)) | ||
client := NewSDKClient(t, | ||
WithClientSideInitialContext(contextA), | ||
dataSource, events) | ||
|
||
_ = client.EvaluateFlag(t, servicedef.EvaluateFlagParams{FlagKey: prereq1Key, DefaultValue: default1}) | ||
_ = client.EvaluateFlag(t, servicedef.EvaluateFlagParams{FlagKey: topLevelKey, DefaultValue: default2}) | ||
_ = client.EvaluateFlag(t, servicedef.EvaluateFlagParams{FlagKey: prereq2Key, DefaultValue: default3}) | ||
|
||
client.FlushEvents(t) | ||
payload := events.ExpectAnalyticsEvents(t, defaultEventTimeout) | ||
|
||
m.In(t).Assert(payload, m.ItemsInAnyOrder( | ||
IsIdentifyEventForContext(contextA), | ||
IsValidSummaryEventWithFlags( | ||
m.KV(topLevelKey, m.MapOf( | ||
// Was first evaluated through the EvaluateFlag call, so it has a default value. | ||
m.KV("default", m.JSONEqual(default2)), | ||
m.KV("counters", m.ItemsInAnyOrder( | ||
flagCounter(topLevelResult.Value, topLevelResult.Variation.Value(), topLevelResult.FlagVersion.Value(), 1), | ||
)), | ||
m.KV("contextKinds", anyContextKindsList()), | ||
)), | ||
m.KV(prereq1Key, m.MapOf( | ||
// Was first evaluated through the EvaluateFlag call, so it has a default value. | ||
m.KV("default", m.JSONEqual(default1)), | ||
m.KV("counters", m.ItemsInAnyOrder( | ||
flagCounter(prereq1Result.Value, prereq1Result.Variation.Value(), prereq1Result.FlagVersion.Value(), 2), | ||
)), | ||
m.KV("contextKinds", anyContextKindsList()), | ||
)), | ||
m.KV(prereq2Key, m.MapOf( | ||
m.KV("counters", m.ItemsInAnyOrder( | ||
flagCounter(prereq2Result.Value, prereq2Result.Variation.Value(), prereq2Result.FlagVersion.Value(), 2), | ||
)), | ||
m.KV("contextKinds", anyContextKindsList()), | ||
)), | ||
m.KV(prereq3Key, m.MapOf( | ||
m.KV("counters", m.ItemsInAnyOrder( | ||
flagCounter(prereq3Result.Value, prereq3Result.Variation.Value(), prereq3Result.FlagVersion.Value(), 2), | ||
)), | ||
m.KV("contextKinds", anyContextKindsList()), | ||
)), | ||
)), | ||
) | ||
} | ||
|
||
func doClientSideSummaryPrereqUnknownFlagTest(t *ldtest.T) { | ||
topLevelKey := "flag1" | ||
topLevelResult := mockld.ClientSDKFlag{ | ||
Value: ldvalue.String("value1-a"), | ||
Variation: o.Some(0), | ||
FlagVersion: o.Some(1), | ||
Version: 11, | ||
Prerequisites: []string{"unknown"}, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. And yet here we have a prereq on an unknown flag. Once we explicitly evaluate the top level key here, the unknown flag is added to the summary event WITH a default value. What's up with that? |
||
} | ||
|
||
contextA := ldcontext.New("user-a") | ||
default1 := ldvalue.String("default1") | ||
|
||
dataBuilder := mockld.NewClientSDKDataBuilder() | ||
dataBuilder.Flag(topLevelKey, topLevelResult) | ||
|
||
dataSource := NewSDKDataSource(t, dataBuilder.Build()) | ||
events := NewSDKEventSinkWithGzip(t, t.Capabilities().Has(servicedef.CapabilityEventGzip)) | ||
client := NewSDKClient(t, | ||
WithClientSideInitialContext(contextA), | ||
dataSource, events) | ||
|
||
_ = client.EvaluateFlag(t, servicedef.EvaluateFlagParams{FlagKey: topLevelKey, DefaultValue: default1}) | ||
|
||
client.FlushEvents(t) | ||
payload := events.ExpectAnalyticsEvents(t, defaultEventTimeout) | ||
|
||
m.In(t).Assert(payload, m.ItemsInAnyOrder( | ||
IsIdentifyEventForContext(contextA), | ||
IsValidSummaryEventWithFlags( | ||
m.KV(topLevelKey, m.MapOf( | ||
// Was first evaluated through the EvaluateFlag call, so it has a default value. | ||
m.KV("default", m.JSONEqual(default1)), | ||
m.KV("counters", m.ItemsInAnyOrder( | ||
flagCounter(topLevelResult.Value, topLevelResult.Variation.Value(), topLevelResult.FlagVersion.Value(), 1), | ||
)), | ||
m.KV("contextKinds", anyContextKindsList()), | ||
)), | ||
m.KV("unknown", m.AllOf( | ||
m.JSONOptProperty("default").Should(m.BeNil()), | ||
m.MapIncluding( | ||
m.KV("counters", m.ItemsInAnyOrder( | ||
unknownFlagCounter(ldvalue.Null(), 1), | ||
)), | ||
m.KV("contextKinds", anyContextKindsList()), | ||
), | ||
)), | ||
)), | ||
) | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Okay @kinyoklion check out this setup I have.