Skip to content

Commit 2fc2313

Browse files
committed
pass: return an error when a cred doesn't exist
fixes #174 Signed-off-by: Nick Santos <[email protected]>
1 parent e595cd6 commit 2fc2313

File tree

2 files changed

+13
-8
lines changed

2 files changed

+13
-8
lines changed

pass/pass.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ func (p Pass) Get(serverURL string) (string, string, error) {
138138

139139
if _, err := os.Stat(path.Join(getPassDir(), PASS_FOLDER, encoded)); err != nil {
140140
if os.IsNotExist(err) {
141-
return "", "", nil
141+
return "", "", credentials.NewErrCredentialsNotFound()
142142
}
143143

144144
return "", "", err

pass/pass_test.go

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,9 @@ func TestPassHelper(t *testing.T) {
5454
t.Fatal(err)
5555
}
5656

57-
username, _, err = helper.Get(server)
58-
if err != nil {
59-
t.Fatal(err)
60-
}
61-
62-
if username != "" {
63-
t.Fatalf("%s shouldn't exist any more", username)
57+
_, _, err = helper.Get(server)
58+
if !credentials.IsErrCredentialsNotFound(err) {
59+
t.Fatalf("expected credentials not found, actual: %v", err)
6460
}
6561
}
6662

@@ -73,3 +69,12 @@ func TestPassHelper(t *testing.T) {
7369
t.Fatal("didn't delete all creds?")
7470
}
7571
}
72+
73+
func TestMissingCred(t *testing.T) {
74+
helper := Pass{}
75+
76+
_, _, err := helper.Get("garbage")
77+
if !credentials.IsErrCredentialsNotFound(err) {
78+
t.Fatalf("expected credentials not found, actual: %v", err)
79+
}
80+
}

0 commit comments

Comments
 (0)