4 Copyright 2018 Intel Corporation.
5 Licensed under the Apache License, Version 2.0 (the "License");
6 you may not use this file except in compliance with the License.
7 You may obtain a copy of the License at
8 http://www.apache.org/licenses/LICENSE-2.0
9 Unless required by applicable law or agreed to in writing, software
10 distributed under the License is distributed on an "AS IS" BASIS,
11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 See the License for the specific language governing permissions and
13 limitations under the License.
20 pkgerrors "github.com/pkg/errors"
23 //Creating an embedded interface via anonymous variable
24 //This allows us to make mockDB satisfy the DatabaseConnection
25 //interface even if we are not implementing all the methods in it
28 Items map[string]map[string][]byte
32 func (m *MockDB) Create(table, key, tag string, data interface{}) error {
36 // MockDB uses simple JSON and not BSON
37 func (m *MockDB) Unmarshal(inp []byte, out interface{}) error {
38 err := json.Unmarshal(inp, out)
40 return pkgerrors.Wrap(err, "Unmarshaling json")
45 func (m *MockDB) Read(table, key, tag string) ([]byte, error) {
50 for k, v := range m.Items {
59 func (m *MockDB) Delete(table, key, tag string) error {
63 func (m *MockDB) ReadAll(table, tag string) (map[string][]byte, error) {
68 ret := make(map[string][]byte)
70 for k, v := range m.Items {
71 for k1, v1 := range v {