-
Notifications
You must be signed in to change notification settings - Fork 5
/
command_sshconfig_test.go
105 lines (96 loc) · 3.3 KB
/
command_sshconfig_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
package vagrant
import (
"testing"
)
func init() {
successfulOutput["ssh-config"] = `
1534898948,default,metadata,provider,virtualbox
1534898948,default,ssh-config,Host default\n HostName 127.0.0.1\n User core\n Port 2222\n UserKnownHostsFile /dev/null\n StrictHostKeyChecking no\n PasswordAuthentication no\n IdentityFile /Users/user/.vagrant.d/insecure_private_key\n IdentitiesOnly yes\n LogLevel FATAL\n ForwardAgent yes\nUnknownField no\n
Host default
HostName 127.0.0.1
User core
Port 2222
UserKnownHostsFile /dev/null
StrictHostKeyChecking no
PasswordAuthentication no
IdentityFile /Users/user/.vagrant.d/insecure_private_key
IdentitiesOnly yes
LogLevel FATAL
ForwardAgent yes
UnknownField no
`
}
func TestSSHConfigCommand_buildArguments(t *testing.T) {
client := newMockVagrantClient()
t.Run("default", func(t *testing.T) {
cmd := client.SSHConfig()
args := cmd.buildArguments()
assertArguments(t, args)
})
t.Run("host", func(t *testing.T) {
cmd := client.SSHConfig()
cmd.Host = "default"
args := cmd.buildArguments()
assertArguments(t, args, "--host", "default")
})
}
func TestSSHConfigCommand_Run(t *testing.T) {
client := newMockVagrantClient()
cmd := client.SSHConfig()
if err := cmd.Run(); err != nil {
t.Fatalf("Command failed to run: %v", err)
}
if cmd.Error != nil {
t.Fatalf("Command returned error: %v", cmd.Error)
}
if len(cmd.Configs) != 1 {
t.Fatalf("Expecting 1 config; got %v", len(cmd.Configs))
}
config, ok := cmd.Configs["default"]
if !ok {
t.Fatalf("Expecting a config for 'default' but didn't get it")
}
if config.Host != "default" {
t.Errorf("Expecting Host to be 'default'; got %v", config.Host)
}
if config.HostName != "127.0.0.1" {
t.Errorf("Expecting HostName to be '127.0.0.1'; got %v", config.HostName)
}
if config.User != "core" {
t.Errorf("Expecting User to be 'core'; got %v", config.User)
}
if config.Port != 2222 {
t.Errorf("Expecting Port to be '2222'; got %v", config.Port)
}
if config.UserKnownHostsFile != "/dev/null" {
t.Errorf("Expecting UserKnownHostsFile to be '/dev/null'; got %v", config.UserKnownHostsFile)
}
if config.StrictHostKeyChecking != "no" {
t.Errorf("Expecting StrictHostKeyChecking to be 'no'; got %v", config.StrictHostKeyChecking)
}
if config.PasswordAuthentication != "no" {
t.Errorf("Expecting PasswordAuthentication to be 'no'; got %v", config.PasswordAuthentication)
}
if config.IdentityFile != "/Users/user/.vagrant.d/insecure_private_key" {
t.Errorf("Expecting IdentityFile to be '/Users/user/.vagrant.d/insecure_private_key'; got %v", config.IdentityFile)
}
if config.IdentitiesOnly != "yes" {
t.Errorf("Expecting IdentitiesOnly to be 'yes'; got %v", config.IdentitiesOnly)
}
if config.LogLevel != "FATAL" {
t.Errorf("Expecting LogLevel to be 'FATAL'; got %v", config.LogLevel)
}
if config.ForwardAgent != "yes" {
t.Errorf("Expecting ForwardAgent to be 'yes'; got %v", config.ForwardAgent)
}
if len(config.AdditionalFields) == 0 {
t.Errorf("Expecting len(AdditionalFields) to be >0; got %v", len(config.AdditionalFields))
} else {
field, ok := config.AdditionalFields["UnknownField"]
if !ok {
t.Errorf("Expecting AdditionalFields to have an 'UnknownField'")
} else if field != "no" {
t.Errorf("Expecting 'UnknownField' to have a value of 'no'; got %v", field)
}
}
}