-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathldclient_test_data_source_test.go
38 lines (30 loc) · 1.1 KB
/
ldclient_test_data_source_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
package ldclient
import (
"testing"
"time"
"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
"github.com/launchdarkly/go-server-sdk/v7/ldcomponents"
"github.com/launchdarkly/go-server-sdk/v7/testhelpers/ldtestdata"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/require"
)
// This is a basic smoke test to verify that TestDataSource works correctly inside of an LDClient instance.
// It is in the main package, rather than the testhelpers package, to avoid a circular package reference.
func TestClientWithTestDataSource(t *testing.T) {
td := ldtestdata.DataSource()
td.Update(td.Flag("flagkey").On(true))
config := Config{
DataSource: td,
Events: ldcomponents.NoEvents(),
}
client, err := MakeCustomClient("", config, time.Second)
require.NoError(t, err)
defer client.Close()
value, err := client.BoolVariation("flagkey", ldcontext.New("userkey"), false)
require.NoError(t, err)
assert.True(t, value)
td.Update(td.Flag("flagkey").On(false))
value, err = client.BoolVariation("flagkey", ldcontext.New("userkey"), false)
require.NoError(t, err)
assert.False(t, value)
}