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