-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmarvin_test.go
95 lines (80 loc) · 2.2 KB
/
marvin_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
91
92
93
94
95
package main
import (
"fmt"
"log"
"testing"
)
func getSampleConfig() string {
return `
tasks:
mysql: mysql_command
template: :db :port :host
task: ignore
inventory:
dynamic:
aws: aws_command
static: |
db:db_name host:host_name port:port_number
db:db_name2 host:host_name2 port:port_number2
nothingheretosee
`
}
func TestNewMarvinStruct(t *testing.T) {
m := newMarvin(getSampleConfig(), ".", "db:", "ls", "")
if taskCommand, taskExists := m.Tasks["mysql"]; !taskExists && taskCommand != "mysql_command" {
log.Fatalf("Expected mysql_command, Actual: " + taskCommand)
}
if dInventoryCommand, dInventoryExists := m.Inventory.Dynamic["aws"]; !dInventoryExists && dInventoryCommand != "aws_command" {
log.Fatalf("Expected aws_command, Actual: " + dInventoryCommand)
}
}
func TestRawToInventory(t *testing.T) {
m := newMarvin(getSampleConfig(), ".", "db:", "ls", "")
if len(m.Inventory.static) != 3 {
log.Fatalf("Expected 3 static inventories")
}
if m.Inventory.static[0]["db"] != "db_name" {
log.Fatalf("1st inventory should be db:db_name")
}
if m.Inventory.static[1]["db"] != "db_name2" {
log.Fatalf("2nd inventory should be db:db_name2")
}
fmt.Println(m.Inventory.static[2])
if m.Inventory.static[2]["id"] != "nothingheretosee" {
log.Fatalf("Without a ':', id should be the key")
}
}
func TestMarvinFilter(t *testing.T) {
m := newMarvin(getSampleConfig(), ".", "db:*", "ls", "")
if len(m.filtered) != 2 {
log.Fatalf("Should be 2 db matches")
}
m.filter("db:db_name2")
if len(m.filtered) != 1 {
log.Fatalf("Should only be 1 db_name2 matches")
}
m.filter("id:not*")
if len(m.filtered) != 1 {
log.Fatalf("Should only be 1 not*")
}
m.filter("id:nothingheretosee")
if len(m.filtered) != 1 {
log.Fatalf("Should only be 1 *here")
}
m.filter("db")
if len(m.filtered) != 2 {
log.Fatalf("Should only be 2 *here")
}
m.filter("bingowashisnameo")
if len(m.filtered) != 0 {
log.Fatalf("bingowashisnameo should have have matched anything")
}
m.filter("db:bingowashisnameo")
if len(m.filtered) != 0 {
log.Fatalf("bingowashisnameo should have have matched anything")
}
m.filter("db:*name")
if len(m.filtered) != 2 {
log.Fatalf("Should have been 2 matches")
}
}