You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
kratos/pkg/conf/paladin/mock.go

41 lines
683 B

6 years ago
package paladin
import (
"context"
)
var _ Client = &Mock{}
// Mock is Mock config client.
type Mock struct {
C chan Event
*Map
}
// NewMock new a config mock client.
func NewMock(vs map[string]string) *Mock {
values := make(map[string]*Value, len(vs))
for k, v := range vs {
values[k] = &Value{val: v, raw: v}
}
m := new(Map)
m.Store(values)
return &Mock{Map: m, C: make(chan Event)}
}
// GetAll return value map.
func (m *Mock) GetAll() *Map {
return m.Map
}
// WatchEvent watch multi key.
func (m *Mock) WatchEvent(ctx context.Context, key ...string) <-chan Event {
return m.C
}
// Close close watcher.
func (m *Mock) Close() error {
close(m.C)
return nil
}