forked from datarhei/gosrt
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server_test.go
61 lines (45 loc) · 1.03 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
package srt
import (
"testing"
"github.com/stretchr/testify/require"
)
func TestServer(t *testing.T) {
server := Server{
Addr: "127.0.0.1:6003",
HandleConnect: func(req ConnRequest) ConnType {
streamid := req.StreamId()
if streamid == "publish" {
return PUBLISH
} else if streamid == "subscribe" {
return SUBSCRIBE
}
return REJECT
},
}
err := server.Listen()
require.NoError(t, err)
defer server.Shutdown()
go func() {
err := server.Serve()
if err == ErrServerClosed {
return
}
require.NoError(t, err)
}()
config := DefaultConfig()
config.StreamId = "publish"
conn, err := Dial("srt", "127.0.0.1:6003", config)
require.NoError(t, err)
err = conn.Close()
require.NoError(t, err)
config = DefaultConfig()
config.StreamId = "subscribe"
conn, err = Dial("srt", "127.0.0.1:6003", config)
require.NoError(t, err)
err = conn.Close()
require.NoError(t, err)
config = DefaultConfig()
config.StreamId = "nothing"
_, err = Dial("srt", "127.0.0.1:6003", config)
require.Error(t, err)
}