コード例 #1
0
func TestBasicAuthSignDoesntBarfOnNil(t *testing.T) {
	defer func() {
		if r := recover(); r != nil {
			t.Errorf("%v", r)
		}
	}()

	credentials.BasicAuth("u", "p").Sign(nil)
}
コード例 #2
0
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"))
	}
}
コード例 #3
0
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)
	}
}