dsmock

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Jan 15, 2022 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func YAMLData

func YAMLData(input string) map[string][]byte

YAMLData creates key values from a yaml object.

It is expected, that the input is a constant string. So there can not be any error at runtime. Therefore this function does not return an error but panics to get the developer a fast feetback.

Types

type Cache

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

Cache caches all requested keys and only redirects keys, if they where not requested before.

func NewCache

func NewCache(ds datastore.Getter) *Cache

NewCache initializes a Cache.

func (*Cache) Get

func (ds *Cache) Get(ctx context.Context, keys ...string) (map[string][]byte, error)

Get redirects the keys to the underling getter. But only, if they where not requested before.

type Counter

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

Counter counts all keys that where requested.

func NewCounter

func NewCounter(ds datastore.Getter) *Counter

NewCounter initializes a Counter.

func (*Counter) Get

func (ds *Counter) Get(ctx context.Context, keys ...string) (map[string][]byte, error)

Get sends the keys to the underling getter. Counting the request.

func (*Counter) Requests

func (ds *Counter) Requests() [][]string

Requests returns all lists of requested keys.

func (*Counter) Reset

func (ds *Counter) Reset()

Reset resets the counter.

func (*Counter) Value

func (ds *Counter) Value() int

Value returns the number of requests.

type DatastoreServer

type DatastoreServer struct {
	TS            *httptest.Server
	RequestCount  int
	RequestedKeys [][]string
	Values        *datastoreValues
	// contains filtered or unexported fields
}

DatastoreServer simulates the Datastore-Service. Only the methods required by the autoupdate-service are supported. This is currently only the getMany method.

Has to be created with NewDatastoreServer.

func NewDatastoreServer

func NewDatastoreServer(closed <-chan struct{}, data map[string][]byte) *DatastoreServer

NewDatastoreServer creates a new fake DatastoreServer.

It creates a webserver that handels get_many requests like the reald datastore-reader.

If the given channel is closed, the server shuts down.

func (*DatastoreServer) Requests

func (d *DatastoreServer) Requests() [][]string

Requests returns all keys that where requested.

func (*DatastoreServer) ResetRequests

func (d *DatastoreServer) ResetRequests()

ResetRequests resets the returnvalue of Requests().

func (*DatastoreServer) Send

func (d *DatastoreServer) Send(values map[string][]byte)

Send sends keys to the mock that can be received with Update().

func (*DatastoreServer) Update

func (d *DatastoreServer) Update(ctx context.Context) (map[string][]byte, error)

Update returnes keys that have changed. Blocks until keys are send with the Send-method.

type MockDatastore

type MockDatastore struct {
	*datastore.Datastore
	// contains filtered or unexported fields
}

MockDatastore implements the autoupdate.Datastore interface.

func NewMockDatastore

func NewMockDatastore(closed <-chan struct{}, data map[string][]byte) *MockDatastore

NewMockDatastore create a MockDatastore with data.

The function starts a mock datastore server in the background. It gets closed, when the closed channel is closed.

func (*MockDatastore) Get

func (d *MockDatastore) Get(ctx context.Context, keys ...string) (map[string][]byte, error)

Get calls the Get() method of the datastore.

func (*MockDatastore) InjectError

func (d *MockDatastore) InjectError(err error)

InjectError lets the next calls to Get() return the injected error.

func (*MockDatastore) KeysRequested

func (d *MockDatastore) KeysRequested(keys ...string) bool

KeysRequested returns true, if all given keys where requested.

func (*MockDatastore) Requests

func (d *MockDatastore) Requests() [][]string

Requests returns a list of all requested keys.

func (*MockDatastore) ResetRequests

func (d *MockDatastore) ResetRequests()

ResetRequests resets the list returned by Requests().

func (*MockDatastore) Send

func (d *MockDatastore) Send(data map[string][]byte)

Send updates the data.

This method is unblocking. If you want to fetch data afterwards, make sure to block until data is processed. For example with RegisterChanceListener.

func (*MockDatastore) Update

func (d *MockDatastore) Update(ctx context.Context) (map[string][]byte, error)

Update implements the datastore.Updater interface.

type Stub

type Stub map[string][]byte

Stub are data that can be used as a datastore value.

func (Stub) Get

func (s Stub) Get(_ context.Context, keys ...string) (map[string][]byte, error)

Get implements the Getter interface.

Jump to

Keyboard shortcuts

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