Skip to content

Commit e3a9357

Browse files
committed
Fix delete confirmation
1 parent 02ef24d commit e3a9357

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

keystore/cli/cli.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ func NewDeleteCmd() *cobra.Command {
177177
}
178178
reader := bufio.NewReader(cmd.InOrStdin())
179179
line, _ := reader.ReadString('\n')
180-
if strings.TrimSpace(line) != "yes\n" {
180+
if strings.TrimSpace(line) != "yes" {
181181
return errors.New("delete aborted by user")
182182
}
183183
}

keystore/cli/cli_test.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,4 +114,19 @@ func TestCLI(t *testing.T) {
114114
require.Equal(t, "testkey", resp.Keys[0].KeyInfo.Name)
115115
// Metadata is []byte, Go's JSON unmarshaler automatically decodes base64 strings
116116
require.Equal(t, "my-custom-metadata", string(resp.Keys[0].KeyInfo.Metadata))
117+
118+
// Delete the key with confirmation.
119+
buf.Reset()
120+
// cmd.SetIn(bytes.NewBufferString("yes\n"))
121+
cmd.SetArgs([]string{"delete", "-d", `{"KeyNames": ["testkey", "testkey2"]}`})
122+
require.NoError(t, cmd.ExecuteContext(t.Context()))
123+
124+
// List keys should be empty.
125+
buf.Reset()
126+
cmd.SetArgs([]string{"list"})
127+
require.NoError(t, cmd.ExecuteContext(t.Context()))
128+
resp = ks.GetKeysResponse{}
129+
err = json.Unmarshal(buf.Bytes(), &resp)
130+
require.NoError(t, err)
131+
require.Len(t, resp.Keys, 0)
117132
}

0 commit comments

Comments
 (0)