-
Notifications
You must be signed in to change notification settings - Fork 5
/
api_test.go
85 lines (64 loc) · 1.69 KB
/
api_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
package plain
import (
"testing"
"github.com/sec-bit/zkPoD-lib/pod_go/setup"
)
const (
testEccPubFile = "../test_data"
testPlainPublishPathSucc = "../test_data/publish/plain"
testPlainPublishPathFail = "../test_data/publish/plain_not_exist_dir"
testPlainPublicPathSucc = "../test_data/publish/plain/public"
testPlainPublicPathFail = "../test_data/publish/plain_not_exist_dir/public"
testPlainBulletinSucc = "../test_data/publish/plain/bulletin"
testPlainBulletinFail = "../test_data/publish/plain_not_exist_dir/bulletin"
)
var (
inited = false
)
func prepare(t *testing.T) {
if !inited {
if ret := setup.Load(testEccPubFile); !ret {
t.Fatalf("failed to load %s\n", testEccPubFile)
}
inited = true
}
}
func TestNewA(t *testing.T) {
prepare(t)
if _, err := NewA(testPlainPublishPathSucc); err != nil {
t.Errorf("%v\n", err)
}
if _, err := NewA(testPlainPublishPathFail); err == nil {
t.Errorf("NewA(%s) should fail\n", testPlainPublishPathFail)
}
}
func TestNewB(t *testing.T) {
prepare(t)
if _, err := NewB(testPlainBulletinSucc, testPlainPublicPathSucc); err != nil {
t.Errorf("%v\n", err)
}
if _, err := NewB(testPlainBulletinFail, testPlainPublicPathFail); err == nil {
t.Errorf("NewB(%s, %s) should fail\n",
testPlainBulletinFail, testPlainPublicPathFail)
}
}
func TestFreeA(t *testing.T) {
prepare(t)
a, err := NewA(testPlainPublishPathSucc)
if err != nil {
t.Fatalf("%v\n", err)
}
if err := a.Free(); err != nil {
t.Errorf("%v\n", err)
}
}
func TestFreeB(t *testing.T) {
prepare(t)
b, err := NewB(testPlainBulletinSucc, testPlainPublicPathSucc)
if err != nil {
t.Fatalf("%v\n", err)
}
if err := b.Free(); err != nil {
t.Errorf("%v\n", err)
}
}