forked from dedis/cothority_template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
api_test.go
66 lines (56 loc) · 1.48 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
package template_test
import (
"testing"
"github.com/stretchr/testify/assert"
// We need to include the service so it is started.
"github.com/dedis/cothority_template"
_ "github.com/dedis/cothority_template/service"
"gopkg.in/dedis/onet.v1"
"gopkg.in/dedis/onet.v1/log"
)
func TestMain(m *testing.M) {
log.MainTest(m)
}
func TestClient_Clock(t *testing.T) {
nbr := 5
local := onet.NewTCPTest()
// generate 5 hosts, they don't connect, they process messages, and they
// don't register the tree or entitylist
_, roster, _ := local.GenTree(nbr, true)
defer local.CloseAll()
c := template.NewClient()
cl1, err := c.Clock(roster)
log.ErrFatal(err)
assert.Equal(t, nbr, cl1.Children)
cl2, err := c.Clock(roster)
log.ErrFatal(err)
assert.Equal(t, nbr, cl2.Children)
}
func TestClient_Count(t *testing.T) {
nbr := 5
local := onet.NewTCPTest()
// generate 5 hosts, they don't connect, they process messages, and they
// don't register the tree or entitylist
_, roster, _ := local.GenTree(nbr, true)
defer local.CloseAll()
c := template.NewClient()
// Verify it's all 0s before
for _, s := range roster.List {
count, err := c.Count(s)
log.ErrFatal(err)
assert.Equal(t, 0, count)
}
// Make some clock-requests
for range roster.List {
_, err := c.Clock(roster)
log.ErrFatal(err)
}
// Verify we have the correct total of requests
total := 0
for _, s := range roster.List {
count, err := c.Count(s)
log.ErrFatal(err)
total += count
}
assert.Equal(t, nbr, total)
}