1
1
package com.plugin.sequentialcommands
2
2
3
+ import com.dtolabs.rundeck.core.common.INodeDesc
4
+ import com.dtolabs.rundeck.core.execution.ExecutionContext
5
+ import com.dtolabs.rundeck.core.execution.ExecutionListener
6
+ import com.dtolabs.rundeck.core.execution.workflow.steps.node.NodeStepException
3
7
import com.dtolabs.rundeck.plugins.step.PluginStepContext
4
8
import com.dtolabs.rundeck.core.execution.workflow.steps.StepException
5
9
import com.dtolabs.rundeck.plugins.PluginLogger
6
10
import com.dtolabs.rundeck.core.common.INodeEntry
11
+ import com.dtolabs.rundeck.core.common.Framework
12
+ import com.dtolabs.rundeck.core.storage.keys.KeyStorageTree
7
13
import spock.lang.Specification
8
14
9
15
class SequentialcommandsSpec extends Specification {
@@ -14,45 +20,260 @@ class SequentialcommandsSpec extends Specification {
14
20
}
15
21
}
16
22
17
- def " check Boolean parameter " (){
23
+ def " Check SSH Key path " () {
18
24
19
25
given :
26
+ def Sequential = new Sequentialcommands ()
27
+ def storageTree = Mock (KeyStorageTree )
28
+ storageTree. getResource(" keys/123" ) >> { throw NodeStepException (e);}
29
+ def executionListener = Mock (ExecutionListener )
30
+ def executionContext = Mock (ExecutionContext ){
31
+ getExecutionListener() >> executionListener
32
+ getStorageTree() >> storageTree
20
33
21
- def example = new Sequentialcommands ()
22
- def context = getContext( Mock ( PluginLogger ))
23
- def node = Mock ( INodeEntry ){
24
- getNodename() >> " Test "
25
- getAttributes() >> [ " attr:name " : " Test " ]
26
- }
34
+ }
35
+ INodeEntry node = new INodeEntry () {
36
+ @Override
37
+ String getOsFamily () {
38
+ return null
39
+ }
27
40
28
- def configuration = [example :" example123" ,exampleBoolean :" true" ]
41
+ @Override
42
+ String getOsArch () {
43
+ return null
44
+ }
45
+
46
+ @Override
47
+ String getOsVersion () {
48
+ return null
49
+ }
50
+
51
+ @Override
52
+ String getOsName () {
53
+ return null
54
+ }
55
+
56
+ @Override
57
+ String getNodename () {
58
+ return null
59
+ }
60
+
61
+ @Override
62
+ String getUsername () {
63
+ return null
64
+ }
65
+
66
+ @Override
67
+ boolean containsUserName () {
68
+ return false
69
+ }
70
+
71
+ @Override
72
+ boolean containsPort () {
73
+ return false
74
+ }
29
75
76
+ @Override
77
+ String extractUserName () {
78
+ return null
79
+ }
80
+
81
+ @Override
82
+ String extractHostname () {
83
+ return null
84
+ }
85
+
86
+ @Override
87
+ String extractPort () {
88
+ return null
89
+ }
90
+
91
+ @Override
92
+ String getFrameworkProject () {
93
+ return null
94
+ }
95
+
96
+ @Override
97
+ String getDescription () {
98
+ return null
99
+ }
100
+
101
+ @Override
102
+ Set getTags () {
103
+ return null
104
+ }
105
+
106
+ @Override
107
+ Map<String , String > getAttributes () {
108
+ return [" nodename" :" myDevice" ," username" :" myUserName" ," ssh-password-storage-path" :" keys/ssh-pass" ]
109
+ }
110
+
111
+ @Override
112
+ String getHostname () {
113
+ return null
114
+ }
115
+
116
+ @Override
117
+ boolean equals (INodeDesc n ) {
118
+ return false
119
+ }
120
+ }
121
+ def context = Mock (PluginStepContext ) {
122
+ getExecutionContext() >> executionContext
123
+ getLogger() >> Mock (PluginLogger )
124
+ }
125
+ def configuration = [region :" us-west-1" ,accountId :" 1234567890" ]
30
126
when :
31
- example . executeNodeStep(context,configuration,node)
127
+ Sequential . executeNodeStep(context,configuration,node)
32
128
33
129
then :
34
- thrown StepException
130
+ NodeStepException e = thrown()
131
+ e. message == " error accessing keys/ssh-pass from Key Storage: no resource for path"
132
+
35
133
}
36
134
37
- def " run OK" (){
135
+ def " Check SSH Key Node Attribute" () {
136
+
137
+ given :
138
+ def Sequential = new Sequentialcommands ()
139
+ def context = Mock (PluginStepContext ){
140
+ getFramework() >> Mock (Framework )
141
+ }
142
+ INodeEntry node = new INodeEntry () {
143
+ @Override
144
+ String getOsFamily () {
145
+ return null
146
+ }
147
+
148
+ @Override
149
+ String getOsArch () {
150
+ return null
151
+ }
152
+
153
+ @Override
154
+ String getOsVersion () {
155
+ return null
156
+ }
157
+
158
+ @Override
159
+ String getOsName () {
160
+ return null
161
+ }
162
+
163
+ @Override
164
+ String getNodename () {
165
+ return null
166
+ }
167
+
168
+ @Override
169
+ String getUsername () {
170
+ return null
171
+ }
172
+
173
+ @Override
174
+ boolean containsUserName () {
175
+ return false
176
+ }
177
+
178
+ @Override
179
+ boolean containsPort () {
180
+ return false
181
+ }
182
+
183
+ @Override
184
+ String extractUserName () {
185
+ return null
186
+ }
187
+
188
+ @Override
189
+ String extractHostname () {
190
+ return null
191
+ }
192
+
193
+ @Override
194
+ String extractPort () {
195
+ return null
196
+ }
197
+
198
+ @Override
199
+ String getFrameworkProject () {
200
+ return null
201
+ }
202
+
203
+ @Override
204
+ String getDescription () {
205
+ return null
206
+ }
207
+
208
+ @Override
209
+ Set getTags () {
210
+ return null
211
+ }
212
+
213
+ @Override
214
+ Map<String , String > getAttributes () {
215
+ return [" nodename" :" myDevice" ," username" :" myUserName" ]
216
+ }
217
+
218
+ @Override
219
+ String getHostname () {
220
+ return null
221
+ }
222
+
223
+ @Override
224
+ boolean equals (INodeDesc n ) {
225
+ return false
226
+ }
227
+ }
228
+ def configuration = [region :" us-west-1" ,accountId :" 1234567890" ]
229
+ when :
230
+ Sequential . executeNodeStep(context,configuration,node)
231
+
232
+ then :
233
+ NodeStepException e = thrown()
234
+ e. message == " SSH Key or Password must be defined as node attribute."
235
+
236
+ }
237
+
238
+ def " check Boolean parameter" (){
38
239
39
240
given :
40
241
41
242
def example = new Sequentialcommands ()
42
- def logger = Mock (PluginLogger )
43
- def context = getContext(logger)
243
+ def context = getContext(Mock (PluginLogger ))
44
244
def node = Mock (INodeEntry ){
45
245
getNodename()>> " Test"
46
246
getAttributes()>> [" attr:name" :" Test" ]
47
247
}
48
248
49
- def configuration = [example :" example123" ,exampleBoolean :" false " ]
249
+ def configuration = [example :" example123" ,exampleBoolean :" true " ]
50
250
51
251
when :
52
252
example. executeNodeStep(context,configuration,node)
53
253
54
254
then :
55
- 1 * logger . log( 2 , " Example node step executing on node: Test " )
255
+ thrown StepException
56
256
}
57
257
258
+ // def "run OK"(){
259
+ //
260
+ // given:
261
+ //
262
+ // def example = new Sequentialcommands()
263
+ // def logger = Mock(PluginLogger)
264
+ // def context = getContext(logger)
265
+ // def node = Mock(INodeEntry){
266
+ // getNodename()>>"Test"
267
+ // getAttributes()>>["attr:name":"Test"]
268
+ // }
269
+ //
270
+ // def configuration = [example:"example123",exampleBoolean:"false"]
271
+ //
272
+ // when:
273
+ // example.executeNodeStep(context,configuration,node)
274
+ //
275
+ // then:
276
+ // 1 * logger.log(2, "Example node step executing on node: Test")
277
+ // }
278
+
58
279
}
0 commit comments