-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathldclient_external_updates_only_test.go
77 lines (66 loc) · 2.64 KB
/
ldclient_external_updates_only_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package ldclient
import (
"testing"
"github.com/launchdarkly/go-server-sdk/v7/internal/sharedtest/mocks"
"github.com/launchdarkly/go-sdk-common/v3/ldlog"
"github.com/launchdarkly/go-sdk-common/v3/ldlogtest"
"github.com/launchdarkly/go-sdk-common/v3/ldvalue"
"github.com/launchdarkly/go-server-sdk-evaluation/v3/ldbuilders"
"github.com/launchdarkly/go-server-sdk/v7/interfaces"
"github.com/launchdarkly/go-server-sdk/v7/internal/datastore"
"github.com/launchdarkly/go-server-sdk/v7/internal/sharedtest"
"github.com/launchdarkly/go-server-sdk/v7/ldcomponents"
"github.com/launchdarkly/go-server-sdk/v7/subsystems"
"github.com/launchdarkly/go-server-sdk/v7/subsystems/ldstoreimpl"
"github.com/stretchr/testify/assert"
)
type clientExternalUpdatesTestParams struct {
client *LDClient
store subsystems.DataStore
mockLog *ldlogtest.MockLog
}
func withClientExternalUpdatesTestParams(callback func(clientExternalUpdatesTestParams)) {
p := clientExternalUpdatesTestParams{}
p.store = datastore.NewInMemoryDataStore(ldlog.NewDisabledLoggers())
p.mockLog = ldlogtest.NewMockLog()
config := Config{
DataSource: ldcomponents.ExternalUpdatesOnly(),
DataStore: mocks.SingleComponentConfigurer[subsystems.DataStore]{Instance: p.store},
Logging: ldcomponents.Logging().Loggers(p.mockLog.Loggers),
}
p.client, _ = MakeCustomClient("sdk_key", config, 0)
defer p.client.Close()
callback(p)
}
func TestClientExternalUpdatesMode(t *testing.T) {
t.Run("is initialized", func(t *testing.T) {
withClientExternalUpdatesTestParams(func(p clientExternalUpdatesTestParams) {
assert.True(t, p.client.Initialized())
assert.Equal(t, interfaces.DataSourceStateValid,
p.client.GetDataSourceStatusProvider().GetStatus().State)
})
})
t.Run("reports non-offline status", func(t *testing.T) {
withClientExternalUpdatesTestParams(func(p clientExternalUpdatesTestParams) {
assert.False(t, p.client.IsOffline())
})
})
t.Run("logs appropriate message at startup", func(t *testing.T) {
withClientExternalUpdatesTestParams(func(p clientExternalUpdatesTestParams) {
assert.Contains(
t,
p.mockLog.GetOutput(ldlog.Info),
"LaunchDarkly client will not connect to Launchdarkly for feature flag data",
)
})
})
t.Run("uses data from store", func(t *testing.T) {
flag := ldbuilders.NewFlagBuilder("flagkey").SingleVariation(ldvalue.Bool(true)).Build()
withClientExternalUpdatesTestParams(func(p clientExternalUpdatesTestParams) {
_, _ = p.store.Upsert(ldstoreimpl.Features(), flag.Key, sharedtest.FlagDescriptor(flag))
result, err := p.client.BoolVariation(flag.Key, evalTestUser, false)
assert.NoError(t, err)
assert.True(t, result)
})
})
}