From 4b716da07041687901f4ee4ab37134753965b7f9 Mon Sep 17 00:00:00 2001 From: David Calavera Date: Tue, 9 Feb 2016 15:52:53 -0800 Subject: [PATCH] Make sure missing credentials returns the right error. Signed-off-by: David Calavera --- osxkeychain/osxkeychain_darwin.go | 6 +++--- osxkeychain/osxkeychain_darwin_test.go | 8 ++++++++ 2 files changed, 11 insertions(+), 3 deletions(-) diff --git a/osxkeychain/osxkeychain_darwin.go b/osxkeychain/osxkeychain_darwin.go index f805a19..c2eae86 100644 --- a/osxkeychain/osxkeychain_darwin.go +++ b/osxkeychain/osxkeychain_darwin.go @@ -18,9 +18,9 @@ import ( "github.com/calavera/docker-credential-helpers/credentials" ) -// notFoundError is the specific error message returned by OS X +// errCredentialsNotFound is the specific error message returned by OS X // when the credentials are not in the keychain. -const notFoundError = "The specified item could not be found in the keychain." +const errCredentialsNotFound = "The specified item could not be found in the keychain." type osxkeychain struct{} @@ -88,7 +88,7 @@ func (h osxkeychain) Get(serverURL string) (string, string, error) { defer C.free(unsafe.Pointer(errMsg)) goMsg := C.GoString(errMsg) - if goMsg == notFoundError { + if goMsg == errCredentialsNotFound { return "", "", credentials.ErrCredentialsNotFound } diff --git a/osxkeychain/osxkeychain_darwin_test.go b/osxkeychain/osxkeychain_darwin_test.go index 6b21406..dd9df65 100644 --- a/osxkeychain/osxkeychain_darwin_test.go +++ b/osxkeychain/osxkeychain_darwin_test.go @@ -35,3 +35,11 @@ func TestOSXKeychainHelper(t *testing.T) { t.Fatal(err) } } + +func TestMissingCredentials(t *testing.T) { + helper := New() + _, _, err := helper.Get("https://adsfasdf.wrewerwer.com/asdfsdddd") + if err != credentials.ErrCredentialsNotFound { + t.Fatal("exptected ErrCredentialsNotFound, got %v", err) + } +}