@@ -22,7 +22,6 @@ import spock.lang.Specification
22
22
import spock.lang.TempDir
23
23
import test.OutputCapture
24
24
25
- import java.nio.file.Files
26
25
import java.nio.file.Path
27
26
28
27
/**
@@ -46,16 +45,6 @@ class CmdAuthTest extends Specification {
46
45
cmd. getName() == ' auth'
47
46
}
48
47
49
- def ' should define correct constants' () {
50
- expect :
51
- CmdAuth . SEQERA_ENDPOINTS . prod == ' https://api.cloud.seqera.io'
52
- CmdAuth . SEQERA_ENDPOINTS . stage == ' https://api.cloud.stage-seqera.io'
53
- CmdAuth . SEQERA_ENDPOINTS . dev == ' https://api.cloud.dev-seqera.io'
54
- CmdAuth . API_TIMEOUT_MS == 10000
55
- CmdAuth . AUTH_POLL_TIMEOUT_RETRIES == 60
56
- CmdAuth . AUTH_POLL_INTERVAL_SECONDS == 5
57
- CmdAuth . WORKSPACE_SELECTION_THRESHOLD == 8
58
- }
59
48
60
49
def ' should show usage when no args provided' () {
61
50
given :
@@ -92,13 +81,15 @@ class CmdAuthTest extends Specification {
92
81
93
82
def ' should throw error for unknown command' () {
94
83
given :
95
- def cmd = new CmdAuth ( )
84
+ def cmd = Spy ( CmdAuth )
96
85
cmd. args = [' unknown' ]
86
+ def operation = Mock (CmdAuth.AuthCommand )
97
87
98
88
when :
99
89
cmd. run()
100
90
101
91
then :
92
+ 1 * cmd. loadOperation() >> operation
102
93
def ex = thrown(AbortOperationException )
103
94
ex. message. contains(' Unknown auth sub-command: unknown' )
104
95
}
@@ -117,163 +108,70 @@ class CmdAuthTest extends Specification {
117
108
ex. message. contains(' login' )
118
109
}
119
110
120
- def ' should identify cloud endpoints correctly' () {
121
- given :
122
- def cmd = new CmdAuth ()
123
-
124
- expect :
125
- cmd. getCloudEndpointInfo(' https://api.cloud.seqera.io' ). isCloud == true
126
- cmd. getCloudEndpointInfo(' https://api.cloud.seqera.io' ). environment == ' prod'
127
- cmd. getCloudEndpointInfo(' https://api.cloud.stage-seqera.io' ). isCloud == true
128
- cmd. getCloudEndpointInfo(' https://api.cloud.stage-seqera.io' ). environment == ' stage'
129
- cmd. getCloudEndpointInfo(' https://api.cloud.dev-seqera.io' ). isCloud == true
130
- cmd. getCloudEndpointInfo(' https://api.cloud.dev-seqera.io' ). environment == ' dev'
131
- cmd. getCloudEndpointInfo(' https://cloud.seqera.io/api' ). isCloud == true
132
- cmd. getCloudEndpointInfo(' https://cloud.seqera.io/api' ). environment == ' prod'
133
- cmd. getCloudEndpointInfo(' https://enterprise.example.com' ). isCloud == false
134
- cmd. getCloudEndpointInfo(' https://enterprise.example.com' ). environment == null
135
- }
136
-
137
- def ' should identify cloud endpoint from URL' () {
138
- given :
139
- def cmd = new CmdAuth ()
140
-
141
- expect :
142
- cmd. isCloudEndpoint(' https://api.cloud.seqera.io' ) == true
143
- cmd. isCloudEndpoint(' https://api.cloud.stage-seqera.io' ) == true
144
- cmd. isCloudEndpoint(' https://enterprise.example.com' ) == false
145
- }
146
-
147
- def ' should validate argument count correctly' () {
148
- given :
149
- def cmd = new CmdAuth ()
150
-
151
- when :
152
- cmd. validateArgumentCount([' extra' ], ' test' )
153
-
154
- then :
155
- def ex = thrown(AbortOperationException )
156
- ex. message == ' Too many arguments for test command'
157
-
158
- when :
159
- cmd. validateArgumentCount([], ' test' )
160
-
161
- then :
162
- noExceptionThrown()
163
- }
164
-
165
- def ' should read config correctly' () {
166
- given :
167
- def cmd = new CmdAuth ()
168
-
169
- expect :
170
- // readConfig method should return a Map
171
- cmd. readConfig() instanceof Map
172
- }
173
-
174
- def ' should clean tower config from existing content' () {
175
- given :
176
- def cmd = new CmdAuth ()
177
- def content = '''
178
- // Some other config
179
- process {
180
- executor = 'local'
181
- }
182
-
183
- // Seqera Platform configuration
184
- tower {
185
- accessToken = 'old-token'
186
- enabled = true
187
- }
188
-
189
- tower.endpoint = 'old-endpoint'
190
-
191
- // More config
192
- params.test = true
193
- '''
194
-
195
- when :
196
- def cleaned = cmd. cleanTowerConfig(content)
197
-
198
- then :
199
- ! cleaned. contains(' tower {' )
200
- ! cleaned. contains(' accessToken = \' old-token\' ' )
201
- ! cleaned. contains(' tower.endpoint' )
202
- ! cleaned. contains(' Seqera Platform configuration' )
203
- cleaned. contains(' process {' )
204
- cleaned. contains(' params.test = true' )
205
- }
206
-
207
- def ' should handle config writing' () {
208
- given :
209
- def cmd = new CmdAuth ()
210
- def config = [
211
- ' tower.accessToken' : ' test-token' ,
212
- ' tower.enabled' : true
213
- ]
214
-
215
- when :
216
- cmd. writeConfig(config, null )
217
-
218
- then :
219
- noExceptionThrown()
220
- }
221
-
222
111
def ' login command should validate too many arguments' () {
223
112
given :
224
- def cmd = new CmdAuth ()
113
+ def cmd = Spy (CmdAuth )
114
+ def operation = Mock (CmdAuth.AuthCommand )
225
115
cmd. args = [' login' , ' extra' ]
226
116
227
117
when :
228
118
cmd. run()
229
119
230
120
then :
121
+ 1 * cmd. loadOperation() >> operation
231
122
def ex = thrown(AbortOperationException )
232
123
ex. message. contains(' Too many arguments for login command' )
233
124
}
234
125
235
126
def ' logout command should validate too many arguments' () {
236
127
given :
237
- def cmd = new CmdAuth ()
128
+ def cmd = Spy (CmdAuth )
129
+ def operation = Mock (CmdAuth.AuthCommand )
238
130
cmd. args = [' logout' , ' extra' ]
239
131
240
132
when :
241
133
cmd. run()
242
134
243
135
then :
136
+ 1 * cmd. loadOperation() >> operation
244
137
def ex = thrown(AbortOperationException )
245
138
ex. message. contains(' Too many arguments for logout command' )
246
139
}
247
140
248
141
def ' config command should validate too many arguments' () {
249
142
given :
250
- def cmd = new CmdAuth ()
143
+ def cmd = Spy (CmdAuth )
144
+ def operation = Mock (CmdAuth.AuthCommand )
251
145
cmd. args = [' config' , ' extra' ]
252
146
253
147
when :
254
148
cmd. run()
255
149
256
150
then :
151
+ 1 * cmd. loadOperation() >> operation
257
152
def ex = thrown(AbortOperationException )
258
153
ex. message. contains(' Too many arguments for config command' )
259
154
}
260
155
261
156
def ' status command should validate too many arguments' () {
262
157
given :
263
- def cmd = new CmdAuth ()
158
+ def cmd = Spy (CmdAuth )
159
+ def operation = Mock (CmdAuth.AuthCommand )
264
160
cmd. args = [' status' , ' extra' ]
265
161
266
162
when :
267
163
cmd. run()
268
164
269
165
then :
166
+ 1 * cmd. loadOperation() >> operation
270
167
def ex = thrown(AbortOperationException )
271
168
ex. message. contains(' Too many arguments for status command' )
272
169
}
273
170
274
171
def ' login command should use provided API URL' () {
275
172
given :
276
- def cmd = new CmdAuth ()
173
+ def cmd = Spy (CmdAuth )
174
+ def operation = Mock (CmdAuth.AuthCommand )
277
175
cmd. args = [' login' ]
278
176
cmd. apiUrl = ' https://api.example.com'
279
177
@@ -287,6 +185,7 @@ params.test = true
287
185
cmd. run()
288
186
289
187
then :
188
+ 1 * cmd. loadOperation() >> operation
290
189
loginCmd. apiUrl == ' https://api.example.com'
291
190
}
292
191
@@ -301,25 +200,4 @@ params.test = true
301
200
cmd. commands. find { it. name == ' config' } != null
302
201
cmd. commands. find { it. name == ' status' } != null
303
202
}
304
-
305
- def ' should create HTTP connection with correct properties' () {
306
- given :
307
- def cmd = new CmdAuth ()
308
-
309
- when :
310
- def connection = cmd. createHttpConnection(' https://example.com' , ' GET' , ' test-token' )
311
-
312
- then :
313
- connection. requestMethod == ' GET'
314
- connection. connectTimeout == CmdAuth . API_TIMEOUT_MS
315
- connection. readTimeout == CmdAuth . API_TIMEOUT_MS
316
-
317
- when :
318
- def connectionNoAuth = cmd. createHttpConnection(' https://example.com' , ' POST' )
319
-
320
- then :
321
- connectionNoAuth. requestMethod == ' POST'
322
- connectionNoAuth. connectTimeout == CmdAuth . API_TIMEOUT_MS
323
- connectionNoAuth. readTimeout == CmdAuth . API_TIMEOUT_MS
324
- }
325
203
}
0 commit comments