polycule-connect/polyculeconnect/services/backend/test/mock.go
Melora Hugues 74cb316d78
All checks were successful
ci/woodpecker/push/test Pipeline was successful
ci/woodpecker/push/deploy Pipeline was successful
feat #43: add CLI commands to manage backends
2023-10-28 16:51:00 +02:00

42 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
}