oauth2: fix test to work with Go tip also

json.UnmarshalError has a new field in Go 1.5. Adjust tests to cope.

Change-Id: I6733b2e14513794676e7329a828001f3f8c6c342
Reviewed-on: https://go-review.googlesource.com/8341
Reviewed-by: Burcu Dogan <jbd@google.com>
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 @@
 		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 @@
 	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 "<nil>", and no
+	// non-nil expected error ever stringifies as "<nil>", 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)