forked from vmware-archive/cfops
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcfops_suite_test.go
More file actions
178 lines (145 loc) · 3.33 KB
/
cfops_suite_test.go
File metadata and controls
178 lines (145 loc) · 3.33 KB
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
package cfops_test
import (
"errors"
. "github.com/onsi/ginkgo"
. "github.com/onsi/gomega"
. "github.com/pivotalservices/cfops"
"testing"
)
func TestCfops(t *testing.T) {
RegisterFailHandler(Fail)
RunSpecs(t, "Cfops")
}
func testPipelineExecutionError(action string) {
var errMock = errors.New("random execution mock error")
Context("when an error is returned from the builtin pipeline", func() {
var fs *mockFlagSet
BeforeEach(func() {
m := mockBuiltinPipeline{
ErrReturned: errMock,
}
BuiltinPipelineExecution[action] = m.action
fs = &mockFlagSet{
tileListFlag: "",
}
})
It("should return the error", func() {
Ω(RunPipeline(fs, action)).ShouldNot(BeNil())
Ω(RunPipeline(fs, action)).Should(Equal(errMock))
})
})
}
func testWithValidTilelist(action string) {
Context("with invalid tile list flag", func() {
var (
fs *mockFlagSet
mTile *mockTile
)
BeforeEach(func() {
mTile = &mockTile{}
SupportedTiles = map[string]func() (Tile, error){
"TESTFLAG": func() (Tile, error) {
return mTile, nil
},
}
m := mockBuiltinPipeline{}
BuiltinPipelineExecution[action] = m.action
fs = &mockFlagSet{
tileListFlag: "badflag",
}
})
It("should return an error", func() {
Ω(RunPipeline(fs, action)).ShouldNot(BeNil())
})
It("should not call the action on the tiles in your list", func() {
RunPipeline(fs, action)
Ω(mTile.RunCount).Should(Equal(0))
})
})
}
func testWithInvalidTileList(action string) {
Context("with valid tile list flag", func() {
var (
fs *mockFlagSet
mTile *mockTile
)
BeforeEach(func() {
mTile = &mockTile{}
SupportedTiles = map[string]func() (Tile, error){
"TESTFLAG": func() (Tile, error) {
return mTile, nil
},
}
m := mockBuiltinPipeline{}
BuiltinPipelineExecution[action] = m.action
fs = &mockFlagSet{
tileListFlag: "testflag",
}
})
It("should not return an error", func() {
Ω(RunPipeline(fs, action)).Should(BeNil())
})
It("should call the action on the tiles in your list", func() {
RunPipeline(fs, action)
Ω(mTile.RunCount).Should(BeNumerically(">", 0))
})
})
}
func testWithoutTilelist(action string) {
Context("without tile list flag", func() {
var fs *mockFlagSet
BeforeEach(func() {
m := mockBuiltinPipeline{}
BuiltinPipelineExecution[action] = m.action
fs = &mockFlagSet{
tileListFlag: "",
}
})
It("should run the builtin pipeline", func() {
Ω(RunPipeline(fs, action)).Should(BeNil())
})
})
}
type mockFlagSet struct {
tileListFlag string
}
func (s *mockFlagSet) Host() (r string) {
return
}
func (s *mockFlagSet) AdminUser() (r string) {
return
}
func (s *mockFlagSet) AdminPass() (r string) {
return
}
func (s *mockFlagSet) OpsManagerUser() (r string) {
return
}
func (s *mockFlagSet) OpsManagerPass() (r string) {
return
}
func (s *mockFlagSet) Dest() (r string) {
return
}
func (s *mockFlagSet) Tilelist() (r string) {
r = s.tileListFlag
return
}
type mockBuiltinPipeline struct {
ErrReturned error
}
func (s *mockBuiltinPipeline) action(string, string, string, string, string, string) error {
return s.ErrReturned
}
type mockTile struct {
ErrReturned error
RunCount int
}
func (s *mockTile) Restore() (err error) {
s.RunCount++
return
}
func (s *mockTile) Backup() (err error) {
s.RunCount++
return
}