aboutsummaryrefslogtreecommitdiffstats
path: root/src/k8splugin/internal/db/testing.go
diff options
context:
space:
mode:
authorKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-15 15:03:01 -0700
committerKiran Kamineni <kiran.k.kamineni@intel.com>2019-03-25 14:41:34 -0700
commit037cfda2181e4995e4e2a47db6f1121b532b686b (patch)
treef9cb838fc5cc037c01a9f55f561c3b5621236667 /src/k8splugin/internal/db/testing.go
parent8cdd50b6a06aef5cb0541e74a07b10bd4b01b589 (diff)
Add support for composite keys
Composite keys help us store objects which are unique for a given set of pre-existing objects. Eg: Many profiles can exist for a definition and its key will have a definition name as a part of the composite key. P2: Use a predefined interface for keys instead of generic interfaceP{} P3: Add check for empty strings in stringer interface P5: Add appropriate keys in other packages. Issue-ID: MULTICLOUD-531 Change-Id: I314b1fbd718489ae8a45f0f38915c08ca32f9f43 Signed-off-by: Kiran Kamineni <kiran.k.kamineni@intel.com>
Diffstat (limited to 'src/k8splugin/internal/db/testing.go')
-rw-r--r--src/k8splugin/internal/db/testing.go18
1 files changed, 13 insertions, 5 deletions
diff --git a/src/k8splugin/internal/db/testing.go b/src/k8splugin/internal/db/testing.go
index a6c940ef..a411790e 100644
--- a/src/k8splugin/internal/db/testing.go
+++ b/src/k8splugin/internal/db/testing.go
@@ -20,6 +20,14 @@ import (
pkgerrors "github.com/pkg/errors"
)
+type mockKey struct {
+ Key string
+}
+
+func (m mockKey) String() string {
+ return m.Key
+}
+
//Creating an embedded interface via anonymous variable
//This allows us to make mockDB satisfy the DatabaseConnection
//interface even if we are not implementing all the methods in it
@@ -29,7 +37,7 @@ type MockDB struct {
Err error
}
-func (m *MockDB) Create(table, key, tag string, data interface{}) error {
+func (m *MockDB) Create(table string, key Key, tag string, data interface{}) error {
return m.Err
}
@@ -42,13 +50,13 @@ func (m *MockDB) Unmarshal(inp []byte, out interface{}) error {
return nil
}
-func (m *MockDB) Read(table, key, tag string) ([]byte, error) {
+func (m *MockDB) Read(table string, key Key, tag string) ([]byte, error) {
if m.Err != nil {
return nil, m.Err
}
for k, v := range m.Items {
- if k == key {
+ if k == key.String() {
return v[tag], nil
}
}
@@ -56,11 +64,11 @@ func (m *MockDB) Read(table, key, tag string) ([]byte, error) {
return nil, m.Err
}
-func (m *MockDB) Delete(table, key, tag string) error {
+func (m *MockDB) Delete(table string, key Key, tag string) error {
return m.Err
}
-func (m *MockDB) ReadAll(table, tag string) (map[string][]byte, error) {
+func (m *MockDB) ReadAll(table string, tag string) (map[string][]byte, error) {
if m.Err != nil {
return nil, m.Err
}