Skip to content
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

fix: Honor explicitly set default value #271

Merged
merged 2 commits into from
Dec 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions data/data-files/server-side-eval/prerequisites.yml
Original file line number Diff line number Diff line change
Expand Up @@ -316,14 +316,14 @@ evaluations:
flagKey: flag-with-prereq-cycle-at-top-level-1
context: { kind: "user", key: "user-key" }
expect:
value: false
value: null
reason: { "kind": "ERROR", "errorKind": "MALFORMED_FLAG" }

- name: prerequisite cycle is detected at deeper level, recursion stops
flagKey: flag-with-prereq-cycle-at-deeper-level-1
context: { kind: "user", key: "user-key" }
expect:
value: false
value: null
reason: { "kind": "ERROR", "errorKind": "MALFORMED_FLAG" }

- name: first prerequisite is a prerequisite of the second prerequisite
Expand Down
30 changes: 18 additions & 12 deletions sdktests/common_tests_stream_fdv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/launchdarkly/go-test-helpers/v2/httphelpers"
m "github.com/launchdarkly/go-test-helpers/v2/matchers"
"github.com/launchdarkly/sdk-test-harness/v2/framework/harness"
h "github.com/launchdarkly/sdk-test-harness/v2/framework/helpers"
"github.com/launchdarkly/sdk-test-harness/v2/framework/ldtest"
"github.com/launchdarkly/sdk-test-harness/v2/mockld"

Expand Down Expand Up @@ -70,11 +71,12 @@ func (c CommonStreamingTests) InitializeFromPollingInitializer(t *ldtest.T) {
}

func (c CommonStreamingTests) InitializeFromPollingInitializerWithStreamingUpdates(t *ldtest.T) {
dataBefore := mockld.NewServerSDKDataBuilder().Flag(c.makeServerSideFlag("flag-key", 1, initialValue)).Build()
dataBefore := mockld.NewServerSDKDataBuilder().
Flag(c.makeServerSideFlag("flag-key", 1, initialValue)).
Build()
dataAfter := mockld.NewServerSDKDataBuilder().
IntentCode("xfer-changes").
IntentReason("stale").
Flag(c.makeServerSideFlag("flag-key", 2, updatedValue)).
Flag(c.makeServerSideFlag("new-flag-key", 1, newInitialValue)).
Build()
dataSystem := NewSDKDataSystem(t, dataBefore, DataSystemOptionPollingInitializer(dataBefore))
Expand Down Expand Up @@ -215,12 +217,8 @@ func (c CommonStreamingTests) IgnoresModelVersion(t *ldtest.T) {
dataSystem, configurers := c.setupDataSystems(t, c.makeSDKDataWithFlag(100, initialValue))
client := NewSDKClient(t, c.baseSDKConfigurationPlus(configurers...)...)

_, err := dataSystem.PrimarySync().endpoint.AwaitConnection(time.Second)
require.NoError(t, err)

context := ldcontext.New("context-key")
flagKeyValue := basicEvaluateFlag(t, client, "flag-key", context, defaultValue)
m.In(t).Assert(flagKeyValue, m.JSONEqual(initialValue))
expectedEvaluations := map[string]ldvalue.Value{"flag-key": initialValue}
validatePayloadReceived(t, dataSystem.PrimarySync().Endpoint(), client, "", expectedEvaluations)

// This flag's version is less than the version previously given to the
// SDK. However, the state we are sending suggests it is later. The SDK
Expand All @@ -230,6 +228,7 @@ func (c CommonStreamingTests) IgnoresModelVersion(t *ldtest.T) {
"flag", "flag-key", 1, c.makeFlagData("flag-key", 1, updatedValue))
dataSystem.PrimarySync().streaming.PushPayloadTransferred("updated", 2)

context := ldcontext.New("context-key")
pollUntilFlagValueUpdated(t, client, "flag-key", context, initialValue, updatedValue, defaultValue)
}

Expand Down Expand Up @@ -338,10 +337,17 @@ func validatePayloadReceived(t *ldtest.T,
m.In(t).Assert(request.URL.Query().Get("basis"), m.Equal(state))

context := ldcontext.New("context-key")
for flagKey, expectedValue := range evaluations {
actualValue := basicEvaluateFlag(t, client, flagKey, context, defaultValue)
m.In(t).Assert(actualValue, m.JSONEqual(expectedValue))
}

h.RequireEventually(t, func() bool {
for flagKey, expectedValue := range evaluations {
actualValue := basicEvaluateFlag(t, client, flagKey, context, defaultValue)
if !m.In(t).Assert(actualValue, m.JSONEqual(expectedValue)) {
return false
}
}

return true
}, time.Second, time.Millisecond*20, "failed to evaluate flag")

return request
}
Loading