48 lines
1.1 KiB
Go
48 lines
1.1 KiB
Go
package ansible
|
|
|
|
import (
|
|
"testing"
|
|
"time"
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
)
|
|
|
|
func TestSSH_NewSSHClient_Good_CustomConfig(t *testing.T) {
|
|
cfg := SSHConfig{
|
|
Host: "localhost",
|
|
Port: 2222,
|
|
User: "root",
|
|
}
|
|
|
|
client, err := NewSSHClient(cfg)
|
|
assert.NoError(t, err)
|
|
assert.NotNil(t, client)
|
|
assert.Equal(t, "localhost", client.host)
|
|
assert.Equal(t, 2222, client.port)
|
|
assert.Equal(t, "root", client.user)
|
|
assert.Equal(t, 30*time.Second, client.timeout)
|
|
}
|
|
|
|
func TestSSH_NewSSHClient_Good_Defaults(t *testing.T) {
|
|
cfg := SSHConfig{
|
|
Host: "localhost",
|
|
}
|
|
|
|
client, err := NewSSHClient(cfg)
|
|
assert.NoError(t, err)
|
|
assert.Equal(t, 22, client.port)
|
|
assert.Equal(t, "root", client.user)
|
|
assert.Equal(t, 30*time.Second, client.timeout)
|
|
}
|
|
|
|
func TestSSH_SSHClient_Good_CommandWithEnvironment(t *testing.T) {
|
|
client := &SSHClient{}
|
|
client.SetEnvironment(map[string]string{
|
|
"BETA": "two words",
|
|
"ALPHA": "O'Reilly",
|
|
})
|
|
|
|
cmd := client.commandWithEnvironment("echo done")
|
|
|
|
assert.Equal(t, "export ALPHA='O'\\''Reilly'; export BETA='two words'; echo done", cmd)
|
|
}
|