...

Source file src/github.com/launchdarkly/go-server-sdk/v6/ldclient_test_data_source_test.go

Documentation: github.com/launchdarkly/go-server-sdk/v6

     1  package ldclient
     2  
     3  import (
     4  	"testing"
     5  	"time"
     6  
     7  	"github.com/launchdarkly/go-sdk-common/v3/ldcontext"
     8  	"github.com/launchdarkly/go-server-sdk/v6/ldcomponents"
     9  	"github.com/launchdarkly/go-server-sdk/v6/testhelpers/ldtestdata"
    10  
    11  	"github.com/stretchr/testify/assert"
    12  	"github.com/stretchr/testify/require"
    13  )
    14  
    15  // This is a basic smoke test to verify that TestDataSource works correctly inside of an LDClient instance.
    16  // It is in the main package, rather than the testhelpers package, to avoid a circular package reference.
    17  
    18  func TestClientWithTestDataSource(t *testing.T) {
    19  	td := ldtestdata.DataSource()
    20  	td.Update(td.Flag("flagkey").On(true))
    21  
    22  	config := Config{
    23  		DataSource: td,
    24  		Events:     ldcomponents.NoEvents(),
    25  	}
    26  	client, err := MakeCustomClient("", config, time.Second)
    27  	require.NoError(t, err)
    28  	defer client.Close()
    29  
    30  	value, err := client.BoolVariation("flagkey", ldcontext.New("userkey"), false)
    31  	require.NoError(t, err)
    32  	assert.True(t, value)
    33  
    34  	td.Update(td.Flag("flagkey").On(false))
    35  	value, err = client.BoolVariation("flagkey", ldcontext.New("userkey"), false)
    36  	require.NoError(t, err)
    37  	assert.False(t, value)
    38  }
    39  

View as plain text