clienttest

package
v0.4.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Feb 21, 2024 License: Apache-2.0 Imports: 5 Imported by: 0

README

clienttest

This package contains clienttest, an in-memory fake Lekko Client. clienttest can be used to test code that depends on the Lekko SDK in Golang.

Here is a simple example of how you may use it in a unit test:

func TestLekko(t *testing.T) {
	testClient := NewTestClient().WithBool("namespace", "bool-config", true)

	result, err := testClient.GetBool(context.Background(), "namespace", "bool-config")
	assert.NoError(t, err)
	assert.True(t, result)
}

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrNotFound     = errors.New("config not found")
	ErrTypeMismatch = errors.New("type mismatch")
)

Functions

This section is empty.

Types

type TestClient

type TestClient struct {
	// contains filtered or unexported fields
}

TestClient is an in-memory configuration store intended for use in unit tests. It conforms to the See client_test.go for examples on how to use it.

func NewTestClient

func NewTestClient() *TestClient

Constructs a TestClient for use in unit tests.

func (*TestClient) Close added in v0.4.0

func (tc *TestClient) Close(ctx context.Context) error

func (*TestClient) GetBool

func (tc *TestClient) GetBool(_ context.Context, namespace, key string) (bool, error)

func (*TestClient) GetFloat

func (tc *TestClient) GetFloat(_ context.Context, namespace, key string) (float64, error)

func (*TestClient) GetInt

func (tc *TestClient) GetInt(_ context.Context, namespace, key string) (int64, error)

func (*TestClient) GetJSON

func (tc *TestClient) GetJSON(_ context.Context, namespace, key string, result interface{}) error

func (*TestClient) GetProto

func (tc *TestClient) GetProto(_ context.Context, namespace, key string, result proto.Message) error

func (*TestClient) GetString

func (tc *TestClient) GetString(_ context.Context, namespace, key string) (string, error)

func (*TestClient) WithBool

func (tc *TestClient) WithBool(namespace, key string, value bool) *TestClient

func (*TestClient) WithError

func (tc *TestClient) WithError(namespace, key string, err error) *TestClient

func (*TestClient) WithFloat

func (tc *TestClient) WithFloat(namespace, key string, value float64) *TestClient

func (*TestClient) WithInt

func (tc *TestClient) WithInt(namespace, key string, value int64) *TestClient

func (*TestClient) WithJSON

func (tc *TestClient) WithJSON(namespace, key string, value []byte) *TestClient

Accepts a JSON-serialized byte array

func (*TestClient) WithProto

func (tc *TestClient) WithProto(namespace, key string, value []byte) *TestClient

Accepts a proto-serialized byte array

func (*TestClient) WithString

func (tc *TestClient) WithString(namespace, key string, value string) *TestClient

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL