-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsshs_test.go
80 lines (64 loc) · 1.7 KB
/
sshs_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
package main
import (
"os"
)
import "io/ioutil"
import "testing"
const selma0004 string = `
Host server004
User root
Hostname 10.1.2.3
Port 22
Protocol 2
IdentityFile /home/user/.ssh/id_rsa
ProxyCommand none
Host server00024
User root
Hostname 10.1.2.3
Port 22
Protocol 2
IdentityFile home/user/.ssh/id_rsa
ProxyCommand ssh -W %h:%p -q [email protected]
`
func Test_parseChunks(t *testing.T) {
t.Run("parseChunks reading from tmp file", func(t *testing.T) {
content := []byte(selma0004)
tmpfile, err := ioutil.TempFile("", "host_info.*.test")
if err != nil {
t.Error(err)
}
defer os.Remove(tmpfile.Name()) // clean up
if _, err := tmpfile.Write(content); err != nil {
t.Error(err)
}
if err := tmpfile.Close(); err != nil {
t.Error(err)
}
// set up some channels and test parseChunks
chunkChan := make(chan []string)
stopChan := make(chan bool)
go parseChunks(tmpfile.Name(), chunkChan, stopChan)
chunkCounter := 0
for range chunkChan {
chunkCounter++
}
if chunkCounter != 2 {
t.Error("Failed to get 2 chunks from parseChunks()")
}
})
}
func Test_NewHostInfo(t *testing.T) {
t.Run("Make HostInfo struct with bad data", func(t *testing.T) {
if _, err := NewHostInfo([]string{"", "", "", "", ""}); (err == nil) != false {
t.Error("NewHostInfo didn't return error when it should have")
}
})
t.Run("Make HostInfo struct with good data", func(t *testing.T) {
dats := []string{"Host selma0004", "User root", "Hostname 10.1.0.156",
"Port 22", "Protocol 2", "IdentityFile /home/alex/.ssh/gitolite",
"ProxyCommand none"}
if _, err := NewHostInfo(dats); (err != nil) != false {
t.Errorf("NewHostInfo returned error: %v", err)
}
})
}