-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcmd_add_test.go
58 lines (49 loc) · 1.29 KB
/
cmd_add_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
package main
import (
"testing"
"github.com/shu-go/gotwant"
)
func TestCmdAdd(t *testing.T) {
hosts := `
# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
# localhost name resolution is handle within DNS itself.
127.0.0.1 localhost # THIS IS LOCALHOST
::1 localhost
# 118.151.235.191 example.com
# 192.168.1.201 server01 # new server
`
t.Run("Option", func(t *testing.T) {
el := read(hosts)
add := addCmd{
IP: "::2",
Host: "hogeserver",
Comment: "this is a server",
}
el = add.addTo(el)
result := list(el)
gotwant.Test(t, result, `# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost # THIS IS LOCALHOST
::1 localhost
# 118.151.235.191 example.com
# 192.168.1.201 server01 # new server
::2 hogeserver # this is a server
`)
})
t.Run("Args", func(t *testing.T) {
el := read(hosts)
add := addCmd{}
add.feed([]string{"::2", "hogeserver", "this is a server"})
el = add.addTo(el)
result := list(el)
gotwant.Test(t, result, `# 102.54.94.97 rhino.acme.com # source server
# 38.25.63.10 x.acme.com # x client host
127.0.0.1 localhost # THIS IS LOCALHOST
::1 localhost
# 118.151.235.191 example.com
# 192.168.1.201 server01 # new server
::2 hogeserver # this is a server
`)
})
}