forked from dullgiulio/sshconfig
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse_test.go
48 lines (42 loc) · 1.09 KB
/
parse_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
package sshconfig_test
import (
"bytes"
"io"
"testing"
"github.com/dullgiulio/sshconfig"
)
func reader(s string) io.Reader {
return bytes.NewReader([]byte(s))
}
func TestHostSection(t *testing.T) {
hostSection := `# Some example Host section
Host local # Local SSH
OptionOne do anything here
OptionTwo 12345 # There is also a comment
OptionWithoutValue
OptionsWithComment # Comment
`
sections, err := sshconfig.Parse(reader(hostSection))
if err != nil {
t.Fatal(err)
}
if len(sections) != 1 {
t.Error("Unexpected number of sections")
}
s0 := sections[0]
if s0.Name != "local" {
t.Error("Unexpected section name")
}
if s0.Values["OptionOne"] != "do anything here" {
t.Error("Unexpected option value (composite string)")
}
if s0.Values["OptionTwo"] != "12345" {
t.Error("Unexpected option value (numeric)")
}
if v, ok := s0.Values["OptionWithoutValue"]; !ok || v != "" {
t.Error("Unexpected value for option without value, or not parsed")
}
if v, ok := s0.Values["OptionsWithComment"]; !ok || v != "" {
t.Error("Unexpected value for option without value, or not parsed")
}
}