-
Notifications
You must be signed in to change notification settings - Fork 0
/
stream_test.go
50 lines (37 loc) · 970 Bytes
/
stream_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
package rpc_stream
import (
"io"
"net"
"testing"
"github.com/stretchr/testify/assert"
)
func bogus(conn net.Conn) error {
return nil
}
func TestAdd(t *testing.T) {
var err error
// test Add
assert.Equal(t, ErrNoProto, Add(Mux_v2, nil))
assert.Equal(t, ErrMissingServFunc, Add(Mux_v2, &Sproto{}))
assert.Equal(t, ErrMissingName, Add(Mux_v2, &Sproto{serv: bogus}))
var p = &Sproto{name: "New", serv: bogus}
assert.Nil(t, Add(Mux_v2, p))
// should replace not add.
assert.Nil(t, Add(Mux_v2, p))
var y = &Sproto{name: "mess", serv: bogus}
assert.Nil(t, Add(Mux_v2, y))
// test NewProto
_, err = NewProto("foo", nil)
assert.Equal(t, ErrMissingServFunc, err)
_, err = NewProto("", bogus)
assert.Equal(t, ErrMissingName, err)
}
var serv_called bool
func servfunc(conn io.ReadWriteCloser) error {
serv_called = true
return nil
}
func TestServFunc(t *testing.T) {
var p = &Sproto{name: "myserv", serv: bogus}
assert.Nil(t, Add(Mux_v2, p))
}