Documentation ¶
Index ¶
- func CommonStoreTest(t *testing.T, store Store)
- func CommonStoreTestAllTypes(t *testing.T, store Store)
- func NewTestConsulInstance(t testing.TB, cfg *config.Configuration) (*testutil.TestServer, *api.Client)
- func SetupTestConfig(t testing.TB) config.Configuration
- type ComplexFoo
- type Foo
- type KeyValueIn
- type KeyValueOut
- type Store
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func CommonStoreTest ¶
CommonStoreTest allows to test storage by storing, reading and deleting data TestStore tests if reading from, writing to and deleting from the store works properly. A struct is used as value. See TestTypes() for a test that is simpler but tests all types.
func CommonStoreTestAllTypes ¶
CommonStoreTestAllTypes allows to test storage of all types
func NewTestConsulInstance ¶
func NewTestConsulInstance(t testing.TB, cfg *config.Configuration) (*testutil.TestServer, *api.Client)
NewTestConsulInstance allows to provide new Consul instance for tests This is a private Consul server instantiation as done in github.com/ystia/yorc/v4/testutil This allows avoiding cyclic dependencies with deployments store package
func SetupTestConfig ¶
func SetupTestConfig(t testing.TB) config.Configuration
SetupTestConfig sets working directory configuration Warning: You need to defer the working directory removal This is a private Consul server instantiation as done in github.com/ystia/yorc/v4/testutil This allows avoiding cyclic dependencies with deployments store package
Types ¶
type ComplexFoo ¶
type ComplexFoo struct { FooData Foo Value string ValueInt int ValueBool bool FooList []Foo FooMap map[string]Foo }
ComplexFoo is just a complex struct for common tests.
type Foo ¶
type Foo struct { Bar string // contains filtered or unexported fields }
Foo is just some struct for common tests.
type KeyValueIn ¶
type KeyValueIn struct { Key string Value interface{} }
KeyValueIn describes a Key-Value representation Input for storing data
type KeyValueOut ¶
type KeyValueOut struct { Key string // Last modification index for the KeyValue LastModifyIndex uint64 // Value in generic format map[string]interface{} which can be cast to struct with mapstructure.Decode by instance Value map[string]interface{} // RawValue is the raw value representation without decode RawValue []byte }
KeyValueOut describes a Key-Value representation Output for retrieving data
type Store ¶
type Store interface { // Set stores the given value for the given key. // The implementation automatically marshalls the value. // The marshalling format depends on the implementation. It can be JSON, gob etc. // The key must not be "" and the value must not be nil. Set(ctx context.Context, k string, v interface{}) error // set a collection of key-values // The implementation automatically marshalls the value. // The marshalling format depends on the implementation. It can be JSON, gob etc. // It's the implementation concern to define storage mode (ie concurrently or serial) // ctx is the context provided for eventually cancelling a storage action SetCollection(ctx context.Context, keyValues []KeyValueIn) error // Get retrieves the value for the given key. // The implementation automatically unmarshalls the value. // The unmarshalling source depends on the implementation. It can be JSON, gob etc. // The automatic unmarshalling requires a pointer to an object of the correct type // being passed as parameter. // If no value is found it returns (false, nil). // The key must not be "" and the pointer must not be nil. Get(k string, v interface{}) (bool, error) // Exist returns true if the key exists in the store // If no value is found it returns (false, nil). // The key must not be "" and the pointer must not be nil. Exist(k string) (bool, error) // Keys returns all the sub-keys of a specified one. // The key must not be "". // If no sub-key is found, it returns an empty slice. // This is not recursive Keys(k string) ([]string, error) // Delete deletes the stored value for the given key. // Deleting a non-existing key-value pair does NOT lead to an error. // The key must not be "". // If recursive is true, all sub-keys are deleted too. Delete(ctx context.Context, k string, recursive bool) error // GetLastModifyIndex returns the last index that modified the key k GetLastModifyIndex(k string) (uint64, error) // List allows to lookup all sub-keys recursively under the defined key k and provided associated values. // The key must not be "" and v must not be nil. // waitIndex is used to enable a blocking query (waitIndex != 0) which wait until the timeout or a new index > waitIndex // if waitIndex is > 0, default timeout is 5 minutes. Max timeout allowed is 10 minutes // ctx can be useful to cancel a blocking query // The values are retrieved in a KeyValueOut collection. // It allows to return values in raw format without decode and in decoded generic format (map[string]interface{} // The lastIndex is returned to perform new blocking query. List(ctx context.Context, k string, waitIndex uint64, timeout time.Duration) ([]KeyValueOut, uint64, error) }
Store is an abstraction for different key-value store implementations. A store must be able to store, retrieve and delete key-value pairs, with the key being a string and the value being any Go interface{}. inspired by https://github.com/philippgille/gokv