-
Notifications
You must be signed in to change notification settings - Fork 81
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 support for client-side prerequisite events #452
Merged
Merged
Changes from 5 commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
992dded
feat: add support for client-side prerequisite events
cwaldren-ld f9f29c3
adding test scaffolding
cwaldren-ld 17b4203
attempt to add a flag with prerequisites via LD API
cwaldren-ld fae991f
unique flag keys
cwaldren-ld 43ad690
add dedicated methods to create the flags
cwaldren-ld 461e14e
remove nesting
cwaldren-ld fe7b668
add another test
cwaldren-ld 4b3c33c
add flagBuilder pattern
cwaldren-ld 3668f83
add third test
cwaldren-ld b6eb56a
code layout
cwaldren-ld 8fe6899
use errors.As
cwaldren-ld 903cc72
don't have a redundant logging routine
cwaldren-ld ff75ac0
add test for mobile keys
cwaldren-ld 4e0c497
refactoring
cwaldren-ld 5bd4aa5
refactor to put flag setup in each test
cwaldren-ld 5856bcd
remove old comment
cwaldren-ld 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
//go:build integrationtests | ||
|
||
package integrationtests | ||
|
||
import ( | ||
ldapi "github.com/launchdarkly/api-client-go/v13" | ||
"github.com/launchdarkly/go-sdk-common/v3/ldvalue" | ||
"github.com/stretchr/testify/require" | ||
"testing" | ||
) | ||
|
||
func withStandardModePrerequisitesTestData(t *testing.T, manager *integrationTestManager, fn func(data standardModeTestData, prereqs map[string][]string)) { | ||
project, envs, err := manager.apiHelper.createProject(1) | ||
require.NoError(t, err) | ||
defer manager.apiHelper.deleteProject(project) | ||
|
||
flagKey := func(name string) string { | ||
return name + "-" + flagKeyForProj(project) | ||
} | ||
|
||
env := envs[0] | ||
toplevel1 := flagKey("toplevel1") | ||
prereq1 := flagKey("prereq1") | ||
prereq2 := flagKey("prereq2") | ||
|
||
err = manager.apiHelper.createFlagWithVariations(project, env, prereq1, true, ldvalue.Bool(false), ldvalue.Bool(true)) | ||
require.NoError(t, err) | ||
|
||
err = manager.apiHelper.createFlagWithVariations(project, env, prereq2, true, ldvalue.Bool(false), ldvalue.Bool(true)) | ||
require.NoError(t, err) | ||
|
||
prerequisites := map[string][]string{ | ||
toplevel1: {prereq1, prereq2}, | ||
} | ||
|
||
// The createFlagWithVariations call sets up two variations, with the second one being used if the flag is on. | ||
// The test here is to see which prerequisites were evaluated for a given flag. If a prerequisite fails, the eval | ||
// algorithm is going to short-circuit and we won't see the other prerequisite. So, we'll have two prerequisites, | ||
// both of which are on, and both of which are satisfied. That way the evaluator will be forced to visit both, | ||
// and we'll see the list of both when we query the eval endpoint. | ||
const onVariation = 1 | ||
for flag, prereqs := range prerequisites { | ||
var ps []ldapi.Prerequisite | ||
for _, prereq := range prereqs { | ||
ps = append(ps, ldapi.Prerequisite{Key: prereq, Variation: onVariation}) | ||
} | ||
err = manager.apiHelper.createFlagWithPrerequisites(project, env, flag, true, ldvalue.Bool(false), ldvalue.Bool(true), ps) | ||
require.NoError(t, err) | ||
} | ||
|
||
testData := standardModeTestData{ | ||
projsAndEnvs: projsAndEnvs{ | ||
{key: project.key, name: project.name}: envs, | ||
}, | ||
} | ||
|
||
fn(testData, prerequisites) | ||
} | ||
|
||
func testStandardModeWithPrerequisites(t *testing.T, manager *integrationTestManager) { | ||
withStandardModePrerequisitesTestData(t, manager, func(testData standardModeTestData, prerequisites map[string][]string) { | ||
envVars := make(map[string]string) | ||
testData.projsAndEnvs.enumerateEnvs(func(proj projectInfo, env environmentInfo) { | ||
envVars["LD_ENV_"+string(env.name)] = string(env.sdkKey) | ||
envVars["LD_MOBILE_KEY_"+string(env.name)] = string(env.mobileKey) | ||
envVars["LD_CLIENT_SIDE_ID_"+string(env.name)] = string(env.id) | ||
}) | ||
manager.startRelay(t, envVars) | ||
defer manager.stopRelay(t) | ||
|
||
manager.awaitEnvironments(t, testData.projsAndEnvs, nil, func(proj projectInfo, env environmentInfo) string { | ||
return env.name | ||
}) | ||
manager.verifyFlagPrerequisites(t, testData.projsAndEnvs, prerequisites) | ||
}) | ||
} |
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
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.
All of this to say.. here's the new behavior implemented by the PR.