func (s *MockStore) Close() error {
	return s.ErrClose
}
Close is not implemented.
package storage
import (
	"errors"
	"fmt"
	"strings"
	"sync"
	"github.com/hyperledger/aries-framework-go/spi/storage"
)
const (
	expressionTagNameOnlyLength     = 1
	expressionTagNameAndValueLength = 2
)
var (
	errInvalidQueryExpressionFormat = errors.New("invalid expression format. " +
		"it must be in the following format: TagName:TagValue")
	errIteratorExhausted = errors.New("iterator is exhausted")
)
type MockStoreProvider struct {
	Store              *MockStore
	Custom             storage.Store
	ErrOpenStoreHandle error
	ErrSetStoreConfig  error
	ErrClose           error
	ErrCloseStore      error
	FailNamespace      string
}
func NewMockStoreProvider() *MockStoreProvider {
	return &MockStoreProvider{Store: &MockStore{
		Store: make(map[string]DBEntry),
	}}
}
func NewCustomMockStoreProvider(customStore storage.Store) *MockStoreProvider {
	return &MockStoreProvider{Custom: customStore}
}
func (s *MockStoreProvider) OpenStore(name string) (storage.Store, error) {
	if name == s.FailNamespace {
		return nil, fmt.Errorf("failed to open store for name space %s", name)
	}
	if s.Custom != nil {
		return s.Custom, s.ErrOpenStoreHandle
	}
	return s.Store, s.ErrOpenStoreHandle
}
func (s *MockStoreProvider) SetStoreConfig(name string, config storage.StoreConfiguration) error {
	return s.ErrSetStoreConfig
}
func (s *MockStoreProvider) GetStoreConfig(name string) (storage.StoreConfiguration, error) {
	panic("implement me")
}
func (s *MockStoreProvider) GetOpenStores() []storage.Store {
	panic("implement me")
}
func (s *MockStoreProvider) Close() error {
	return s.ErrClose
}
func (s *MockStoreProvider) CloseStore(name string) error {
	return s.ErrCloseStore
}
type DBEntry struct {
	Value []byte
	Tags  []storage.Tag
}
type MockStore struct {
	Store     map[string]DBEntry
	lock      sync.RWMutex
	ErrPut    error
	ErrGet    error
	ErrDelete error
	ErrQuery  error
	ErrNext   error
	ErrValue  error
	ErrKey    error
	ErrBatch  error
	ErrClose  error
}
func (s *MockStore) Put(k string, v []byte, tags ...storage.Tag) error {
	if k == "" {
		return errors.New("key is mandatory")
	}
	if s.ErrPut != nil {
		return s.ErrPut
	}
	s.lock.Lock()
	s.Store[k] = DBEntry{
		Value: v,
		Tags:  tags,
	}
	s.lock.Unlock()
	return s.ErrPut
}
func (s *MockStore) Get(k string) ([]byte, error) {
	if s.ErrGet != nil {
		return nil, s.ErrGet
	}
	s.lock.RLock()
	defer s.lock.RUnlock()
	entry, ok := s.Store[k]
	if !ok {
		return nil, storage.ErrDataNotFound
	}
	return entry.Value, s.ErrGet
}
func (s *MockStore) GetTags(key string) ([]storage.Tag, error) {
	panic("implement me")
}
func (s *MockStore) GetBulk(keys ...string) ([][]byte, error) {
	panic("implement me")
}
func (s *MockStore) Query(expression string, _ ...storage.QueryOption) (storage.Iterator, error) {
	if s.ErrQuery != nil {
		return nil, s.ErrQuery
	}
	if expression == "" {
		return nil, errInvalidQueryExpressionFormat
	}
	expressionSplit := strings.Split(expression, ":")
	switch len(expressionSplit) {
	case expressionTagNameOnlyLength:
		expressionTagName := expressionSplit[0]
		s.lock.RLock()
		defer s.lock.RUnlock()
		keys, dbEntries := s.getMatchingKeysAndDBEntries(expressionTagName, "")
		return &iterator{keys: keys, dbEntries: dbEntries, errNext: s.ErrNext, errValue: s.ErrValue, errKey: s.ErrKey}, nil
	case expressionTagNameAndValueLength:
		expressionTagName := expressionSplit[0]
		expressionTagValue := expressionSplit[1]
		s.lock.RLock()
		defer s.lock.RUnlock()
		keys, dbEntries := s.getMatchingKeysAndDBEntries(expressionTagName, expressionTagValue)
		return &iterator{keys: keys, dbEntries: dbEntries, errNext: s.ErrNext, errValue: s.ErrValue, errKey: s.ErrKey}, nil
	default:
		return nil, errInvalidQueryExpressionFormat
	}
}
func (s *MockStore) Delete(k string) error {
	s.lock.Lock()
	delete(s.Store, k)
	s.lock.Unlock()
	return s.ErrDelete
}
func (s *MockStore) Batch(operations []storage.Operation) error {
	if s.ErrBatch != nil {
		return s.ErrBatch
	}
	s.lock.Lock()
	defer s.lock.Unlock()
	for _, op := range operations {
		s.Store[op.Key] = DBEntry{
			Value: op.Value,
			Tags:  op.Tags,
		}
	}
	return nil
}
func (s *MockStore) Flush() error {
	panic("implement me")
}