@@ -5,27 +5,29 @@ import (
5
5
"fmt"
6
6
"strings"
7
7
"testing"
8
+
9
+ "github.com/stretchr/testify/assert"
8
10
)
9
11
10
- type KeyVal struct {
12
+ type keyVal struct {
11
13
Private string `json:"private"`
12
14
Public string `json:"public"`
13
15
Certificate string `json:"certificate,omitempty"`
14
16
}
15
17
16
- type Key struct {
18
+ type key struct {
17
19
KeyID string `json:"keyid"`
18
20
KeyIDHashAlgorithms []string `json:"keyid_hash_algorithms"`
19
21
KeyType string `json:"keytype"`
20
- KeyVal KeyVal `json:"keyval"`
22
+ KeyVal keyVal `json:"keyval"`
21
23
Scheme string `json:"scheme"`
22
24
}
23
25
24
26
func TestEncodeCanonical (t * testing.T ) {
25
27
objects := []interface {}{
26
- Key {},
27
- Key {
28
- KeyVal : KeyVal {
28
+ key {},
29
+ key {
30
+ KeyVal : keyVal {
29
31
Private : "priv" ,
30
32
Public : "pub" ,
31
33
},
@@ -42,8 +44,8 @@ func TestEncodeCanonical(t *testing.T) {
42
44
"int2" : float64 (42 ),
43
45
"string" : `\"` ,
44
46
},
45
- Key {
46
- KeyVal : KeyVal {
47
+ key {
48
+ KeyVal : keyVal {
47
49
Certificate : "cert" ,
48
50
Private : "priv" ,
49
51
Public : "pub" ,
@@ -91,21 +93,22 @@ func TestEncodeCanonicalErr(t *testing.T) {
91
93
}
92
94
}
93
95
94
- func TestencodeCanonical (t * testing.T ) {
95
- expectedError := "Can't canonicalize"
96
+ func TestEncodeCanonicalHelper (t * testing.T ) {
97
+ defer func () {
98
+ if r := recover (); r == nil {
99
+ t .Error ("encodeCanonical did not panic as expected" )
100
+ }
101
+ }()
96
102
97
103
objects := []interface {}{
98
- TestencodeCanonical ,
99
- []interface {}{TestencodeCanonical },
104
+ TestEncodeCanonicalHelper ,
105
+ []interface {}{TestEncodeCanonicalHelper },
100
106
}
101
107
102
108
for i := 0 ; i < len (objects ); i ++ {
103
109
var result strings.Builder
104
110
err := encodeCanonical (objects [i ], & result )
105
- if err == nil || ! strings .Contains (err .Error (), expectedError ) {
106
- t .Errorf ("EncodeCanonical returned '%s', expected '%s' error" ,
107
- err , expectedError )
108
- }
111
+ assert .Nil (t , err )
109
112
}
110
113
}
111
114
0 commit comments