Skip to content

Commit ad5c481

Browse files
tests(keys): add tests to keys cmds (#214)
1 parent eefb125 commit ad5c481

4 files changed

Lines changed: 221 additions & 69 deletions

File tree

cmd/cmd.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@ type DeisCmd struct {
9797
ConfigFile string
9898
WOut io.Writer
9999
WErr io.Writer
100+
WIn io.Reader
100101
}
101102

102103
// Println prints a line to an output writer.

cmd/keys.go

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@ import (
44
"fmt"
55
"io"
66
"io/ioutil"
7-
"os"
87
"path/filepath"
98
"strconv"
109
"strings"
10+
"text/tabwriter"
1111

1212
"github.com/deis/controller-sdk-go/api"
1313
"github.com/deis/controller-sdk-go/keys"
@@ -34,9 +34,12 @@ func (d DeisCmd) KeysList(results int) error {
3434

3535
d.Printf("=== %s Keys%s", s.Username, limitCount(len(keys), count))
3636

37+
w := tabwriter.NewWriter(d.WOut, 0, 8, 1, ' ', 0)
38+
3739
for _, key := range keys {
38-
d.Printf("%s %s...%s\n", key.ID, key.Public[:16], key.Public[len(key.Public)-10:])
40+
fmt.Fprintf(w, "%s\t%s...%s\n", key.ID, key.Public[:16], key.Public[len(key.Public)-10:])
3941
}
42+
w.Flush()
4043
return nil
4144
}
4245

@@ -74,7 +77,7 @@ func (d DeisCmd) KeyAdd(keyLocation string) error {
7477
if err != nil {
7578
return err
7679
}
77-
key, err = chooseKey(ks, os.Stdin, d.WOut)
80+
key, err = chooseKey(ks, d.WIn, d.WOut)
7881
if err != nil {
7982
return err
8083
}
@@ -125,7 +128,7 @@ func chooseKey(keys []api.KeyCreateRequest, input io.Reader,
125128
var filename string
126129

127130
fmt.Fprint(wOut, "Enter the path to the pubkey file: ")
128-
fmt.Scanln(&filename)
131+
fmt.Fscanln(input, &filename)
129132

130133
return getKey(filename)
131134
}

0 commit comments

Comments
 (0)