From 464c24ab07b8e8694078a51eade4e40531ca05f3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Carlos=20Mart=C3=ADn=20Nieto?= Date: Mon, 17 Apr 2017 19:02:49 +0200 Subject: [PATCH] remote: add a test to see that we're calling the credentials callback This does get called when we use the libgit2 stack, but is not yet something the Go one does. --- remote_test.go | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/remote_test.go b/remote_test.go index 8b20fd2..9e14391 100644 --- a/remote_test.go +++ b/remote_test.go @@ -184,3 +184,26 @@ func TestRemotePrune(t *testing.T) { t.Fatal("Expected error getting a pruned reference") } } + +func TestRemoteCredentialsCalled(t *testing.T) { + t.Parallel() + + repo := createTestRepo(t) + defer cleanupTestRepo(t, repo) + + remote, err := repo.Remotes.CreateAnonymous("https://github.com/libgit2/non-existent") + checkFatal(t, err) + + fetchOpts := FetchOptions{ + RemoteCallbacks: RemoteCallbacks{ + CredentialsCallback: func(url, username string, allowedTypes CredType) (ErrorCode, *Cred) { + return ErrUser, nil + }, + }, + } + + err = remote.Fetch(nil, &fetchOpts, "fetch") + if !IsErrorCode(err, ErrUser) { + t.Fatal("Bad Fetch return, expected ErrUser, got", err) + } +}