@@ -22,7 +22,6 @@ import spock.lang.Specification
2222import spock.lang.TempDir
2323import test.OutputCapture
2424
25- import java.nio.file.Files
2625import java.nio.file.Path
2726
2827/**
@@ -46,16 +45,6 @@ class CmdAuthTest extends Specification {
4645 cmd. getName() == ' auth'
4746 }
4847
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- }
5948
6049 def ' should show usage when no args provided' () {
6150 given :
@@ -92,13 +81,15 @@ class CmdAuthTest extends Specification {
9281
9382 def ' should throw error for unknown command' () {
9483 given :
95- def cmd = new CmdAuth ( )
84+ def cmd = Spy ( CmdAuth )
9685 cmd. args = [' unknown' ]
86+ def operation = Mock (CmdAuth.AuthCommand )
9787
9888 when :
9989 cmd. run()
10090
10191 then :
92+ 1 * cmd. loadOperation() >> operation
10293 def ex = thrown(AbortOperationException )
10394 ex. message. contains(' Unknown auth sub-command: unknown' )
10495 }
@@ -117,163 +108,70 @@ class CmdAuthTest extends Specification {
117108 ex. message. contains(' login' )
118109 }
119110
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-
222111 def ' login command should validate too many arguments' () {
223112 given :
224- def cmd = new CmdAuth ()
113+ def cmd = Spy (CmdAuth )
114+ def operation = Mock (CmdAuth.AuthCommand )
225115 cmd. args = [' login' , ' extra' ]
226116
227117 when :
228118 cmd. run()
229119
230120 then :
121+ 1 * cmd. loadOperation() >> operation
231122 def ex = thrown(AbortOperationException )
232123 ex. message. contains(' Too many arguments for login command' )
233124 }
234125
235126 def ' logout command should validate too many arguments' () {
236127 given :
237- def cmd = new CmdAuth ()
128+ def cmd = Spy (CmdAuth )
129+ def operation = Mock (CmdAuth.AuthCommand )
238130 cmd. args = [' logout' , ' extra' ]
239131
240132 when :
241133 cmd. run()
242134
243135 then :
136+ 1 * cmd. loadOperation() >> operation
244137 def ex = thrown(AbortOperationException )
245138 ex. message. contains(' Too many arguments for logout command' )
246139 }
247140
248141 def ' config command should validate too many arguments' () {
249142 given :
250- def cmd = new CmdAuth ()
143+ def cmd = Spy (CmdAuth )
144+ def operation = Mock (CmdAuth.AuthCommand )
251145 cmd. args = [' config' , ' extra' ]
252146
253147 when :
254148 cmd. run()
255149
256150 then :
151+ 1 * cmd. loadOperation() >> operation
257152 def ex = thrown(AbortOperationException )
258153 ex. message. contains(' Too many arguments for config command' )
259154 }
260155
261156 def ' status command should validate too many arguments' () {
262157 given :
263- def cmd = new CmdAuth ()
158+ def cmd = Spy (CmdAuth )
159+ def operation = Mock (CmdAuth.AuthCommand )
264160 cmd. args = [' status' , ' extra' ]
265161
266162 when :
267163 cmd. run()
268164
269165 then :
166+ 1 * cmd. loadOperation() >> operation
270167 def ex = thrown(AbortOperationException )
271168 ex. message. contains(' Too many arguments for status command' )
272169 }
273170
274171 def ' login command should use provided API URL' () {
275172 given :
276- def cmd = new CmdAuth ()
173+ def cmd = Spy (CmdAuth )
174+ def operation = Mock (CmdAuth.AuthCommand )
277175 cmd. args = [' login' ]
278176 cmd. apiUrl = ' https://api.example.com'
279177
@@ -287,6 +185,7 @@ params.test = true
287185 cmd. run()
288186
289187 then :
188+ 1 * cmd. loadOperation() >> operation
290189 loginCmd. apiUrl == ' https://api.example.com'
291190 }
292191
@@ -301,25 +200,4 @@ params.test = true
301200 cmd. commands. find { it. name == ' config' } != null
302201 cmd. commands. find { it. name == ' status' } != null
303202 }
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- }
325203}
0 commit comments