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 <bradfitz@golang.org>
This commit is contained in:
Jaana Burcu Dogan 2016-08-26 11:51:24 -07:00
parent 68218bf41b
commit e839600e66
3 changed files with 13 additions and 14 deletions

View File

@ -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)
}
}

View File

@ -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")
}
}

View File

@ -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")
}
}