forked from openshift/origin
-
Notifications
You must be signed in to change notification settings - Fork 0
/
identity.go
75 lines (61 loc) · 1.97 KB
/
identity.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package test
import (
kerrs "k8s.io/apimachinery/pkg/api/errors"
metav1 "k8s.io/apimachinery/pkg/apis/meta/v1"
userapi "github.com/openshift/origin/pkg/user/apis/user"
"github.com/openshift/origin/pkg/user/generated/internalclientset/typed/user/internalversion/fake"
)
type Action struct {
Name string
Object interface{}
}
type IdentityRegistry struct {
*fake.FakeIdentities
GetErr map[string]error
GetIdentities map[string]*userapi.Identity
CreateErr error
CreateIdentity *userapi.Identity
UpdateErr error
UpdateIdentity *userapi.Identity
ListErr error
ListIdentity *userapi.IdentityList
Actions *[]Action
}
func NewIdentityRegistry() *IdentityRegistry {
return &IdentityRegistry{
GetErr: map[string]error{},
GetIdentities: map[string]*userapi.Identity{},
Actions: &[]Action{},
}
}
func (r *IdentityRegistry) Get(name string, options metav1.GetOptions) (*userapi.Identity, error) {
*r.Actions = append(*r.Actions, Action{"GetIdentity", name})
if identity, ok := r.GetIdentities[name]; ok {
return identity, nil
}
if err, ok := r.GetErr[name]; ok {
return nil, err
}
return nil, kerrs.NewNotFound(userapi.Resource("identity"), name)
}
func (r *IdentityRegistry) Create(u *userapi.Identity) (*userapi.Identity, error) {
*r.Actions = append(*r.Actions, Action{"CreateIdentity", u})
if r.CreateIdentity == nil && r.CreateErr == nil {
return u, nil
}
return r.CreateIdentity, r.CreateErr
}
func (r *IdentityRegistry) Update(u *userapi.Identity) (*userapi.Identity, error) {
*r.Actions = append(*r.Actions, Action{"UpdateIdentity", u})
if r.UpdateIdentity == nil && r.UpdateErr == nil {
return u, nil
}
return r.UpdateIdentity, r.UpdateErr
}
func (r *IdentityRegistry) List(options metav1.ListOptions) (*userapi.IdentityList, error) {
*r.Actions = append(*r.Actions, Action{"ListIdentities", options})
if r.ListIdentity == nil && r.ListErr == nil {
return &userapi.IdentityList{}, nil
}
return r.ListIdentity, r.ListErr
}