-
Notifications
You must be signed in to change notification settings - Fork 94
/
certstore_test.go
82 lines (62 loc) · 1.68 KB
/
certstore_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
package goczmq
import (
"os"
"testing"
)
func TestCertStore(t *testing.T) {
testDir := ".test_zcertstore"
err := os.Mkdir(testDir, 0777)
if err != nil {
t.Error(err)
}
certstore := NewCertStore(testDir)
defer certstore.Destroy()
client0 := NewCert()
client0Key := client0.PublicText()
client0.Destroy()
client0Loaded := certstore.Lookup(client0Key)
if client0Loaded != nil {
t.Errorf("want %#v, have %#v", nil, client0Loaded)
}
client1 := NewCert()
client1.SetMeta("name", "Brian")
client1Key := client1.PublicText()
err = client1.Save(testDir + "/mycert.txt")
if err != nil {
t.Error(err)
}
client1.Destroy()
client1Loaded := certstore.Lookup(client1Key)
if want, have := "Brian", client1Loaded.Meta("name"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
if want, have := client1Key, client1Loaded.PublicText(); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
client2 := NewCert()
client2.SetMeta("name", "Luna")
client2Key := client2.PublicText()
certstore.Insert(client2)
client2Loaded := certstore.Lookup(client2Key)
if want, have := "Luna", client2Loaded.Meta("name"); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
if want, have := client2Key, client2Loaded.PublicText(); want != have {
t.Errorf("want %#v, have %#v", want, have)
}
err = os.RemoveAll(testDir)
if err != nil {
t.Fatal(err)
}
}
func TestCertStoreMem(t *testing.T) {
certstore := NewCertStoreInMemory()
defer certstore.Destroy()
client0 := NewCert()
client0Key := client0.PublicText()
client0.Destroy()
client0Loaded := certstore.Lookup(client0Key)
if client0Loaded != nil {
t.Errorf("want %#v, have %#v", nil, client0Loaded)
}
}