go-ansible/ssh_test.go
Virgil ac55514427
Some checks failed
CI / test (push) Failing after 2s
CI / auto-fix (push) Failing after 0s
CI / auto-merge (push) Failing after 0s
feat(ansible): apply play and task environment
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-01 06:32:15 +00:00

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)
}