@@ -76,15 +76,48 @@ func TestLoadConsumer(t *testing.T) {
76
76
assert .Equal (t , entities.Consumer {Id : "001" , Username : "Jon Doe" }, resp )
77
77
}
78
78
79
- /*
80
- func TestGetConsumer(t *testing.T) {
81
- assert.Equal(t, bridge.StepData{Method: "kong.client.get_consumer"}, getBack(func() { client.GetConsumer() }))
79
+ func TestAuthenticate (t * testing.T ) {
80
+ var consumer * entities.Consumer = & entities.Consumer {Id : "001" , Username : "Jon Doe" }
81
+ var credential * AuthenticatedCredential = & AuthenticatedCredential {Id : "000:00" , ConsumerId : "001" }
82
+
83
+ c := mockClient (t , []bridgetest.MockStep {
84
+ {Method : "kong.client.authenticate" ,
85
+ Args : & kong_plugin_protocol.AuthenticateArgs {
86
+ Consumer : & kong_plugin_protocol.Consumer {
87
+ Id : consumer .Id ,
88
+ CreatedAt : int64 (consumer .CreatedAt ),
89
+ Username : consumer .Username ,
90
+ CustomId : consumer .CustomId ,
91
+ Tags : consumer .Tags ,
92
+ },
93
+ Credential : & kong_plugin_protocol.AuthenticatedCredential {
94
+ Id : credential .Id ,
95
+ ConsumerId : credential .ConsumerId ,
96
+ },
97
+ },
98
+ Ret : nil ,
99
+ },
100
+ })
101
+
102
+ err := c .Authenticate (consumer , credential )
103
+
104
+ assert .NoError (t , err )
82
105
}
83
106
84
- func TestAuthenticate (t *testing.T) {
107
+ func TestAuthenticateNil (t * testing.T ) {
85
108
var consumer * entities.Consumer = nil
86
109
var credential * AuthenticatedCredential = nil
87
- assert.Equal(t, bridge.StepData{Method: "kong.client.authenticate", Args: []interface{}{consumer, credential}}, getBack(func() { client.Authenticate(nil, nil) }))
110
+
111
+ c := mockClient (t , nil )
112
+
113
+ err := c .Authenticate (consumer , credential )
114
+
115
+ assert .EqualError (t , err , "either credential or consumer must be provided" )
116
+ }
117
+
118
+ /*
119
+ func TestGetConsumer(t *testing.T) {
120
+ assert.Equal(t, bridge.StepData{Method: "kong.client.get_consumer"}, getBack(func() { client.GetConsumer() }))
88
121
}
89
122
90
123
func TestGetProtocol(t *testing.T) {
0 commit comments