1
0
mirror of https://github.com/docker/docker-credential-helpers.git synced 2026-06-13 16:01:28 +05:30

implementation on client side as well, complete with tests

Signed-off-by: avaid96 <avaid1996@gmail.com>
This commit is contained in:
avaid96
2016-07-13 10:20:51 -07:00
parent 887a66459a
commit 8fa18eb16c
3 changed files with 25 additions and 3 deletions
+13 -2
View File
@@ -55,11 +55,10 @@ func Get(program ProgramFunc, serverURL string) (*credentials.Credentials, error
return resp, nil
}
// Erase executes a program to remove the server credentails from the native store.
// Erase executes a program to remove the server credentials from the native store.
func Erase(program ProgramFunc, serverURL string) error {
cmd := program("erase")
cmd.Input(strings.NewReader(serverURL))
out, err := cmd.Output()
if err != nil {
t := strings.TrimSpace(string(out))
@@ -68,3 +67,15 @@ func Erase(program ProgramFunc, serverURL string) error {
return nil
}
// List executes a program to remove the server credentials from the native store.
func List(program ProgramFunc) error {
cmd := program("list")
cmd.Input(strings.NewReader("garbage"))
out, err := cmd.Output()
if err != nil {
t := strings.TrimSpace(string(out))
return fmt.Errorf("error listing credentials - err: %v, out: `%s`", err, t)
}
return nil
}
+9
View File
@@ -70,6 +70,9 @@ func (m *mockProgram) Output() ([]byte, error) {
default:
return []byte("error storing credentials"), errProgramExited
}
case "list":
return []byte(`{"Path":"e237574ae22fd53ddb9490dc1f72139946fd5372d42ba54d1eeb3ae5068fd22b","Username":"http://example.com/collections\u003cnotary_key\u003eSnapshot"}`), nil
}
return []byte(fmt.Sprintf("unknown argument %q with %q", m.arg, inS)), errProgramExited
@@ -190,3 +193,9 @@ func TestErase(t *testing.T) {
t.Fatalf("Expected error for server %s, got nil", invalidServerAddress)
}
}
func TestList(t *testing.T) {
if err := List(mockProgramFn); err != nil {
t.Fatal(err)
}
}