@@ -275,26 +275,26 @@ const day = 24 * time.Hour
275275func TestExchangeRequest_JSONResponse_Expiry (t * testing.T ) {
276276 seconds := int32 (day .Seconds ())
277277 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
281282 }{
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 },
290290 } {
291291 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 )
293293 })
294294 }
295295}
296296
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 ) {
298298 ts := httptest .NewServer (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {
299299 w .Header ().Set ("Content-Type" , "application/json" )
300300 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
303303 conf := newConf (ts .URL )
304304 t1 := time .Now ().Add (day )
305305 tok , err := conf .Exchange (context .Background (), "exchange-code" )
306- t2 := time . Now () .Add (day )
306+ t2 := t1 .Add (day )
307307
308308 if got := (err == nil ); got != want {
309309 if want {
@@ -319,8 +319,12 @@ func testExchangeRequest_JSONResponse_expiry(t *testing.T, exp string, want bool
319319 t .Fatalf ("Token invalid. Got: %#v" , tok )
320320 }
321321 expiry := tok .Expiry
322+
323+ if nullExpires && expiry .IsZero () {
324+ return
325+ }
322326 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 )
324328 }
325329}
326330
0 commit comments