-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver_test.go
49 lines (41 loc) · 979 Bytes
/
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
package evmn
import (
"fmt"
"math/rand"
"net"
"net/textproto"
"strings"
"testing"
"github.com/stretchr/testify/assert"
)
func init() {
hostname = fmt.Sprint(rand.Int63())
expected["nodes"] = hostname + "\n."
}
func TestListenAndServe(t *testing.T) {
go func() {
err := ListenAndServe(":4950")
assert.NoError(t, err)
}()
}
func TestServer(t *testing.T) {
expected["config"] = "# Unknown service"
expected["fetch"] = "# Unknown service"
expected["help"] = "# Unknown command"
for k, v := range expected {
conn, err := net.Dial("tcp", "localhost:4950")
assert.NoError(t, err)
tc := textproto.NewConn(conn)
s, err := tc.ReadLine()
assert.NoError(t, err)
assert.Equal(t, "# munin node at "+hostname, s)
n, err := tc.W.WriteString(k + "\n\n")
assert.NoError(t, tc.W.Flush())
assert.NoError(t, err)
assert.NotZero(t, n)
r, err := tc.ReadLine()
assert.NoError(t, err)
assert.Equal(t, strings.Split(v, "\n")[0], r)
conn.Close()
}
}