diff --git a/oauth2_test.go b/oauth2_test.go index b3696a1..0bc6129 100644 --- a/oauth2_test.go +++ b/oauth2_test.go @@ -182,11 +182,11 @@ func TestExchangeRequest_JSONResponse_Expiry(t *testing.T) { expect error }{ {fmt.Sprintf(`"expires_in": %d`, seconds), nil}, - {fmt.Sprintf(`"expires_in": "%d"`, seconds), nil}, // PayPal case - {fmt.Sprintf(`"expires": %d`, seconds), nil}, // Facebook case - {`"expires": false`, &json.UnmarshalTypeError{"bool", jsonNumberType}}, // wrong type - {`"expires": {}`, &json.UnmarshalTypeError{"object", jsonNumberType}}, // wrong type - {`"expires": "zzz"`, &strconv.NumError{"ParseInt", "zzz", strconv.ErrSyntax}}, // wrong value + {fmt.Sprintf(`"expires_in": "%d"`, seconds), nil}, // PayPal case + {fmt.Sprintf(`"expires": %d`, seconds), nil}, // Facebook case + {`"expires": false`, &json.UnmarshalTypeError{Value: "bool", Type: jsonNumberType}}, // wrong type + {`"expires": {}`, &json.UnmarshalTypeError{Value: "object", Type: jsonNumberType}}, // wrong type + {`"expires": "zzz"`, &strconv.NumError{Func: "ParseInt", Num: "zzz", Err: strconv.ErrSyntax}}, // wrong value } { testExchangeRequest_JSONResponse_expiry(t, c.expires, c.expect) } @@ -202,16 +202,20 @@ func testExchangeRequest_JSONResponse_expiry(t *testing.T, exp string, expect er t1 := time.Now().Add(day) tok, err := conf.Exchange(NoContext, "exchange-code") t2 := time.Now().Add(day) - if err == nil && expect != nil { - t.Errorf("Incorrect state, conf.Exchange() should return an error: %v", expect) - } else if err != nil { - if reflect.DeepEqual(err, expect) { - t.Logf("Expected error: %v", err) - return - } else { - t.Error(err) - } - + // Do a fmt.Sprint comparison so either side can be + // nil. fmt.Sprint just stringifies them to "", and no + // non-nil expected error ever stringifies as "", so this + // isn't terribly disgusting. We do this because Go 1.4 and + // Go 1.5 return a different deep value for + // json.UnmarshalTypeError. In Go 1.5, the + // json.UnmarshalTypeError contains a new field with a new + // non-zero value. Rather than ignore it here with reflect or + // add new files and +build tags, just look at the strings. + if fmt.Sprint(err) != fmt.Sprint(expect) { + t.Errorf("Error = %v; want %v", err, expect) + } + if err != nil { + return } if !tok.Valid() { t.Fatalf("Token invalid. Got: %#v", tok)