-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from arillso/refactor/galaxy-api-support
Refactor/galaxy api support
- Loading branch information
Showing
4 changed files
with
253 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,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. | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
--- | ||
- name: "Check Ansible Connection via SSH" | ||
hosts: localhost | ||
connection: local | ||
gather_facts: true | ||
tasks: | ||
- name: "Test Connection to Hosts" | ||
ansible.builtin.ping: |