From e839600e667558ee911f25df4f44b69cb1a743ff Mon Sep 17 00:00:00 2001 From: Jaana Burcu Dogan Date: Fri, 26 Aug 2016 11:51:24 -0700 Subject: [PATCH] oauth2, jws, internal: more style fixes for bad test messages Change-Id: Id2805fd77fb11d975414eb66689efab284a18805 Reviewed-on: https://go-review.googlesource.com/27911 Reviewed-by: Brad Fitzpatrick --- internal/token_test.go | 9 ++++----- jws/jws_test.go | 2 +- transport_test.go | 16 ++++++++-------- 3 files changed, 13 insertions(+), 14 deletions(-) diff --git a/internal/token_test.go b/internal/token_test.go index d8d1e98..5ed0b15 100644 --- a/internal/token_test.go +++ b/internal/token_test.go @@ -14,23 +14,22 @@ func TestRegisterBrokenAuthHeaderProvider(t *testing.T) { RegisterBrokenAuthHeaderProvider("https://aaa.com/") tokenURL := "https://aaa.com/token" if providerAuthHeaderWorks(tokenURL) { - t.Errorf("URL: %s is a broken provider", tokenURL) + t.Errorf("got %q as unbroken; want broken", tokenURL) } } func Test_providerAuthHeaderWorks(t *testing.T) { for _, p := range brokenAuthHeaderProviders { if providerAuthHeaderWorks(p) { - t.Errorf("URL: %s not found in list", p) + t.Errorf("got %q as unbroken; want broken", p) } p := fmt.Sprintf("%ssomesuffix", p) if providerAuthHeaderWorks(p) { - t.Errorf("URL: %s not found in list", p) + t.Errorf("got %q as unbroken; want broken", p) } } p := "https://api.not-in-the-list-example.com/" if !providerAuthHeaderWorks(p) { - t.Errorf("URL: %s found in list", p) + t.Errorf("got %q as unbroken; want broken", p) } - } diff --git a/jws/jws_test.go b/jws/jws_test.go index 9b5efdd..39a136a 100644 --- a/jws/jws_test.go +++ b/jws/jws_test.go @@ -41,6 +41,6 @@ func TestSignAndVerify(t *testing.T) { func TestVerifyFailsOnMalformedClaim(t *testing.T) { err := Verify("abc.def", nil) if err == nil { - t.Error("Improperly formed JWT should fail.") + t.Error("got no errors; want improperly formed JWT not to be verified") } } diff --git a/transport_test.go b/transport_test.go index 9bb1383..d6e8087 100644 --- a/transport_test.go +++ b/transport_test.go @@ -18,12 +18,12 @@ func TestTransportNilTokenSource(t *testing.T) { server := newMockServer(func(w http.ResponseWriter, r *http.Request) {}) defer server.Close() client := &http.Client{Transport: tr} - res, err := client.Get(server.URL) + resp, err := client.Get(server.URL) if err == nil { - t.Errorf("a nil Source was passed into the transport expected an error") + t.Errorf("got no errors, want an error with nil token source") } - if res != nil { - t.Errorf("expected a nil response, got %v", res) + if resp != nil { + t.Errorf("Response = %v; want nil", resp) } } @@ -37,8 +37,8 @@ func TestTransportTokenSource(t *testing.T) { Source: ts, } server := newMockServer(func(w http.ResponseWriter, r *http.Request) { - if r.Header.Get("Authorization") != "Bearer abc" { - t.Errorf("Transport doesn't set the Authorization header from the fetched token") + if got, want := r.Header.Get("Authorization"), "Bearer abc"; got != want { + t.Errorf("Authorization header = %q; want %q", got, want) } }) defer server.Close() @@ -90,7 +90,7 @@ func TestTransportTokenSourceTypes(t *testing.T) { func TestTokenValidNoAccessToken(t *testing.T) { token := &Token{} if token.Valid() { - t.Errorf("Token should not be valid with no access token") + t.Errorf("got valid with no access token; want invalid") } } @@ -99,7 +99,7 @@ func TestExpiredWithExpiry(t *testing.T) { Expiry: time.Now().Add(-5 * time.Hour), } if token.Valid() { - t.Errorf("Token should not be valid if it expired in the past") + t.Errorf("got valid with expired token; want invalid") } }