1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49
|
package agent
import (
"context"
)
type MockClient struct {
NamespaceStore map[string]struct{}
ApplyRecorder string
MockError error
}
func NewMockClient() *MockClient {
return &MockClient{
NamespaceStore: map[string]struct{}{},
}
}
func (m *MockClient) NamespaceExists(_ context.Context, name string) (bool, error) {
_, ok := m.NamespaceStore[name]
return ok, nil
}
func (m *MockClient) CreateNamespace(_ context.Context, name string) error {
m.NamespaceStore[name] = struct{}{}
return nil
}
func (m *MockClient) DeleteNamespace(_ context.Context, name string) error {
delete(m.NamespaceStore, name)
return nil
}
func (m *MockClient) Apply(_ context.Context, config string) <-chan error {
m.ApplyRecorder = config
if m.MockError != nil {
errorCh := make(chan error)
go func() {
defer close(errorCh)
errorCh <- m.MockError
m.MockError = nil
}()
return errorCh
}
return nil
}
|