-
Notifications
You must be signed in to change notification settings - Fork 4
/
mock.go
54 lines (44 loc) · 1.3 KB
/
mock.go
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
50
51
52
53
54
package authenticator
import (
"fmt"
cfclient "github.com/cloudfoundry-community/go-cfclient"
)
type MockAuthenticator struct {
AllowedUsername string
AllowedPassword string
}
func (a *MockAuthenticator) Authenticate(username, password string) (User, error) {
if username == a.AllowedUsername && password == a.AllowedPassword {
return &MockUser{MockUsername: username}, nil
}
return nil, fmt.Errorf("password not allowed")
}
var _ Authenticator = (*MockAuthenticator)(nil)
type MockUser struct {
MockUsername string
MockServiceInstances []cfclient.ServiceInstance
MockServiceInstancesErr error
}
func (u *MockUser) Username() string {
return u.MockUsername
}
func (u *MockUser) ListServiceInstancesMatchingPlanGUIDs(planGuids []string) ([]cfclient.ServiceInstance, error) {
if u.MockServiceInstancesErr != nil {
return nil, u.MockServiceInstancesErr
}
matchingServiceInstances := []cfclient.ServiceInstance{}
for _, serviceInstance := range u.MockServiceInstances {
matches := false
for _, planGuid := range planGuids {
if serviceInstance.ServicePlanGuid == planGuid {
matches = true
break
}
}
if matches {
matchingServiceInstances = append(matchingServiceInstances, serviceInstance)
}
}
return matchingServiceInstances, nil
}
var _ User = (*MockUser)(nil)