cd381aea56
libnetwork/etchosts/etchosts_test.go:167:54: empty-lines: extra empty line at the end of a block (revive) libnetwork/osl/route_linux.go:185:74: empty-lines: extra empty line at the start of a block (revive) libnetwork/osl/sandbox_linux_test.go:323:36: empty-lines: extra empty line at the start of a block (revive) libnetwork/bitseq/sequence.go:412:48: empty-lines: extra empty line at the start of a block (revive) libnetwork/datastore/datastore_test.go:67:46: empty-lines: extra empty line at the end of a block (revive) libnetwork/datastore/mock_store.go:34:60: empty-lines: extra empty line at the end of a block (revive) libnetwork/iptables/firewalld.go:202:44: empty-lines: extra empty line at the end of a block (revive) libnetwork/iptables/firewalld_test.go:76:36: empty-lines: extra empty line at the end of a block (revive) libnetwork/iptables/iptables.go:256:67: empty-lines: extra empty line at the end of a block (revive) libnetwork/iptables/iptables.go:303:128: empty-lines: extra empty line at the start of a block (revive) libnetwork/networkdb/cluster.go:183:72: empty-lines: extra empty line at the end of a block (revive) libnetwork/ipams/null/null_test.go:44:38: empty-lines: extra empty line at the end of a block (revive) libnetwork/drivers/macvlan/macvlan_store.go:45:52: empty-lines: extra empty line at the end of a block (revive) libnetwork/ipam/allocator_test.go:1058:39: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/bridge/port_mapping.go:88:111: empty-lines: extra empty line at the end of a block (revive) libnetwork/drivers/bridge/link.go:26:90: empty-lines: extra empty line at the end of a block (revive) libnetwork/drivers/bridge/setup_ipv6_test.go:17:34: empty-lines: extra empty line at the end of a block (revive) libnetwork/drivers/bridge/setup_ip_tables.go:392:4: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/bridge/bridge.go:804:50: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/ov_serf.go:183:29: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/ov_utils.go:81:64: empty-lines: extra empty line at the end of a block (revive) libnetwork/drivers/overlay/peerdb.go:172:67: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/peerdb.go:209:67: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/peerdb.go:344:89: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/peerdb.go:436:63: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/overlay.go:183:36: empty-lines: extra empty line at the start of a block (revive) libnetwork/drivers/overlay/encryption.go:69:28: empty-lines: extra empty line at the end of a block (revive) libnetwork/drivers/overlay/ov_network.go:563:81: empty-lines: extra empty line at the start of a block (revive) libnetwork/default_gateway.go:32:43: empty-lines: extra empty line at the start of a block (revive) libnetwork/errors_test.go:9:40: empty-lines: extra empty line at the start of a block (revive) libnetwork/service_common.go:184:64: empty-lines: extra empty line at the end of a block (revive) libnetwork/endpoint.go:161:55: empty-lines: extra empty line at the end of a block (revive) libnetwork/store.go:320:33: empty-lines: extra empty line at the end of a block (revive) libnetwork/store_linux_test.go:11:38: empty-lines: extra empty line at the end of a block (revive) libnetwork/sandbox.go:571:36: empty-lines: extra empty line at the start of a block (revive) libnetwork/service_common.go:317:246: empty-lines: extra empty line at the start of a block (revive) libnetwork/endpoint.go:550:17: empty-lines: extra empty line at the end of a block (revive) libnetwork/sandbox_dns_unix.go:213:106: empty-lines: extra empty line at the start of a block (revive) libnetwork/controller.go:676:85: empty-lines: extra empty line at the end of a block (revive) libnetwork/agent.go:876:60: empty-lines: extra empty line at the end of a block (revive) libnetwork/resolver.go:324:69: empty-lines: extra empty line at the end of a block (revive) libnetwork/network.go:1153:92: empty-lines: extra empty line at the end of a block (revive) libnetwork/network.go:1955:67: empty-lines: extra empty line at the start of a block (revive) libnetwork/network.go:2235:9: empty-lines: extra empty line at the start of a block (revive) libnetwork/libnetwork_internal_test.go:336:26: empty-lines: extra empty line at the start of a block (revive) libnetwork/resolver_test.go:76:35: empty-lines: extra empty line at the end of a block (revive) libnetwork/libnetwork_test.go:303:38: empty-lines: extra empty line at the end of a block (revive) libnetwork/libnetwork_test.go:985:46: empty-lines: extra empty line at the end of a block (revive) libnetwork/ipam/allocator_test.go:1263:37: empty-lines: extra empty line at the start of a block (revive) libnetwork/errors_test.go:9:40: empty-lines: extra empty line at the end of a block (revive) Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
127 lines
3.4 KiB
Go
127 lines
3.4 KiB
Go
package datastore
|
|
|
|
import (
|
|
"errors"
|
|
|
|
"github.com/docker/docker/libnetwork/types"
|
|
"github.com/docker/libkv/store"
|
|
)
|
|
|
|
var (
|
|
// ErrNotImplemented exported
|
|
ErrNotImplemented = errors.New("Functionality not implemented")
|
|
)
|
|
|
|
// MockData exported
|
|
type MockData struct {
|
|
Data []byte
|
|
Index uint64
|
|
}
|
|
|
|
// MockStore exported
|
|
type MockStore struct {
|
|
db map[string]*MockData
|
|
}
|
|
|
|
// NewMockStore creates a Map backed Datastore that is useful for mocking
|
|
func NewMockStore() *MockStore {
|
|
db := make(map[string]*MockData)
|
|
return &MockStore{db}
|
|
}
|
|
|
|
// Get the value at "key", returns the last modified index
|
|
// to use in conjunction to CAS calls
|
|
func (s *MockStore) Get(key string) (*store.KVPair, error) {
|
|
mData := s.db[key]
|
|
if mData == nil {
|
|
return nil, nil
|
|
}
|
|
return &store.KVPair{Value: mData.Data, LastIndex: mData.Index}, nil
|
|
}
|
|
|
|
// Put a value at "key"
|
|
func (s *MockStore) Put(key string, value []byte, options *store.WriteOptions) error {
|
|
mData := s.db[key]
|
|
if mData == nil {
|
|
mData = &MockData{value, 0}
|
|
}
|
|
mData.Index = mData.Index + 1
|
|
s.db[key] = mData
|
|
return nil
|
|
}
|
|
|
|
// Delete a value at "key"
|
|
func (s *MockStore) Delete(key string) error {
|
|
delete(s.db, key)
|
|
return nil
|
|
}
|
|
|
|
// Exists checks that the key exists inside the store
|
|
func (s *MockStore) Exists(key string) (bool, error) {
|
|
_, ok := s.db[key]
|
|
return ok, nil
|
|
}
|
|
|
|
// List gets a range of values at "directory"
|
|
func (s *MockStore) List(prefix string) ([]*store.KVPair, error) {
|
|
return nil, ErrNotImplemented
|
|
}
|
|
|
|
// DeleteTree deletes a range of values at "directory"
|
|
func (s *MockStore) DeleteTree(prefix string) error {
|
|
delete(s.db, prefix)
|
|
return nil
|
|
}
|
|
|
|
// Watch a single key for modifications
|
|
func (s *MockStore) Watch(key string, stopCh <-chan struct{}) (<-chan *store.KVPair, error) {
|
|
return nil, ErrNotImplemented
|
|
}
|
|
|
|
// WatchTree triggers a watch on a range of values at "directory"
|
|
func (s *MockStore) WatchTree(prefix string, stopCh <-chan struct{}) (<-chan []*store.KVPair, error) {
|
|
return nil, ErrNotImplemented
|
|
}
|
|
|
|
// NewLock exposed
|
|
func (s *MockStore) NewLock(key string, options *store.LockOptions) (store.Locker, error) {
|
|
return nil, ErrNotImplemented
|
|
}
|
|
|
|
// AtomicPut put a value at "key" if the key has not been
|
|
// modified in the meantime, throws an error if this is the case
|
|
func (s *MockStore) AtomicPut(key string, newValue []byte, previous *store.KVPair, options *store.WriteOptions) (bool, *store.KVPair, error) {
|
|
mData := s.db[key]
|
|
|
|
if previous == nil {
|
|
if mData != nil {
|
|
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
|
|
} // Else OK.
|
|
} else {
|
|
if mData == nil {
|
|
return false, nil, types.BadRequestErrorf("atomic put failed because key exists")
|
|
}
|
|
if mData != nil && mData.Index != previous.LastIndex {
|
|
return false, nil, types.BadRequestErrorf("atomic put failed due to mismatched Index")
|
|
} // Else OK.
|
|
}
|
|
err := s.Put(key, newValue, nil)
|
|
if err != nil {
|
|
return false, nil, err
|
|
}
|
|
return true, &store.KVPair{Key: key, Value: newValue, LastIndex: s.db[key].Index}, nil
|
|
}
|
|
|
|
// AtomicDelete deletes a value at "key" if the key has not
|
|
// been modified in the meantime, throws an error if this is the case
|
|
func (s *MockStore) AtomicDelete(key string, previous *store.KVPair) (bool, error) {
|
|
mData := s.db[key]
|
|
if mData != nil && mData.Index != previous.LastIndex {
|
|
return false, types.BadRequestErrorf("atomic delete failed due to mismatched Index")
|
|
}
|
|
return true, s.Delete(key)
|
|
}
|
|
|
|
// Close closes the client connection
|
|
func (s *MockStore) Close() {
|
|
}
|