17
17
18
18
package nextflow.cli
19
19
20
+ import nextflow.data.cid.serde.CidEncoder
21
+
20
22
import java.nio.file.Files
21
23
22
24
import nextflow.SysEnv
@@ -28,11 +30,13 @@ import nextflow.data.cid.model.Parameter
28
30
import nextflow.data.cid.model.TaskOutput
29
31
import nextflow.data.cid.model.TaskRun
30
32
import nextflow.data.cid.model.WorkflowOutput
31
- import nextflow.data.cid.serde.CidEncoder
32
33
import nextflow.plugin.Plugins
33
34
import org.junit.Rule
34
35
import spock.lang.Specification
35
36
import test.OutputCapture
37
+
38
+ import java.time.Instant
39
+
36
40
/**
37
41
* CLI cid Tests
38
42
*
@@ -132,9 +136,10 @@ class CmdCidTest extends Specification {
132
136
def launcher = Mock (Launcher ){
133
137
getOptions() >> new CliOptions (config : [configFile. toString()])
134
138
}
139
+ def time = Instant . ofEpochMilli(123456789 ). toString()
135
140
def encoder = new CidEncoder (). withPrettyPrint(true )
136
141
def entry = new WorkflowOutput (" path/to/file" ,new Checksum (" 45372qe" ," nextflow" ," standard" ),
137
- " cid://123987/file.bam" , 1234 , 123456789 , 123456789 , null )
142
+ " cid://123987/file.bam" , 1234 , time, time , null )
138
143
def jsonSer = encoder. encode(entry)
139
144
def expectedOutput = jsonSer
140
145
cidFile. text = jsonSer
@@ -177,7 +182,7 @@ class CmdCidTest extends Specification {
177
182
178
183
then :
179
184
stdout. size() == 1
180
- stdout[0 ] == " No entry found for cid://12345."
185
+ stdout[0 ] == " No entries found for cid://12345."
181
186
182
187
cleanup :
183
188
folder?. deleteDir()
@@ -203,19 +208,20 @@ class CmdCidTest extends Specification {
203
208
Files . createDirectories(cidFile4. parent)
204
209
Files . createDirectories(cidFile5. parent)
205
210
def encoder = new CidEncoder ()
211
+ def time = Instant . ofEpochMilli(123456789 ). toString()
206
212
def entry = new WorkflowOutput (" path/to/file" ,new Checksum (" 45372qe" ," nextflow" ," standard" ),
207
- " cid://123987/file.bam" , 1234 , 123456789 , 123456789 , null )
213
+ " cid://123987/file.bam" , 1234 , time, time , null )
208
214
cidFile. text = encoder. encode(entry)
209
215
entry = new TaskOutput (" path/to/file" ,new Checksum (" 45372qe" ," nextflow" ," standard" ),
210
- " cid://123987" , 1234 , 123456789 , 123456789 , null )
216
+ " cid://123987" , 1234 , time, time , null )
211
217
cidFile2. text = encoder. encode(entry)
212
218
entry = new TaskRun (" u345-2346-1stw2" , " foo" , new Checksum (" abcde2345" ," nextflow" ," standard" ),
213
219
[new Parameter ( " ValueInParam" , " sample_id" ," ggal_gut" ),
214
220
new Parameter (" FileInParam" ," reads" ,[" cid://45678/output.txt" ])],
215
221
null , null , null , null , [:],[], null )
216
222
cidFile3. text = encoder. encode(entry)
217
223
entry = new TaskOutput (" path/to/file" ,new Checksum (" 45372qe" ," nextflow" ," standard" ),
218
- " cid://45678" , 1234 , 123456789 , 123456789 , null )
224
+ " cid://45678" , 1234 , time, time , null )
219
225
cidFile4. text = encoder. encode(entry)
220
226
entry = new TaskRun (" u345-2346-1stw2" , " bar" , new Checksum (" abfs2556" ," nextflow" ," standard" ),
221
227
null ,null , null , null , null , [:],[], null )
@@ -258,4 +264,39 @@ class CmdCidTest extends Specification {
258
264
259
265
}
260
266
267
+ def ' should show query results' (){
268
+ given :
269
+ def folder = Files . createTempDirectory(' test' ). toAbsolutePath()
270
+ def configFile = folder. resolve(' nextflow.config' )
271
+ configFile. text = " workflow.data.enabled = true\n workflow.data.store.location = '$folder '" . toString()
272
+ def cidFile = folder. resolve(" .meta/12345/.data.json" )
273
+ Files . createDirectories(cidFile. parent)
274
+ def launcher = Mock (Launcher ){
275
+ getOptions() >> new CliOptions (config : [configFile. toString()])
276
+ }
277
+ def encoder = new CidEncoder (). withPrettyPrint(true )
278
+ def time = Instant . ofEpochMilli(123456789 ). toString()
279
+ def entry = new WorkflowOutput (" path/to/file" ,new Checksum (" 45372qe" ," nextflow" ," standard" ),
280
+ " cid://123987/file.bam" , 1234 , time, time, null )
281
+ def jsonSer = encoder. encode(entry)
282
+ def expectedOutput = jsonSer
283
+ cidFile. text = jsonSer
284
+ when :
285
+ def cidCmd = new CmdCid (launcher : launcher, args : [" show" , " cid:///?type=WorkflowOutput" ])
286
+ cidCmd. run()
287
+ def stdout = capture
288
+ .toString()
289
+ .readLines()// remove the log part
290
+ .findResults { line -> ! line. contains(' DEBUG' ) ? line : null }
291
+ .findResults { line -> ! line. contains(' INFO' ) ? line : null }
292
+ .findResults { line -> ! line. contains(' plugin' ) ? line : null }
293
+
294
+ then :
295
+ stdout. size() == expectedOutput. readLines(). size()
296
+ stdout. join(' \n ' ) == expectedOutput
297
+
298
+ cleanup :
299
+ folder?. deleteDir()
300
+ }
301
+
261
302
}
0 commit comments