-
Notifications
You must be signed in to change notification settings - Fork 0
/
ansiblePlaybook_test.go
90 lines (74 loc) · 2.45 KB
/
ansiblePlaybook_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
package ansible
import (
"os"
"testing"
)
// TestPrivateKey tests the privateKey method of AnsiblePlaybook.
func TestPrivateKey(t *testing.T) {
// Initialize an AnsiblePlaybook instance with a test private key.
ap := AnsiblePlaybook{
Config: Config{
PrivateKey: "test-key",
},
}
// Execute the privateKey method and check for errors.
err := ap.privateKey()
if err != nil {
t.Errorf("privateKey() failed: %s", err)
}
// Read the content of the generated private key file.
content, err := os.ReadFile(ap.Config.PrivateKeyFile)
if err != nil {
t.Errorf("Read private key file failed: %s", err)
}
// Assert that the content of the file matches the expected private key.
if string(content) != "test-key" {
t.Errorf("Expected private key content to be 'test-key', got '%s'", string(content))
}
}
// TestVersionCommand tests the versionCommand method of AnsiblePlaybook.
func TestVersionCommand(t *testing.T) {
// Initialize an AnsiblePlaybook instance.
ap := AnsiblePlaybook{}
// Execute the versionCommand method.
cmd := ap.versionCommand()
if cmd == nil {
t.Errorf("versionCommand() returned nil")
}
// Assert the correctness of the command and arguments.
// Additional checks for command arguments can be added here.
}
// TestExecSuccess tests the Exec method of AnsiblePlaybook for successful execution.
func TestExecSuccess(t *testing.T) {
// Initialize an AnsiblePlaybook instance with a mock configuration.
playbook := &AnsiblePlaybook{
Config: Config{
Playbooks: []string{"tests/test.yml"},
},
}
// Note: Mock external dependencies here if necessary.
// Execute the Exec method and expect no errors.
if err := playbook.Exec(); err != nil {
t.Errorf("Exec should execute without error, but received: %v", err)
}
// Additional assertions to verify expected behavior can be added here.
}
// TestVaultPass tests the vaultPass method of AnsiblePlaybook.
func TestVaultPass(t *testing.T) {
// Initialize an AnsiblePlaybook instance with a test vault password.
playbook := &AnsiblePlaybook{
Config: Config{
VaultPassword: "test-password",
},
}
// Execute the vaultPass method and check for errors.
err := playbook.vaultPass()
if err != nil {
t.Errorf("vaultPass should not return an error, but received: %v", err)
}
// Assert that the VaultPasswordFile property is set correctly.
if playbook.Config.VaultPasswordFile == "" {
t.Error("VaultPasswordFile should not be empty")
}
// Cleanup (delete file) if necessary.
}