go-ansible/ssh_test.go
Virgil 82c7c73d50
Some checks are pending
CI / test (push) Waiting to run
CI / auto-fix (push) Waiting to run
CI / auto-merge (push) Waiting to run
fix(ansible): clear become state when disabled
Co-Authored-By: Virgil <virgil@lethean.io>
2026-04-03 11:41:04 +00:00

52 lines
1.2 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_SetBecome_Good_DisablesAndClearsState(t *testing.T) {
client := &SSHClient{}
client.SetBecome(true, "admin", "secret")
become, user, password := client.BecomeState()
assert.True(t, become)
assert.Equal(t, "admin", user)
assert.Equal(t, "secret", password)
client.SetBecome(false, "", "")
become, user, password = client.BecomeState()
assert.False(t, become)
assert.Empty(t, user)
assert.Empty(t, password)
}