func TestBasicAuthSignDoesntBarfOnNil(t *testing.T) { defer func() { if r := recover(); r != nil { t.Errorf("%v", r) } }() credentials.BasicAuth("u", "p").Sign(nil) }
func TestBasicAuthAddAuthorizationDataToTheRequest(t *testing.T) { req, err := http.NewRequest("GET", "http://www.google.com", nil) if err != nil { t.Errorf("Error creating request: %v", err) return } credentials.BasicAuth("username", "password").Sign(req) if req.Header.Get("Authorization") != "Basic dXNlcm5hbWU6cGFzc3dvcmQ=" { t.Errorf("Expected Basic dXNlcm5hbWU6cGFzc3dvcmQ=, got %v", req.Header.Get("Authorization")) } }
func TestOrZeroReturnsTheGivenNonNilArgument(t *testing.T) { c := credentials.BasicAuth("", "") if v := credentials.OrZero(c); v != c { t.Errorf("credentials.OrZero(%v) should've returned %v, not %v!", c, c, v) } }