-
Notifications
You must be signed in to change notification settings - Fork 1
/
server_test.go
56 lines (46 loc) · 1.14 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
package lanes_test
import (
"bytes"
"strings"
"testing"
"github.com/stretchr/testify/assert"
"github.com/codekoala/go-aws-lanes"
)
func TestServerSortKey(t *testing.T) {
s := &lanes.Server{
ID: "z",
Name: "r",
Lane: "u",
IP: "5",
}
assert.Equal(t, s.SortKey(), "u r z")
assert.Equal(t, s.String(), "r (z)")
}
func TestDisplayServersWriter(t *testing.T) {
var (
ss []*lanes.Server
buf = bytes.NewBuffer(nil)
s = &lanes.Server{
ID: "i-id-i",
Name: "n-name-n",
Lane: "l-lane-l",
IP: "i-5-i",
}
)
assert.NotNil(t, lanes.DisplayServersWriter(buf, ss))
assert.Equal(t, buf.String(), "")
ss = append(ss, s)
assert.Nil(t, lanes.DisplayServersWriter(buf, ss))
tbl := buf.String()
assert.True(t, strings.Contains(tbl, s.ID))
assert.True(t, strings.Contains(tbl, s.Name))
assert.True(t, strings.Contains(tbl, s.Lane))
assert.True(t, strings.Contains(tbl, s.IP))
idIdx := strings.Index(tbl, s.ID)
nameIdx := strings.Index(tbl, s.Name)
laneIdx := strings.Index(tbl, s.Lane)
ipIdx := strings.Index(tbl, s.IP)
assert.True(t, laneIdx < nameIdx)
assert.True(t, nameIdx < ipIdx)
assert.True(t, ipIdx < idIdx)
}