summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/xordataexchange/crypt/backend/mock
diff options
context:
space:
mode:
authorWim <wim@42.be>2018-03-04 23:46:13 +0100
committerWim <wim@42.be>2018-03-04 23:46:13 +0100
commit25a72113b122f984c904b24c4af23a1cba1eff45 (patch)
treef0fb7067d7c958d60ac964afa5b8d5fb79ebc339 /vendor/github.com/xordataexchange/crypt/backend/mock
parent79c4ad5015bd2be47b32141c6d53f0d128bf865b (diff)
downloadmatterbridge-msglm-25a72113b122f984c904b24c4af23a1cba1eff45.tar.gz
matterbridge-msglm-25a72113b122f984c904b24c4af23a1cba1eff45.tar.bz2
matterbridge-msglm-25a72113b122f984c904b24c4af23a1cba1eff45.zip
Add vendor files for spf13/viper
Diffstat (limited to 'vendor/github.com/xordataexchange/crypt/backend/mock')
-rw-r--r--vendor/github.com/xordataexchange/crypt/backend/mock/mock.go61
1 files changed, 61 insertions, 0 deletions
diff --git a/vendor/github.com/xordataexchange/crypt/backend/mock/mock.go b/vendor/github.com/xordataexchange/crypt/backend/mock/mock.go
new file mode 100644
index 00000000..68a9b1c7
--- /dev/null
+++ b/vendor/github.com/xordataexchange/crypt/backend/mock/mock.go
@@ -0,0 +1,61 @@
+package mock
+
+import (
+ "errors"
+ "path"
+ "strings"
+ "time"
+
+ "github.com/xordataexchange/crypt/backend"
+)
+
+var mockedStore map[string][]byte
+
+type Client struct{}
+
+func New(machines []string) (*Client, error) {
+ if mockedStore == nil {
+ mockedStore = make(map[string][]byte, 2)
+ }
+ return &Client{}, nil
+}
+
+func (c *Client) Get(key string) ([]byte, error) {
+ if v, ok := mockedStore[key]; ok {
+ return v, nil
+ }
+ err := errors.New("Could not find key: " + key)
+ return nil, err
+}
+
+func (c *Client) List(key string) (backend.KVPairs, error) {
+ var list backend.KVPairs
+ dir := path.Clean(key) + "/"
+ for k, v := range mockedStore {
+ if strings.HasPrefix(k, dir) {
+ list = append(list, &backend.KVPair{Key: k, Value: v})
+ }
+ }
+ return list, nil
+}
+
+func (c *Client) Set(key string, value []byte) error {
+ mockedStore[key] = value
+ return nil
+}
+
+func (c *Client) Watch(key string, stop chan bool) <-chan *backend.Response {
+ respChan := make(chan *backend.Response, 0)
+ go func() {
+ for {
+ b, err := c.Get(key)
+ if err != nil {
+ respChan <- &backend.Response{nil, err}
+ time.Sleep(time.Second * 5)
+ continue
+ }
+ respChan <- &backend.Response{b, nil}
+ }
+ }()
+ return respChan
+}