-
Notifications
You must be signed in to change notification settings - Fork 0
/
client_config_test.go
60 lines (52 loc) · 1.45 KB
/
client_config_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
package sshx
import (
"testing"
"time"
"golang.org/x/crypto/ssh"
"gotest.tools/v3/assert"
)
func Test_ClientConfig_Validate(t *testing.T) {
t.Run("ok", func(t *testing.T) {
assert.NilError(t, (&ClientConfig{
Addr: "1",
SSHClientConfig: ssh.ClientConfig{Timeout: time.Second},
Bridge: &ClientConfig{
Addr: "2",
SSHClientConfig: ssh.ClientConfig{Timeout: time.Second},
},
}).Validate())
})
t.Run("ko", func(t *testing.T) {
t.Run("empty addr", func(t *testing.T) {
err := (&ClientConfig{
SSHClientConfig: ssh.ClientConfig{Timeout: time.Second},
}).Validate()
assert.ErrorContains(t, err, "empty addr")
})
t.Run("empty network timeout", func(t *testing.T) {
err := (&ClientConfig{
Addr: "1",
}).Validate()
assert.ErrorContains(t, err, "empty network timeout")
})
t.Run("bridge invalid", func(t *testing.T) {
err := (&ClientConfig{
Addr: "1",
SSHClientConfig: ssh.ClientConfig{Timeout: time.Second},
Bridge: &ClientConfig{},
}).Validate()
assert.ErrorContains(t, err, "bridge of 1 config is invalid: empty addr")
})
})
}
func newTestingClientConfig(t *testing.T, addr, user string) *ClientConfig {
t.Helper()
return &ClientConfig{
Addr: addr,
SSHClientConfig: ssh.ClientConfig{
User: user,
HostKeyCallback: ssh.InsecureIgnoreHostKey(), //nolint:gosec // its a test we don't care
Timeout: time.Minute,
},
}
}