@@ -275,26 +275,26 @@ const day = 24 * time.Hour
275
275
func TestExchangeRequest_JSONResponse_Expiry (t * testing.T ) {
276
276
seconds := int32 (day .Seconds ())
277
277
for _ , c := range []struct {
278
- name string
279
- expires string
280
- want bool
278
+ name string
279
+ expires string
280
+ want bool
281
+ nullExpires bool
281
282
}{
282
- {"normal" , fmt .Sprintf (`"expires_in": %d` , seconds ), true },
283
- {"paypal" , fmt .Sprintf (`"expires_in": "%d"` , seconds ), true },
284
- {"facebook" , fmt .Sprintf (`"expires": %d` , seconds ), true },
285
- {"issue_239" , fmt .Sprintf (`"expires_in": null, "expires": %d` , seconds ), true },
286
-
287
- {"wrong_type" , `"expires": false` , false },
288
- {"wrong_type2" , `"expires": {}` , false },
289
- {"wrong_value" , `"expires": "zzz"` , false },
283
+ {"normal" , fmt .Sprintf (`"expires_in": %d` , seconds ), true , false },
284
+ {"paypal" , fmt .Sprintf (`"expires_in": "%d"` , seconds ), true , false },
285
+ {"issue_239" , fmt .Sprintf (`"expires_in": null` ), true , true },
286
+
287
+ {"wrong_type" , `"expires_in": false` , false , false },
288
+ {"wrong_type2" , `"expires_in": {}` , false , false },
289
+ {"wrong_value" , `"expires_in": "zzz"` , false , false },
290
290
} {
291
291
t .Run (c .name , func (t * testing.T ) {
292
- testExchangeRequest_JSONResponse_expiry (t , c .expires , c .want )
292
+ testExchangeRequest_JSONResponse_expiry (t , c .expires , c .want , c . nullExpires )
293
293
})
294
294
}
295
295
}
296
296
297
- func testExchangeRequest_JSONResponse_expiry (t * testing.T , exp string , want bool ) {
297
+ func testExchangeRequest_JSONResponse_expiry (t * testing.T , exp string , want , nullExpires bool ) {
298
298
ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
299
299
w .Header ().Set ("Content-Type" , "application/json" )
300
300
w .Write ([]byte (fmt .Sprintf (`{"access_token": "90d", "scope": "user", "token_type": "bearer", %s}` , exp )))
@@ -303,7 +303,7 @@ func testExchangeRequest_JSONResponse_expiry(t *testing.T, exp string, want bool
303
303
conf := newConf (ts .URL )
304
304
t1 := time .Now ().Add (day )
305
305
tok , err := conf .Exchange (context .Background (), "exchange-code" )
306
- t2 := time . Now () .Add (day )
306
+ t2 := t1 .Add (day )
307
307
308
308
if got := (err == nil ); got != want {
309
309
if want {
@@ -319,8 +319,12 @@ func testExchangeRequest_JSONResponse_expiry(t *testing.T, exp string, want bool
319
319
t .Fatalf ("Token invalid. Got: %#v" , tok )
320
320
}
321
321
expiry := tok .Expiry
322
+
323
+ if nullExpires && expiry .IsZero () {
324
+ return
325
+ }
322
326
if expiry .Before (t1 ) || expiry .After (t2 ) {
323
- t .Errorf ("Unexpected value for Expiry: %v (shold be between %v and %v)" , expiry , t1 , t2 )
327
+ t .Errorf ("Unexpected value for Expiry: %v (should be between %v and %v)" , expiry , t1 , t2 )
324
328
}
325
329
}
326
330
0 commit comments