forked from Praqma/helmsman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
plan_test.go
210 lines (203 loc) · 4.44 KB
/
plan_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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
package main
import (
"reflect"
"testing"
"time"
)
func Test_createPlan(t *testing.T) {
tests := []struct {
name string
want plan
}{
{
name: "test creating a plan",
want: createPlan(),
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
if got := createPlan(); reflect.DeepEqual(got, tt.want) {
t.Errorf("createPlan() = %v, want %v", got, tt.want)
}
})
}
}
func Test_plan_addCommand(t *testing.T) {
type fields struct {
Commands []orderedCommand
Decisions []orderedDecision
Created time.Time
}
type args struct {
c command
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "testing command 1",
fields: fields{
Commands: []orderedCommand{},
Decisions: []orderedDecision{},
Created: time.Now(),
},
args: args{
c: command{
Cmd: "bash",
Args: []string{"-c", "echo this is fun"},
Description: "A bash command execution test with echo.",
},
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &plan{
Commands: tt.fields.Commands,
Decisions: tt.fields.Decisions,
Created: tt.fields.Created,
}
r := &release{}
p.addCommand(tt.args.c, 0, r)
if got := len(p.Commands); got != 1 {
t.Errorf("addCommand(): got %v, want 1", got)
}
})
}
}
func Test_plan_addDecision(t *testing.T) {
type fields struct {
Commands []orderedCommand
Decisions []orderedDecision
Created time.Time
}
type args struct {
decision string
}
tests := []struct {
name string
fields fields
args args
}{
{
name: "testing decision adding",
fields: fields{
Commands: []orderedCommand{},
Decisions: []orderedDecision{},
Created: time.Now(),
},
args: args{
decision: "This is a test decision.",
},
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
p := &plan{
Commands: tt.fields.Commands,
Decisions: tt.fields.Decisions,
Created: tt.fields.Created,
}
p.addDecision(tt.args.decision, 0, noop)
if got := len(p.Decisions); got != 1 {
t.Errorf("addDecision(): got %v, want 1", got)
}
})
}
}
// func Test_plan_execPlan(t *testing.T) {
// type fields struct {
// Commands []command
// Decisions []string
// Created time.Time
// }
// tests := []struct {
// name string
// fields fields
// }{
// {
// name: "testing executing a plan",
// fields: fields{
// Commands: []command{
// {
// Cmd: "bash",
// Args: []string{"-c", "touch hello.world"},
// Description: "Creating hello.world file.",
// }, {
// Cmd: "bash",
// Args: []string{"-c", "touch hello.world1"},
// Description: "Creating hello.world1 file.",
// },
// },
// Decisions: []string{"Create hello.world.", "Create hello.world1."},
// Created: time.Now(),
// },
// },
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// p := plan{
// Commands: tt.fields.Commands,
// Decisions: tt.fields.Decisions,
// Created: tt.fields.Created,
// }
// p.execPlan()
// c := command{
// Cmd: "bash",
// Args: []string{"-c", "ls | grep hello.world | wc -l"},
// Description: "",
// }
// if _, got := c.exec(false, false); strings.TrimSpace(got) != "2" {
// t.Errorf("execPlan(): got %v, want hello world, again!", got)
// }
// })
// }
// }
// func Test_plan_printPlanCmds(t *testing.T) {
// type fields struct {
// Commands []command
// Decisions []string
// Created time.Time
// }
// tests := []struct {
// name string
// fields fields
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// p := plan{
// Commands: tt.fields.Commands,
// Decisions: tt.fields.Decisions,
// Created: tt.fields.Created,
// }
// p.printPlanCmds()
// })
// }
// }
// func Test_plan_printPlan(t *testing.T) {
// type fields struct {
// Commands []command
// Decisions []string
// Created time.Time
// }
// tests := []struct {
// name string
// fields fields
// }{
// // TODO: Add test cases.
// }
// for _, tt := range tests {
// t.Run(tt.name, func(t *testing.T) {
// p := plan{
// Commands: tt.fields.Commands,
// Decisions: tt.fields.Decisions,
// Created: tt.fields.Created,
// }
// p.printPlan()
// })
// }
// }