This repository has been archived by the owner on Sep 20, 2022. It is now read-only.
forked from dedis/onet
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
71 lines (59 loc) · 1.7 KB
/
server_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
package onet
import (
"testing"
"github.com/stretchr/testify/require"
"go.dedis.ch/onet/v3/log"
bbolt "go.etcd.io/bbolt"
uuid "gopkg.in/satori/go.uuid.v1"
)
var serverTestBuilder = NewLocalBuilder(NewDefaultBuilder())
func init() {
serverTestBuilder.SetSuite(testSuite)
}
func TestServer_ProtocolRegisterName(t *testing.T) {
c := serverTestBuilder.Build()
defer c.Close()
plen := len(c.protocols.instantiators)
require.True(t, plen > 0)
id, err := c.ProtocolRegister("ServerProtocol", NewServerProtocol)
log.ErrFatal(err)
require.NotNil(t, id)
require.True(t, plen < len(c.protocols.instantiators))
_, err = c.protocolInstantiate(ProtocolID(uuid.Nil), nil)
require.NotNil(t, err)
// Test for not overwriting
_, err = c.ProtocolRegister("ServerProtocol", NewServerProtocol2)
require.NotNil(t, err)
}
func TestServer_GetService(t *testing.T) {
c := serverTestBuilder.Build()
defer c.Close()
s := c.Service("nil")
require.Nil(t, s)
}
func TestServer_Database(t *testing.T) {
c := serverTestBuilder.Build()
require.NotNil(t, c.serviceManager.db)
for _, s := range c.serviceManager.availableServices() {
c.serviceManager.db.Update(func(tx *bbolt.Tx) error {
b := tx.Bucket([]byte(s))
require.NotNil(t, b)
return nil
})
}
c.Close()
}
type ServerProtocol struct {
*TreeNodeInstance
}
// NewExampleHandlers initialises the structure for use in one round
func NewServerProtocol(n *TreeNodeInstance) (ProtocolInstance, error) {
return &ServerProtocol{n}, nil
}
// NewExampleHandlers initialises the structure for use in one round
func NewServerProtocol2(n *TreeNodeInstance) (ProtocolInstance, error) {
return &ServerProtocol{n}, nil
}
func (cp *ServerProtocol) Start() error {
return nil
}