43 lines
1 KiB
Go
43 lines
1 KiB
Go
|
package test
|
||
|
|
||
|
import "github.com/dexidp/dex/storage"
|
||
|
|
||
|
type MockBackendService struct {
|
||
|
Connectors map[string]storage.Connector
|
||
|
ListError error
|
||
|
GetError error
|
||
|
AddError error
|
||
|
RemoveError error
|
||
|
}
|
||
|
|
||
|
func (mbs *MockBackendService) ListConnectors() ([]storage.Connector, error) {
|
||
|
var res []storage.Connector
|
||
|
for _, c := range mbs.Connectors {
|
||
|
res = append(res, c)
|
||
|
}
|
||
|
return res, mbs.ListError
|
||
|
}
|
||
|
|
||
|
func (mbs *MockBackendService) GetConnector(connectorID string) (storage.Connector, error) {
|
||
|
if res, ok := mbs.Connectors[connectorID]; ok {
|
||
|
return res, mbs.GetError
|
||
|
}
|
||
|
return storage.Connector{}, storage.ErrNotFound
|
||
|
}
|
||
|
|
||
|
func (mbs *MockBackendService) AddConnector(config storage.Connector) error {
|
||
|
if _, ok := mbs.Connectors[config.ID]; ok {
|
||
|
return storage.ErrAlreadyExists
|
||
|
}
|
||
|
if mbs.AddError != nil {
|
||
|
return mbs.AddError
|
||
|
}
|
||
|
mbs.Connectors[config.ID] = config
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func (mbs *MockBackendService) RemoveConnector(connectorID string) error {
|
||
|
delete(mbs.Connectors, connectorID)
|
||
|
return mbs.RemoveError
|
||
|
}
|