-
Notifications
You must be signed in to change notification settings - Fork 64
/
run_list_item_test.go
164 lines (146 loc) · 4.32 KB
/
run_list_item_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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
package chef
import (
"testing"
)
func TestQualifiedRecipeWithVersion(t *testing.T) {
runListItem := "recipe[[email protected]]"
rli, err := NewRunListItem(runListItem)
if err != nil {
t.Errorf(`NewRunListItem("%s") did not correctly parse.`, runListItem)
}
if rli.Name != "my_recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set name`, runListItem)
}
if rli.Type != "recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set type`, runListItem)
}
if rli.Version != "1.0.0" {
t.Errorf(`NewRunListItem("%s") did not correctly set version`, runListItem)
}
}
func TestQualifiedRecipe(t *testing.T) {
runListItem := "recipe[my_recipe]"
rli, err := NewRunListItem(runListItem)
if err != nil {
t.Errorf(`NewRunListItem("%s") did not correctly parse.`, runListItem)
}
if rli.Name != "my_recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set name`, runListItem)
}
if rli.Type != "recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set type`, runListItem)
}
if rli.Version != "" {
t.Errorf(`NewRunListItem("%s") did not correctly set version`, runListItem)
}
}
func TestQualifiedRole(t *testing.T) {
runListItem := "role[my_role]"
rli, err := NewRunListItem(runListItem)
if err != nil {
t.Errorf(`NewRunListItem("%s") did not correctly parse.`, runListItem)
}
if rli.Name != "my_role" {
t.Errorf(`NewRunListItem("%s") did not correctly set name`, runListItem)
}
if rli.Type != "role" {
t.Errorf(`NewRunListItem("%s") did not correctly set type, %s`, runListItem, rli.Type)
}
if rli.Version != "" {
t.Errorf(`NewRunListItem("%s") did not correctly set version`, runListItem)
}
}
func TestVersionedUnqualifiedRecipe(t *testing.T) {
runListItem := "[email protected]"
rli, err := NewRunListItem(runListItem)
if err != nil {
t.Errorf(`NewRunListItem("%s") did not correctly parse.`, runListItem)
}
if rli.Name != "my_recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set name`, runListItem)
}
if rli.Type != "recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set type`, runListItem)
}
if rli.Version != "1.0.0" {
t.Errorf(`NewRunListItem("%s") did not correctly set version`, runListItem)
}
}
func TestRecipeNameAlone(t *testing.T) {
runListItem := "my_recipe"
rli, err := NewRunListItem(runListItem)
if err != nil {
t.Errorf(`NewRunListItem("%s") did not correctly parse.`, runListItem)
}
if rli.Name != "my_recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set name`, runListItem)
}
if rli.Type != "recipe" {
t.Errorf(`NewRunListItem("%s") did not correctly set type`, runListItem)
}
if rli.Version != "" {
t.Errorf(`NewRunListItem("%s") did not correctly set version`, runListItem)
}
}
func TestBadCase(t *testing.T) {
runListItem := "Recipe[my_recipe]" // Capital R
_, err := NewRunListItem(runListItem)
if err == nil {
t.Errorf(`NewRunListItem("%s") should have returned and error and it didn't.`, runListItem)
}
}
func TestSpaceThrowsError(t *testing.T) {
runListItem := "recipe [my_recipe]"
_, err := NewRunListItem(runListItem)
if err == nil {
t.Errorf(`NewRunListItem("%s") should have returned and error and it didn't.`, runListItem)
}
}
func TestMissingClosingBracketThrowsError(t *testing.T) {
runListItem := "recipe[my_recipe"
_, err := NewRunListItem(runListItem)
if err == nil {
t.Errorf(`NewRunListItem("%s") should have returned and error and it didn't.`, runListItem)
}
}
func TestStringConversion(t *testing.T) {
runListItems := []string{
"recipe[[email protected]]",
"recipe[my_recipe]",
"role[my_recipe]",
}
for _, runListItem := range runListItems {
rli, err := NewRunListItem(runListItem)
if err != nil || rli.String() != runListItem {
t.Errorf(`NewRunListItem("%s").String() does not match %s`, runListItem, runListItem)
}
}
}
func TestIsRecipe(t *testing.T) {
recipe := RunListItem{
Type: "recipe",
}
if recipe.IsRecipe() != true {
t.Error(`IsRecipe() should return true for recipe`)
}
role := RunListItem{
Type: "role",
}
if role.IsRecipe() != false {
t.Error(`IsRecipe() should return false for role`)
}
}
func TestIsRole(t *testing.T) {
recipe := RunListItem{
Type: "role",
}
if recipe.IsRole() != true {
t.Error(`IsRole() should return true for role`)
}
role := RunListItem{
Type: "recipe",
}
if role.IsRole() != false {
t.Error(`IsRole() should return false for recipe`)
}
}