-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathplaybook_test.go
75 lines (62 loc) · 1.67 KB
/
playbook_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
package ansible
import (
"fmt"
"github.com/stretchr/testify/assert"
"testing"
)
const (
TestPlaybookPath = "/playbook.yaml"
TestInventoryPath = "/inventory.ini"
)
var (
TestExtraVars = map[string]string{
"k1": "v1",
"k2": "v2",
}
TestBaseCmd = fmt.Sprintf("ansible-playbook -i %s %s", TestInventoryPath, TestPlaybookPath)
)
func TestPlaybook(t *testing.T) {
pb := Playbook()
assert.NotNil(t, pb.extraVars)
assert.Empty(t, pb.inventoryPath)
assert.Empty(t, pb.playbookPath)
}
func TestPlaybook_ExtraVars(t *testing.T) {
pb := Playbook()
vars := map[string]string{
"test": "test",
}
pb.ExtraVars(vars)
assert.Equal(t, vars, pb.extraVars)
pb.ExtraVars(map[string]string{"test-2": "test"})
assert.NotEqual(t, vars, pb.extraVars)
}
func TestPlaybook_ExtraVarsString(t *testing.T) {
pb := Playbook()
pb.ExtraVars(TestExtraVars)
assert.Contains(t, pb.extraVarsToString(), "-e k1=v1")
assert.Contains(t, pb.extraVarsToString(), "-e k2=v2")
}
func TestPlaybook_Inventory(t *testing.T) {
pb := Playbook().Inventory(TestInventoryPath)
assert.Equal(t, TestInventoryPath, pb.inventoryPath)
}
func TestPlaybook_Path(t *testing.T) {
pb := Playbook().Path(TestPlaybookPath)
assert.Equal(t, TestPlaybookPath, pb.playbookPath)
}
func TestPlaybook_BaseCmd(t *testing.T) {
pb := Playbook().
Inventory(TestInventoryPath).
Path(TestPlaybookPath)
assert.Equal(t, TestBaseCmd, pb.baseCmd())
}
func TestPlaybook_Command(t *testing.T) {
pb := Playbook().
Inventory(TestInventoryPath).
Path(TestPlaybookPath).
ExtraVars(TestExtraVars)
assert.Contains(t, pb.Command(), TestBaseCmd)
assert.Contains(t, pb.Command(), "-e k1=v1")
assert.Contains(t, pb.Command(), "-e k2=v2")
}