@@ -17,6 +17,9 @@ limitations under the License.
17
17
package controller
18
18
19
19
import (
20
+ "encoding/json"
21
+ "fmt"
22
+ "reflect"
20
23
"testing"
21
24
22
25
"github.com/kubernetes-incubator/service-catalog/pkg/apis/servicecatalog/v1beta1"
@@ -33,7 +36,7 @@ func TestBuildOriginatingIdentity(t *testing.T) {
33
36
34
37
e := osb.OriginatingIdentity {
35
38
Platform : "kubernetes" ,
36
- Value :
`{"foo":["bar","baz"],"groups":["stuff-dev","main-eng"],"uid":"abcd-1234","username":"[email protected] "}` ,
39
+ Value :
`{extra: { "foo":["bar","baz"]} ,"groups":["stuff-dev","main-eng"],"uid":"abcd-1234","username":"[email protected] "}` ,
37
40
}
38
41
39
42
g , err := buildOriginatingIdentity (& userInfo )
@@ -46,7 +49,28 @@ func TestBuildOriginatingIdentity(t *testing.T) {
46
49
t .Fatalf ("Unexpected Platform, %s" , expectedGot (e .Platform , g .Platform ))
47
50
}
48
51
49
- if e .Value != g .Value {
50
- t .Fatalf ("Unexpected Value, %s" , expectedGot (e .Value , g .Value ))
52
+ var retUserInfo v1beta1.UserInfo
53
+ err = json .Unmarshal ([]byte (g .Value ), & retUserInfo )
54
+ if err != nil {
55
+ t .Fatalf ("Unexpected Error, %+v" , err )
56
+ }
57
+
58
+ if userInfo .Username != retUserInfo .Username {
59
+ t .Fatalf ("Unexpected Value Username, %s" , expectedGot (userInfo .Username , retUserInfo .Username ))
60
+ }
61
+ if userInfo .UID != retUserInfo .UID {
62
+ t .Fatalf ("Unexpected Value UID, %s" , expectedGot (userInfo .UID , retUserInfo .UID ))
63
+ }
64
+
65
+ if ! reflect .DeepEqual (userInfo .Groups , retUserInfo .Groups ) {
66
+ t .Fatalf ("Unexpected Value Groups, %s" , expectedGot (fmt .Sprintf ("%#v" , userInfo .Groups ), fmt .Sprintf ("%#v" , retUserInfo .Groups )))
67
+ }
68
+
69
+ if extras , ok := retUserInfo .Extra ["foo" ]; ! ok {
70
+ t .Fatalf ("Unexpected Value extras, %s" , expectedGot (fmt .Sprintf ("%#v" , userInfo .Extra ), fmt .Sprintf ("%#v" , retUserInfo .Extra )))
71
+ } else {
72
+ if ! reflect .DeepEqual (extras , userInfo .Extra ["foo" ]) {
73
+ t .Fatalf ("Unexpected Value extras, %s" , expectedGot (fmt .Sprintf ("%#v" , userInfo .Extra ), fmt .Sprintf ("%#v" , retUserInfo .Extra )))
74
+ }
51
75
}
52
76
}
0 commit comments