@@ -15,7 +15,6 @@ package apns
15
15
16
16
import (
17
17
"bytes"
18
- "context"
19
18
"io"
20
19
"net/http"
21
20
"strings"
@@ -52,7 +51,7 @@ func TestInit(t *testing.T) {
52
51
},
53
52
}}
54
53
binding := NewAPNS (testLogger ).(* APNS )
55
- err := binding .Init (context . Background (), metadata )
54
+ err := binding .Init (t . Context (), metadata )
56
55
require .NoError (t , err )
57
56
assert .Equal (t , developmentPrefix , binding .urlPrefix )
58
57
})
@@ -67,7 +66,7 @@ func TestInit(t *testing.T) {
67
66
},
68
67
}}
69
68
binding := NewAPNS (testLogger ).(* APNS )
70
- err := binding .Init (context . Background (), metadata )
69
+ err := binding .Init (t . Context (), metadata )
71
70
require .NoError (t , err )
72
71
assert .Equal (t , productionPrefix , binding .urlPrefix )
73
72
})
@@ -81,7 +80,7 @@ func TestInit(t *testing.T) {
81
80
},
82
81
}}
83
82
binding := NewAPNS (testLogger ).(* APNS )
84
- err := binding .Init (context . Background (), metadata )
83
+ err := binding .Init (t . Context (), metadata )
85
84
require .NoError (t , err )
86
85
assert .Equal (t , productionPrefix , binding .urlPrefix )
87
86
})
@@ -94,7 +93,7 @@ func TestInit(t *testing.T) {
94
93
},
95
94
}}
96
95
binding := NewAPNS (testLogger ).(* APNS )
97
- err := binding .Init (context . Background (), metadata )
96
+ err := binding .Init (t . Context (), metadata )
98
97
require .Error (t , err , "the key-id parameter is required" )
99
98
})
100
99
@@ -107,7 +106,7 @@ func TestInit(t *testing.T) {
107
106
},
108
107
}}
109
108
binding := NewAPNS (testLogger ).(* APNS )
110
- err := binding .Init (context . Background (), metadata )
109
+ err := binding .Init (t . Context (), metadata )
111
110
require .NoError (t , err )
112
111
assert .Equal (t , testKeyID , binding .authorizationBuilder .keyID )
113
112
})
@@ -120,7 +119,7 @@ func TestInit(t *testing.T) {
120
119
},
121
120
}}
122
121
binding := NewAPNS (testLogger ).(* APNS )
123
- err := binding .Init (context . Background (), metadata )
122
+ err := binding .Init (t . Context (), metadata )
124
123
require .Error (t , err , "the team-id parameter is required" )
125
124
})
126
125
@@ -133,7 +132,7 @@ func TestInit(t *testing.T) {
133
132
},
134
133
}}
135
134
binding := NewAPNS (testLogger ).(* APNS )
136
- err := binding .Init (context . Background (), metadata )
135
+ err := binding .Init (t . Context (), metadata )
137
136
require .NoError (t , err )
138
137
assert .Equal (t , testTeamID , binding .authorizationBuilder .teamID )
139
138
})
@@ -146,7 +145,7 @@ func TestInit(t *testing.T) {
146
145
},
147
146
}}
148
147
binding := NewAPNS (testLogger ).(* APNS )
149
- err := binding .Init (context . Background (), metadata )
148
+ err := binding .Init (t . Context (), metadata )
150
149
require .Error (t , err , "the private-key parameter is required" )
151
150
})
152
151
@@ -159,7 +158,7 @@ func TestInit(t *testing.T) {
159
158
},
160
159
}}
161
160
binding := NewAPNS (testLogger ).(* APNS )
162
- err := binding .Init (context . Background (), metadata )
161
+ err := binding .Init (t . Context (), metadata )
163
162
require .NoError (t , err )
164
163
assert .NotNil (t , binding .authorizationBuilder .privateKey )
165
164
})
@@ -192,7 +191,7 @@ func TestInvoke(t *testing.T) {
192
191
t .Run ("operation must be create" , func (t * testing.T ) {
193
192
testBinding := makeTestBinding (t , testLogger )
194
193
req := & bindings.InvokeRequest {Operation : bindings .DeleteOperation }
195
- _ , err := testBinding .Invoke (context . TODO (), req )
194
+ _ , err := testBinding .Invoke (t . Context (), req )
196
195
require .Error (t , err , "operation not supported: delete" )
197
196
})
198
197
@@ -202,7 +201,7 @@ func TestInvoke(t *testing.T) {
202
201
Operation : bindings .CreateOperation ,
203
202
Metadata : map [string ]string {},
204
203
}
205
- _ , err := testBinding .Invoke (context . TODO (), req )
204
+ _ , err := testBinding .Invoke (t . Context (), req )
206
205
require .Error (t , err , "the device-token parameter is required" )
207
206
})
208
207
@@ -213,7 +212,7 @@ func TestInvoke(t *testing.T) {
213
212
214
213
return successResponse ()
215
214
})
216
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
215
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
217
216
})
218
217
219
218
t .Run ("the push type header is sent" , func (t * testing.T ) {
@@ -224,7 +223,7 @@ func TestInvoke(t *testing.T) {
224
223
225
224
return successResponse ()
226
225
})
227
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
226
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
228
227
})
229
228
230
229
t .Run ("the message ID is sent" , func (t * testing.T ) {
@@ -235,7 +234,7 @@ func TestInvoke(t *testing.T) {
235
234
236
235
return successResponse ()
237
236
})
238
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
237
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
239
238
})
240
239
241
240
t .Run ("the expiration is sent" , func (t * testing.T ) {
@@ -246,7 +245,7 @@ func TestInvoke(t *testing.T) {
246
245
247
246
return successResponse ()
248
247
})
249
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
248
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
250
249
})
251
250
252
251
t .Run ("the priority is sent" , func (t * testing.T ) {
@@ -257,7 +256,7 @@ func TestInvoke(t *testing.T) {
257
256
258
257
return successResponse ()
259
258
})
260
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
259
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
261
260
})
262
261
263
262
t .Run ("the topic is sent" , func (t * testing.T ) {
@@ -268,7 +267,7 @@ func TestInvoke(t *testing.T) {
268
267
269
268
return successResponse ()
270
269
})
271
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
270
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
272
271
})
273
272
274
273
t .Run ("the collapse ID is sent" , func (t * testing.T ) {
@@ -279,15 +278,15 @@ func TestInvoke(t *testing.T) {
279
278
280
279
return successResponse ()
281
280
})
282
- _ , _ = testBinding .Invoke (context . TODO (), successRequest )
281
+ _ , _ = testBinding .Invoke (t . Context (), successRequest )
283
282
})
284
283
285
284
t .Run ("the message ID is returned" , func (t * testing.T ) {
286
285
testBinding := makeTestBinding (t , testLogger )
287
286
testBinding .client = newTestClient (func (req * http.Request ) * http.Response {
288
287
return successResponse ()
289
288
})
290
- response , err := testBinding .Invoke (context . TODO (), successRequest )
289
+ response , err := testBinding .Invoke (t . Context (), successRequest )
291
290
require .NoError (t , err )
292
291
assert .NotNil (t , response .Data )
293
292
var body notificationResponse
@@ -307,7 +306,7 @@ func TestInvoke(t *testing.T) {
307
306
Body : io .NopCloser (strings .NewReader (body )),
308
307
}
309
308
})
310
- _ , err := testBinding .Invoke (context . TODO (), successRequest )
309
+ _ , err := testBinding .Invoke (t . Context (), successRequest )
311
310
require .Error (t , err , "BadDeviceToken" )
312
311
})
313
312
}
@@ -322,7 +321,7 @@ func makeTestBinding(t *testing.T, log logger.Logger) *APNS {
322
321
privateKeyKey : testPrivateKey ,
323
322
},
324
323
}}
325
- err := testBinding .Init (context . Background (), bindingMetadata )
324
+ err := testBinding .Init (t . Context (), bindingMetadata )
326
325
require .NoError (t , err )
327
326
328
327
return testBinding
0 commit comments