diff options
author | Victor Morales <victor.morales@intel.com> | 2018-12-15 00:34:27 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2018-12-15 00:34:27 +0000 |
commit | 2da9b6c0498528a6eac478fa7b334906457f7b82 (patch) | |
tree | be33f0fadf12c321c9a20eaf943eda5b43335948 /src/k8splugin/db/testing.go | |
parent | b878686931d404568af000df1f0f86927a730680 (diff) | |
parent | d203ccf9174e450b6f5a6a9aabea95b73c9973ff (diff) |
Merge "Migrating from consul to mongodb for backend"
Diffstat (limited to 'src/k8splugin/db/testing.go')
-rw-r--r-- | src/k8splugin/db/testing.go | 42 |
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 } |