@@ -5,10 +5,7 @@ import com.sun.net.httpserver.HttpHandler
5
5
import com.sun.net.httpserver.HttpServer
6
6
import org.zeroturnaround.exec.InvalidExitValueException
7
7
import 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.*
12
9
13
10
import java.nio.file.Files
14
11
import java.nio.file.Path
@@ -137,7 +134,7 @@ class CoderCLIManagerTest extends Specification {
137
134
138
135
then :
139
136
downloaded
140
- ccm. version(). contains( " Coder " )
137
+ CoderSemVer . isValidVersion( ccm. version())
141
138
142
139
// Make sure login failures propagate correctly.
143
140
when :
@@ -161,7 +158,7 @@ class CoderCLIManagerTest extends Specification {
161
158
// The mock does not serve a binary that works on Windows so do not
162
159
// actually execute. Checking the contents works just as well as proof
163
160
// that the binary was correctly downloaded anyway.
164
- ccm. localBinaryPath. toFile(). text == " #!/bin/sh \n echo ' $ url ' "
161
+ ccm. localBinaryPath. toFile(). text. contains( url)
165
162
166
163
cleanup :
167
164
srv. stop(0 )
@@ -172,7 +169,7 @@ class CoderCLIManagerTest extends Specification {
172
169
def ccm = new CoderCLIManager (new URL (" https://foo" ), tmpdir. resolve(" does-not-exist" ))
173
170
174
171
when :
175
- ccm. version( )
172
+ ccm. login( " token " )
176
173
177
174
then :
178
175
thrown(ProcessInitException )
@@ -193,7 +190,7 @@ class CoderCLIManagerTest extends Specification {
193
190
downloaded
194
191
ccm. localBinaryPath. toFile(). readBytes() != " cli" . getBytes()
195
192
ccm. localBinaryPath. toFile(). lastModified() > 0
196
- ccm. localBinaryPath. toFile(). text == " #!/bin/sh \n echo ' $ url ' "
193
+ ccm. localBinaryPath. toFile(). text. contains( url)
197
194
198
195
cleanup :
199
196
srv. stop(0 )
@@ -207,6 +204,7 @@ class CoderCLIManagerTest extends Specification {
207
204
when :
208
205
def downloaded1 = ccm. downloadCLI()
209
206
ccm. localBinaryPath. toFile(). setLastModified(0 )
207
+ // Download will be skipped due to a 304.
210
208
def downloaded2 = ccm. downloadCLI()
211
209
212
210
then :
@@ -231,8 +229,8 @@ class CoderCLIManagerTest extends Specification {
231
229
232
230
then :
233
231
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)
236
234
237
235
cleanup :
238
236
srv1. stop(0 )
@@ -249,7 +247,7 @@ class CoderCLIManagerTest extends Specification {
249
247
250
248
then :
251
249
downloaded
252
- ccm. localBinaryPath. toFile(). text == " #!/bin/sh \n echo ' ${ expected.replace("{{url}}", url)} ' "
250
+ ccm. localBinaryPath. toFile(). text. contains( expected. replace(" {{url}}" , url))
253
251
254
252
cleanup :
255
253
srv. stop(0 )
@@ -429,4 +427,27 @@ class CoderCLIManagerTest extends Specification {
429
427
" malformed-start-after-end" ,
430
428
]
431
429
}
430
+
431
+ @IgnoreIf ({ os.windows })
432
+ def " parses version" () {
433
+ given :
434
+ def ccm = new CoderCLIManager (new URL (" https://test.coder.invalid" ), tmpdir)
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
+ }
432
453
}
0 commit comments