@@ -5,10 +5,7 @@ import com.sun.net.httpserver.HttpHandler
55import  com.sun.net.httpserver.HttpServer 
66import  org.zeroturnaround.exec.InvalidExitValueException 
77import  org.zeroturnaround.exec.ProcessInitException 
8- import  spock.lang.Requires 
9- import  spock.lang.Shared 
10- import  spock.lang.Specification 
11- import  spock.lang.Unroll 
8+ import  spock.lang.* 
129
1310import  java.nio.file.Files 
1411import  java.nio.file.Path 
@@ -137,7 +134,7 @@ class CoderCLIManagerTest extends Specification {
137134
138135        then :
139136        downloaded
140-         ccm. version(). contains( " Coder " 
137+         CoderSemVer . isValidVersion( ccm. version())
141138
142139        //  Make sure login failures propagate correctly.
143140        when :
@@ -161,7 +158,7 @@ class CoderCLIManagerTest extends Specification {
161158        //  The mock does not serve a binary that works on Windows so do not
162159        //  actually execute.  Checking the contents works just as well as proof
163160        //  that the binary was correctly downloaded anyway.
164-         ccm. localBinaryPath. toFile(). text  ==   " #!/bin/sh \n echo ' $ url ' " 
161+         ccm. localBinaryPath. toFile(). text. contains( url) 
165162
166163        cleanup :
167164        srv. stop(0 )
@@ -172,7 +169,7 @@ class CoderCLIManagerTest extends Specification {
172169        def  ccm =  new  CoderCLIManager (new  URL (" https://foo" . resolve(" does-not-exist" 
173170
174171        when :
175-         ccm. version( )
172+         ccm. login( " token " 
176173
177174        then :
178175        thrown(ProcessInitException )
@@ -193,7 +190,7 @@ class CoderCLIManagerTest extends Specification {
193190        downloaded
194191        ccm. localBinaryPath. toFile(). readBytes() !=  " cli" . getBytes()
195192        ccm. localBinaryPath. toFile(). lastModified() >  0 
196-         ccm. localBinaryPath. toFile(). text  ==   " #!/bin/sh \n echo ' $ url ' " 
193+         ccm. localBinaryPath. toFile(). text. contains( url) 
197194
198195        cleanup :
199196        srv. stop(0 )
@@ -207,6 +204,7 @@ class CoderCLIManagerTest extends Specification {
207204        when :
208205        def  downloaded1 =  ccm. downloadCLI()
209206        ccm. localBinaryPath. toFile(). setLastModified(0 )
207+         //  Download will be skipped due to a 304.
210208        def  downloaded2 =  ccm. downloadCLI()
211209
212210        then :
@@ -231,8 +229,8 @@ class CoderCLIManagerTest extends Specification {
231229
232230        then :
233231        ccm1. localBinaryPath !=  ccm2. localBinaryPath
234-         ccm1. localBinaryPath. toFile(). text  ==   " #!/bin/sh \n echo ' $ url1 ' " 
235-         ccm2. localBinaryPath. toFile(). text  ==   " #!/bin/sh \n echo ' $ url2 ' " 
232+         ccm1. localBinaryPath. toFile(). text. contains( url1) 
233+         ccm2. localBinaryPath. toFile(). text. contains( url2) 
236234
237235        cleanup :
238236        srv1. stop(0 )
@@ -249,7 +247,7 @@ class CoderCLIManagerTest extends Specification {
249247
250248        then :
251249        downloaded
252-         ccm. localBinaryPath. toFile(). text  ==   " #!/bin/sh \n echo ' ${ expected.replace("{{url}}", url)} ' " 
250+         ccm. localBinaryPath. toFile(). text. contains( expected. replace(" {{url}}" ) 
253251
254252        cleanup :
255253        srv. stop(0 )
@@ -429,4 +427,27 @@ class CoderCLIManagerTest extends Specification {
429427                " malformed-start-after-end" 
430428        ]
431429    }
430+ 
431+     @IgnoreIf ({ os.windows })
432+     def  " parses version" 
433+         given :
434+         def  ccm =  new  CoderCLIManager (new  URL (" https://test.coder.invalid" 
435+         Files . createDirectories(ccm. localBinaryPath. parent)
436+ 
437+         when :
438+         ccm. localBinaryPath. toFile(). text =  " #!/bin/sh\n $contents  " 
439+         ccm. localBinaryPath. toFile(). setExecutable(true )
440+ 
441+         then :
442+         ccm. version() ==  expected
443+ 
444+         where :
445+         contents                                                 | expected
446+         """ echo '{"version": "1.0.0"}'""" " 1.0.0" 
447+         """ echo '{"version": "1.0.0", "foo": true, "baz": 1}'""" " 1.0.0" 
448+         """ echo '{"foo": true, "baz": 1}'""" null 
449+         """ echo '{"version: "1.0.0", "foo": true, "baz": 1}'""" null 
450+         " exit 0" null 
451+         " exit 1" null 
452+     }
432453}
0 commit comments