Skip to content
This repository was archived by the owner on Feb 7, 2024. It is now read-only.

Commit 69fcb18

Browse files
committed
implement: ipfs key rm
Signed-off-by: Max Peng <[email protected]> (cherry picked from commit 88d33fe)
1 parent 87f03b0 commit 69fcb18

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

key.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,3 +72,13 @@ func (s *Shell) KeyRename(ctx context.Context, old string, new string, force boo
7272
}
7373
return &out, nil
7474
}
75+
76+
// KeyRm remove a keypair
77+
func (s *Shell) KeyRm(ctx context.Context, name string) ([]*Key, error) {
78+
var out keyListOutput
79+
if err := s.Request("key/rm", name).
80+
Exec(ctx, &out); err != nil {
81+
return nil, err
82+
}
83+
return out.Keys, nil
84+
}

key_test.go

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,9 @@ func TestKeyGen(t *testing.T) {
1616

1717
is.Equal(key.Name, "testKey")
1818
is.NotNil(key.Id)
19+
20+
_, err = s.KeyRm(context.Background(), "testKey")
21+
is.Nil(err)
1922
}
2023

2124
func TestKeyList(t *testing.T) {
@@ -44,4 +47,22 @@ func TestKeyRename(t *testing.T) {
4447
is.Equal(out.Was, "test1")
4548
is.Equal(out.Id, key.Id)
4649
is.False(out.Overwrite)
50+
51+
_, err = s.KeyRm(context.Background(), "test2")
52+
is.Nil(err)
53+
}
54+
55+
func TestKeyRm(t *testing.T) {
56+
is := is.New(t)
57+
s := NewShell(shellUrl)
58+
59+
key, err := s.KeyGen(context.Background(), "testKey")
60+
is.Nil(err)
61+
62+
keys, err := s.KeyRm(context.Background(), "testKey")
63+
is.Nil(err)
64+
65+
is.Equal(len(keys), 1)
66+
is.Equal(keys[0].Name, "testKey")
67+
is.Equal(keys[0].Id, key.Id)
4768
}

0 commit comments

Comments
 (0)