summaryrefslogtreecommitdiffstats
path: root/src/k8splugin/db
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-01-23 12:09:42 -0800
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-01-23 12:09:46 -0800
commit704d7c52983cd935b48d4eb38108c758c7b6c67d (patch)
treef43035dc95795708c743a8e57d79c2a2d6876168 /src/k8splugin/db
parentf26259e651ee0be263a3398d2d0ca0eb27c8995c (diff)
Add support for tags in the mockdb
Add support for tags in mockdb. Needed for supporting unit tests where a method does multiple db calls using same uuid but different tags. Eg: Download methods Issue-ID: MULTICLOUD-455 Change-Id: I4eff8eeb00eac630205e4e186981a53a573b61fa Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/db')
-rw-r--r--src/k8splugin/db/testing.go16
1 files changed, 13 insertions, 3 deletions
diff --git a/src/k8splugin/db/testing.go b/src/k8splugin/db/testing.go
index 4b7e6078..003399af 100644
--- a/src/k8splugin/db/testing.go
+++ b/src/k8splugin/db/testing.go
@@ -25,7 +25,7 @@ import (
//interface even if we are not implementing all the methods in it
type MockDB struct {
Store
- Items map[string][]byte
+ Items map[string]map[string][]byte
Err error
}
@@ -49,7 +49,7 @@ func (m *MockDB) Read(table, key, tag string) ([]byte, error) {
for k, v := range m.Items {
if k == key {
- return v, nil
+ return v[tag], nil
}
}
@@ -65,5 +65,15 @@ func (m *MockDB) ReadAll(table, tag string) (map[string][]byte, error) {
return nil, m.Err
}
- return m.Items, nil
+ ret := make(map[string][]byte)
+
+ for k, v := range m.Items {
+ for k1, v1 := range v {
+ if k1 == tag {
+ ret[k] = v1
+ }
+ }
+ }
+
+ return ret, nil
}