-
Notifications
You must be signed in to change notification settings - Fork 96
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Maciej Winnicki
committed
Sep 26, 2017
1 parent
311b2bf
commit 3f6808f
Showing
9 changed files
with
255 additions
and
49 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package kv | ||
package embedded | ||
|
||
import ( | ||
"net/url" | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
//go:generate mockgen -package mock -destination ./store.go github.com/serverless/libkv/store Store | ||
|
||
package mock |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,157 @@ | ||
// Automatically generated by MockGen. DO NOT EDIT! | ||
// Source: github.com/serverless/libkv/store (interfaces: Store) | ||
|
||
package mock | ||
|
||
import ( | ||
gomock "github.com/golang/mock/gomock" | ||
store "github.com/serverless/libkv/store" | ||
) | ||
|
||
// Mock of Store interface | ||
type MockStore struct { | ||
ctrl *gomock.Controller | ||
recorder *_MockStoreRecorder | ||
} | ||
|
||
// Recorder for MockStore (not exported) | ||
type _MockStoreRecorder struct { | ||
mock *MockStore | ||
} | ||
|
||
func NewMockStore(ctrl *gomock.Controller) *MockStore { | ||
mock := &MockStore{ctrl: ctrl} | ||
mock.recorder = &_MockStoreRecorder{mock} | ||
return mock | ||
} | ||
|
||
func (_m *MockStore) EXPECT() *_MockStoreRecorder { | ||
return _m.recorder | ||
} | ||
|
||
func (_m *MockStore) AtomicDelete(_param0 string, _param1 *store.KVPair) (bool, error) { | ||
ret := _m.ctrl.Call(_m, "AtomicDelete", _param0, _param1) | ||
ret0, _ := ret[0].(bool) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) AtomicDelete(arg0, arg1 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "AtomicDelete", arg0, arg1) | ||
} | ||
|
||
func (_m *MockStore) AtomicPut(_param0 string, _param1 []byte, _param2 *store.KVPair, _param3 *store.WriteOptions) (bool, *store.KVPair, error) { | ||
ret := _m.ctrl.Call(_m, "AtomicPut", _param0, _param1, _param2, _param3) | ||
ret0, _ := ret[0].(bool) | ||
ret1, _ := ret[1].(*store.KVPair) | ||
ret2, _ := ret[2].(error) | ||
return ret0, ret1, ret2 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) AtomicPut(arg0, arg1, arg2, arg3 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "AtomicPut", arg0, arg1, arg2, arg3) | ||
} | ||
|
||
func (_m *MockStore) Close() { | ||
_m.ctrl.Call(_m, "Close") | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) Close() *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Close") | ||
} | ||
|
||
func (_m *MockStore) Delete(_param0 string) error { | ||
ret := _m.ctrl.Call(_m, "Delete", _param0) | ||
ret0, _ := ret[0].(error) | ||
return ret0 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) Delete(arg0 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Delete", arg0) | ||
} | ||
|
||
func (_m *MockStore) DeleteTree(_param0 string) error { | ||
ret := _m.ctrl.Call(_m, "DeleteTree", _param0) | ||
ret0, _ := ret[0].(error) | ||
return ret0 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) DeleteTree(arg0 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "DeleteTree", arg0) | ||
} | ||
|
||
func (_m *MockStore) Exists(_param0 string) (bool, error) { | ||
ret := _m.ctrl.Call(_m, "Exists", _param0) | ||
ret0, _ := ret[0].(bool) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) Exists(arg0 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Exists", arg0) | ||
} | ||
|
||
func (_m *MockStore) Get(_param0 string) (*store.KVPair, error) { | ||
ret := _m.ctrl.Call(_m, "Get", _param0) | ||
ret0, _ := ret[0].(*store.KVPair) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) Get(arg0 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Get", arg0) | ||
} | ||
|
||
func (_m *MockStore) List(_param0 string) ([]*store.KVPair, error) { | ||
ret := _m.ctrl.Call(_m, "List", _param0) | ||
ret0, _ := ret[0].([]*store.KVPair) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) List(arg0 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "List", arg0) | ||
} | ||
|
||
func (_m *MockStore) NewLock(_param0 string, _param1 *store.LockOptions) (store.Locker, error) { | ||
ret := _m.ctrl.Call(_m, "NewLock", _param0, _param1) | ||
ret0, _ := ret[0].(store.Locker) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) NewLock(arg0, arg1 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "NewLock", arg0, arg1) | ||
} | ||
|
||
func (_m *MockStore) Put(_param0 string, _param1 []byte, _param2 *store.WriteOptions) error { | ||
ret := _m.ctrl.Call(_m, "Put", _param0, _param1, _param2) | ||
ret0, _ := ret[0].(error) | ||
return ret0 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) Put(arg0, arg1, arg2 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Put", arg0, arg1, arg2) | ||
} | ||
|
||
func (_m *MockStore) Watch(_param0 string, _param1 <-chan struct{}) (<-chan *store.KVPair, error) { | ||
ret := _m.ctrl.Call(_m, "Watch", _param0, _param1) | ||
ret0, _ := ret[0].(<-chan *store.KVPair) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) Watch(arg0, arg1 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "Watch", arg0, arg1) | ||
} | ||
|
||
func (_m *MockStore) WatchTree(_param0 string, _param1 <-chan struct{}) (<-chan []*store.KVPair, error) { | ||
ret := _m.ctrl.Call(_m, "WatchTree", _param0, _param1) | ||
ret0, _ := ret[0].(<-chan []*store.KVPair) | ||
ret1, _ := ret[1].(error) | ||
return ret0, ret1 | ||
} | ||
|
||
func (_mr *_MockStoreRecorder) WatchTree(arg0, arg1 interface{}) *gomock.Call { | ||
return _mr.mock.ctrl.RecordCall(_mr.mock, "WatchTree", arg0, arg1) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
package kv | ||
|
||
import ( | ||
"errors" | ||
"testing" | ||
|
||
"github.com/golang/mock/gomock" | ||
"github.com/serverless/event-gateway/functions/mock" | ||
"github.com/serverless/libkv/store" | ||
"github.com/stretchr/testify/assert" | ||
) | ||
|
||
func TestPrefixedStoreList(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
kvs := []*store.KVPair{ | ||
&store.KVPair{Key: "testroot/", Value: []byte(nil)}, | ||
&store.KVPair{Key: "testroot/testdir/key1", Value: []byte("value1")}, | ||
&store.KVPair{Key: "testroot/testdir/key2", Value: []byte("value2")}, | ||
} | ||
kv := mock.NewMockStore(ctrl) | ||
kv.EXPECT().List("testroot/testdir").Return(kvs, nil) | ||
ps := NewPrefixedStore("testroot", kv) | ||
|
||
values, err := ps.List("testdir") | ||
assert.Nil(t, err) | ||
assert.Equal(t, []*store.KVPair{ | ||
&store.KVPair{Key: "testdir/key1", Value: []byte("value1")}, | ||
&store.KVPair{Key: "testdir/key2", Value: []byte("value2")}, | ||
}, values) | ||
} | ||
|
||
func TestPrefixedStoreList_Error(t *testing.T) { | ||
ctrl := gomock.NewController(t) | ||
defer ctrl.Finish() | ||
|
||
kv := mock.NewMockStore(ctrl) | ||
kv.EXPECT().List("testroot/key").Return(nil, errors.New("KV error")) | ||
ps := NewPrefixedStore("testroot", kv) | ||
|
||
values, err := ps.List("key") | ||
assert.Nil(t, values) | ||
assert.EqualError(t, err, "KV error") | ||
} |
Oops, something went wrong.