@@ -11,26 +11,66 @@ func TestKeyGen(t *testing.T) {
11
11
is := is .New (t )
12
12
s := NewShell (shellUrl )
13
13
14
- key , err := s .KeyGen (context .Background (), "testKey" , KeyGen .Type ("ed25519" ), KeyGen .Size (2048 ))
14
+ defer func () {
15
+ _ , err := s .KeyRm (context .Background (), "testKey1" )
16
+ is .Nil (err )
17
+ }()
18
+ key1 , err := s .KeyGen (context .Background (), "testKey1" , KeyGen .Type ("ed25519" ), KeyGen .Size (2048 ))
15
19
is .Nil (err )
16
-
17
- is .Equal (key .Name , "testKey" )
18
- is .NotNil (key .Id )
19
-
20
- _ , err = s .KeyRm (context .Background (), "testKey" )
20
+ is .Equal (key1 .Name , "testKey1" )
21
+ is .NotNil (key1 .Id )
22
+
23
+ defer func () {
24
+ _ , err = s .KeyRm (context .Background (), "testKey2" )
25
+ is .Nil (err )
26
+ }()
27
+ key2 , err := s .KeyGen (context .Background (), "testKey2" , KeyGen .Type ("ed25519" ))
28
+ is .Nil (err )
29
+ is .Equal (key2 .Name , "testKey2" )
30
+ is .NotNil (key2 .Id )
31
+
32
+ defer func () {
33
+ _ , err = s .KeyRm (context .Background (), "testKey3" )
34
+ is .Nil (err )
35
+ }()
36
+ key3 , err := s .KeyGen (context .Background (), "testKey3" , KeyGen .Type ("rsa" ))
21
37
is .Nil (err )
38
+ is .Equal (key3 .Name , "testKey3" )
39
+ is .NotNil (key3 .Id )
40
+
41
+ defer func () {
42
+ _ , err = s .KeyRm (context .Background (), "testKey4" )
43
+ is .Nil (err )
44
+ }()
45
+ key4 , err := s .KeyGen (context .Background (), "testKey4" , KeyGen .Type ("rsa" ), KeyGen .Size (4096 ))
46
+ is .Nil (err )
47
+ is .Equal (key4 .Name , "testKey4" )
48
+ is .NotNil (key4 .Id )
49
+
50
+ _ , err = s .KeyGen (context .Background (), "testKey5" , KeyGen .Type ("rsa" ), KeyGen .Size (1024 ))
51
+ is .NotNil (err )
52
+ is .Equal (err .Error (), "key/gen: rsa keys must be >= 2048 bits to be useful" )
22
53
}
23
54
24
55
func TestKeyList (t * testing.T ) {
25
56
is := is .New (t )
26
57
s := NewShell (shellUrl )
27
58
59
+ defer func () {
60
+ _ , err := s .KeyRm (context .Background (), "testKey" )
61
+ is .Nil (err )
62
+ }()
63
+ key , err := s .KeyGen (context .Background (), "testKey" )
64
+ is .Nil (err )
65
+
28
66
keys , err := s .KeyList (context .Background ())
29
67
is .Nil (err )
30
68
31
- is .Equal (len (keys ), 1 )
69
+ is .Equal (len (keys ), 2 )
32
70
is .Equal (keys [0 ].Name , "self" )
33
71
is .NotNil (keys [0 ].Id )
72
+ is .NotNil (keys [1 ].Id , key .Id )
73
+ is .NotNil (keys [1 ].Name , key .Name )
34
74
}
35
75
36
76
func TestKeyRename (t * testing.T ) {
@@ -50,6 +90,10 @@ func TestKeyRename(t *testing.T) {
50
90
51
91
_ , err = s .KeyRm (context .Background (), "test2" )
52
92
is .Nil (err )
93
+
94
+ _ , err = s .KeyRename (context .Background (), "test2" , "test1" , false )
95
+ is .NotNil (err )
96
+ is .Equal (err .Error (), "key/rename: no key named test2 was found" )
53
97
}
54
98
55
99
func TestKeyRm (t * testing.T ) {
@@ -63,6 +107,10 @@ func TestKeyRm(t *testing.T) {
63
107
is .Nil (err )
64
108
65
109
is .Equal (len (keys ), 1 )
66
- is .Equal (keys [0 ].Name , "testKey" )
110
+ is .Equal (keys [0 ].Name , key . Name )
67
111
is .Equal (keys [0 ].Id , key .Id )
112
+
113
+ _ , err = s .KeyRm (context .Background (), "testKey" )
114
+ is .NotNil (err )
115
+ is .Equal (err .Error (), "key/rm: no key named testKey was found" )
68
116
}
0 commit comments