1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
|
package main
import "testing"
func TestCheckNames(t *testing.T) {
testCases := []struct {
pub, sec string
err error
}{
{"key.pub", "key.sec", nil},
{"testdata/key.pub", "key.sec", nil},
{"key.pub", "testdata/key.sec", nil},
{"foo.pub", "bar.sec", ErrNames},
{"key.foo", "key.bar", ErrNames},
}
for _, tc := range testCases {
t.Run(tc.pub+"+"+tc.sec, func(t *testing.T) {
err := ValidateNames(tc.pub, tc.sec)
if err != tc.err {
t.Errorf("got %v, want %v", err, tc.err)
}
})
}
}
func TestVerify(t *testing.T) {
testCases := []struct {
comment string
file string
}{
{"verify with key.pub", "key.pub"},
{"verify with s p a c e s.pub", "s p a c e s.pub"},
{"verify with key.sec", ""},
{"whatever", ""},
}
for _, tc := range testCases {
t.Run(tc.comment, func(t *testing.T) {
file := CommentPubFile(tc.comment)
if file != tc.file {
t.Errorf("got %v, want %v", file, tc.file)
}
})
}
}
func TestSplit(t *testing.T) {
testCases := []struct {
fname, name, ext string
}{
{"testkey.pub", "testkey", ".pub"},
{"testkey", "testkey", ""},
{".pub", "", ".pub"},
{".testkey.pub", ".testkey", ".pub"},
{"", "", ""},
{"path/key.pub", "key", ".pub"},
}
for _, tc := range testCases {
t.Run(tc.fname, func(t *testing.T) {
name, ext := splitNameExt(tc.fname)
if name != tc.name || ext != tc.ext {
t.Errorf("got %q %q, want %q %q", name, tc.name, ext, tc.ext)
}
})
}
}
|