summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/db/testing.go
diff options
context:
space:
mode:
Diffstat (limited to 'src/k8splugin/db/testing.go')
-rw-r--r--src/k8splugin/db/testing.go42
1 files changed, 23 insertions, 19 deletions
diff --git a/src/k8splugin/db/testing.go b/src/k8splugin/db/testing.go
index 672fcbfb..4b7e6078 100644
--- a/src/k8splugin/db/testing.go
+++ b/src/k8splugin/db/testing.go
@@ -16,7 +16,8 @@ limitations under the License.
package db
import (
- "github.com/hashicorp/consul/api"
+ "encoding/json"
+ pkgerrors "github.com/pkg/errors"
)
//Creating an embedded interface via anonymous variable
@@ -24,42 +25,45 @@ import (
//interface even if we are not implementing all the methods in it
type MockDB struct {
Store
- Items api.KVPairs
+ Items map[string][]byte
Err error
}
-func (m *MockDB) Create(key string, value string) error {
+func (m *MockDB) Create(table, key, tag string, data interface{}) error {
return m.Err
}
-func (m *MockDB) Read(key string) (string, error) {
+// MockDB uses simple JSON and not BSON
+func (m *MockDB) Unmarshal(inp []byte, out interface{}) error {
+ err := json.Unmarshal(inp, out)
+ if err != nil {
+ return pkgerrors.Wrap(err, "Unmarshaling json")
+ }
+ return nil
+}
+
+func (m *MockDB) Read(table, key, tag string) ([]byte, error) {
if m.Err != nil {
- return "", m.Err
+ return nil, m.Err
}
- for _, kvpair := range m.Items {
- if kvpair.Key == key {
- return string(kvpair.Value), nil
+ for k, v := range m.Items {
+ if k == key {
+ return v, nil
}
}
- return "", nil
+ return nil, m.Err
}
-func (m *MockDB) Delete(key string) error {
+func (m *MockDB) Delete(table, key, tag string) error {
return m.Err
}
-func (m *MockDB) ReadAll(prefix string) ([]string, error) {
+func (m *MockDB) ReadAll(table, tag string) (map[string][]byte, error) {
if m.Err != nil {
- return []string{}, m.Err
- }
-
- var res []string
-
- for _, keypair := range m.Items {
- res = append(res, keypair.Key)
+ return nil, m.Err
}
- return res, nil
+ return m.Items, nil
}