-
Notifications
You must be signed in to change notification settings - Fork 95
/
cert_test.go
92 lines (73 loc) · 1.86 KB
/
cert_test.go
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
package goczmq
import (
"os"
"testing"
)
func TestCert(t *testing.T) {
cert := NewCert()
defer cert.Destroy()
cert.SetMeta("email", "[email protected]")
if want, have := "[email protected]", cert.Meta("email"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
cert.SetMeta("name", "Brian Knox")
if want, have := "Brian Knox", cert.Meta("name"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
cert.SetMeta("organization", "ZeroMQ")
if want, have := "ZeroMQ", cert.Meta("organization"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
cert.SetMeta("version", "1")
if want, have := "1", cert.Meta("version"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
_ = cert.PublicText()
dup := cert.Dup()
defer dup.Destroy()
if want, have := "Brian Knox", dup.Meta("name"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
if want, have := true, cert.Equal(dup); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
if testing.Verbose() {
cert.Print()
}
err := cert.Save("./test_cert")
if err != nil {
t.Error(err)
}
loaded, err := NewCertFromFile("./test_cert")
if err != nil {
t.Error(err)
}
defer loaded.Destroy()
if want, have := true, loaded.Equal(cert); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
if testing.Verbose() {
loaded.Print()
}
err = os.Remove("./test_cert")
if err != nil {
t.Error(err)
}
err = os.Remove("./test_cert_secret")
if err != nil {
t.Error(err)
}
}
func TestNewCertFromFile(t *testing.T) {
want, have := NewCertFromFile("./test_file_that_does_not_exist")
if have != ErrCertNotFound {
t.Errorf("want %#v, have %#v", want, have)
}
}
func ExampleCert() {
cert := NewCert()
defer cert.Destroy()
cert.SetMeta("email", "[email protected]")
cert.SetMeta("name", "Brian Knox")
cert.SetMeta("organization", "ZeroMQ")
}