1+ // +build go1.8
2+
13package cognitoidentity_test
24
35import (
@@ -10,47 +12,68 @@ import (
1012
1113var svc = cognitoidentity .New (unit .Config ())
1214
13- func TestUnsignedRequest_GetID (t * testing.T ) {
14- req := svc .GetIdRequest (& cognitoidentity.GetIdInput {
15- IdentityPoolId : aws .String ("IdentityPoolId" ),
16- })
17-
18- err := req .Sign ()
19- if err != nil {
20- t .Errorf ("expected no error, but received %v" , err )
21- }
22-
23- if e , a := "" , req .HTTPRequest .Header .Get ("Authorization" ); e != a {
24- t .Errorf ("expected empty value '%v', but received, %v" , e , a )
25- }
26- }
27-
28- func TestUnsignedRequest_GetOpenIDToken (t * testing.T ) {
29- req := svc .GetOpenIdTokenRequest (& cognitoidentity.GetOpenIdTokenInput {
30- IdentityId : aws .String ("IdentityId" ),
31- })
32-
33- err := req .Sign ()
34- if err != nil {
35- t .Errorf ("expected no error, but received %v" , err )
15+ func TestUnsignedRequests (t * testing.T ) {
16+ type reqSigner interface {
17+ Sign () error
3618 }
3719
38- if e , a := "" , req .HTTPRequest .Header .Get ("Authorization" ); e != a {
39- t .Errorf ("expected empty value '%v', but received, %v" , e , a )
20+ cases := map [string ]struct {
21+ ReqFn func () reqSigner
22+ }{
23+ "GetId" : {
24+ ReqFn : func () reqSigner {
25+ req := svc .GetIdRequest (& cognitoidentity.GetIdInput {
26+ IdentityPoolId : aws .String ("IdentityPoolId" ),
27+ })
28+ return req
29+ },
30+ },
31+ "GetOpenIdToken" : {
32+ ReqFn : func () reqSigner {
33+ req := svc .GetOpenIdTokenRequest (& cognitoidentity.GetOpenIdTokenInput {
34+ IdentityId : aws .String ("IdentityId" ),
35+ })
36+ return req
37+ },
38+ },
39+ "UnlinkIdentity" : {
40+ ReqFn : func () reqSigner {
41+ req := svc .UnlinkIdentityRequest (& cognitoidentity.UnlinkIdentityInput {
42+ IdentityId : aws .String ("IdentityId" ),
43+ Logins : map [string ]string {},
44+ LoginsToRemove : []string {},
45+ })
46+ return req
47+ },
48+ },
49+ "GetCredentialsForIdentity" : {
50+ ReqFn : func () reqSigner {
51+ req := svc .GetCredentialsForIdentityRequest (& cognitoidentity.GetCredentialsForIdentityInput {
52+ IdentityId : aws .String ("IdentityId" ),
53+ })
54+ return req
55+ },
56+ },
4057 }
41- }
4258
43- func TestUnsignedRequest_GetCredentialsForIdentity (t * testing.T ) {
44- req := svc .GetCredentialsForIdentityRequest (& cognitoidentity.GetCredentialsForIdentityInput {
45- IdentityId : aws .String ("IdentityId" ),
46- })
59+ for cn , c := range cases {
60+ t .Run (cn , func (t * testing.T ) {
61+ req := c .ReqFn ()
62+ err := req .Sign ()
63+ if err != nil {
64+ t .Errorf ("expected no error, but received %v" , err )
65+ }
4766
48- err := req .Sign ()
49- if err != nil {
50- t .Errorf ("expected no error, but received %v" , err )
51- }
67+ switch tv := req .(type ) {
68+ case cognitoidentity.GetIdRequest :
69+ if e , a := aws .AnonymousCredentials , tv .Config .Credentials ; e != a {
70+ t .Errorf ("expect request to use anonymous credentias, %v" , a )
71+ }
72+ if e , a := "" , tv .HTTPRequest .Header .Get ("Authorization" ); e != a {
73+ t .Errorf ("expected empty value '%v', but received, %v" , e , a )
74+ }
75+ }
5276
53- if e , a := "" , req .HTTPRequest .Header .Get ("Authorization" ); e != a {
54- t .Errorf ("expected empty value '%v', but received, %v" , e , a )
77+ })
5578 }
5679}
0 commit comments