refactor(kv): split provide and configuration.
This commit is contained in:
parent
e3d1201b46
commit
be0dd71bb4
9 changed files with 944 additions and 546 deletions
|
@ -4,18 +4,9 @@ import (
|
|||
"errors"
|
||||
"strings"
|
||||
|
||||
"github.com/containous/traefik/types"
|
||||
"github.com/docker/libkv/store"
|
||||
)
|
||||
|
||||
type KvMock struct {
|
||||
Provider
|
||||
}
|
||||
|
||||
func (provider *KvMock) loadConfig() *types.Configuration {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Override Get/List to return a error
|
||||
type KvError struct {
|
||||
Get error
|
||||
|
@ -29,6 +20,20 @@ type Mock struct {
|
|||
WatchTreeMethod func() <-chan []*store.KVPair
|
||||
}
|
||||
|
||||
func newKvClientMock(kvPairs []*store.KVPair, err error) *Mock {
|
||||
mock := &Mock{
|
||||
KVPairs: kvPairs,
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
mock.Error = KvError{
|
||||
Get: err,
|
||||
List: err,
|
||||
}
|
||||
}
|
||||
return mock
|
||||
}
|
||||
|
||||
func (s *Mock) Put(key string, value []byte, opts *store.WriteOptions) error {
|
||||
return errors.New("Put not supported")
|
||||
}
|
||||
|
@ -82,9 +87,9 @@ func (s *Mock) List(prefix string, options *store.ReadOptions) ([]*store.KVPair,
|
|||
if err := s.Error.List; err != nil {
|
||||
return nil, err
|
||||
}
|
||||
kv := []*store.KVPair{}
|
||||
var kv []*store.KVPair
|
||||
for _, kvPair := range s.KVPairs {
|
||||
if strings.HasPrefix(kvPair.Key, prefix) && !strings.ContainsAny(strings.TrimPrefix(kvPair.Key, prefix), "/") {
|
||||
if strings.HasPrefix(kvPair.Key, prefix) && !strings.ContainsAny(strings.TrimPrefix(kvPair.Key, prefix), pathSeparator) {
|
||||
kv = append(kv, kvPair)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue