16
16
17
17
package nextflow.lineage.cli
18
18
19
+ import java.nio.file.Files
20
+ import java.nio.file.Path
21
+ import java.time.Instant
22
+ import java.time.OffsetDateTime
23
+ import java.time.ZoneOffset
24
+
19
25
import nextflow.SysEnv
20
26
import nextflow.config.ConfigMap
21
27
import nextflow.dag.MermaidHtmlRenderer
28
+ import nextflow.exception.AbortOperationException
29
+ import nextflow.file.FileHelper
30
+ import nextflow.lineage.DefaultLinHistoryLog
22
31
import nextflow.lineage.LinHistoryRecord
23
32
import nextflow.lineage.LinStoreFactory
24
- import nextflow.lineage.DefaultLinHistoryLog
33
+ import nextflow.lineage.fs.LinFileSystemProvider
25
34
import nextflow.lineage.model.v1beta1.Checksum
26
- import nextflow.lineage.model.v1beta1.FileOutput
27
35
import nextflow.lineage.model.v1beta1.DataPath
36
+ import nextflow.lineage.model.v1beta1.FileOutput
28
37
import nextflow.lineage.model.v1beta1.Parameter
29
38
import nextflow.lineage.model.v1beta1.TaskRun
30
39
import nextflow.lineage.model.v1beta1.Workflow
31
40
import nextflow.lineage.model.v1beta1.WorkflowRun
32
41
import nextflow.lineage.serde.LinEncoder
33
42
import nextflow.plugin.Plugins
43
+ import nextflow.util.CacheHelper
34
44
import org.junit.Rule
45
+ import spock.lang.Shared
35
46
import spock.lang.Specification
36
- import spock.lang.TempDir
37
47
import test.OutputCapture
38
- import java.nio.file.Files
39
- import java.nio.file.Path
40
- import java.time.Instant
41
- import java.time.OffsetDateTime
42
- import java.time.ZoneOffset
43
48
44
49
class LinCommandImplTest extends Specification {
45
50
46
- @TempDir
51
+ @Shared
47
52
Path tmpDir
48
53
54
+ @Shared
49
55
Path storeLocation
56
+
57
+ @Shared
50
58
ConfigMap configMap
51
59
60
+ def reset () {
61
+ def provider = FileHelper . getProviderFor(' lid' ) as LinFileSystemProvider
62
+ provider?. reset()
63
+ LinStoreFactory . reset()
64
+ }
65
+
52
66
def setup () {
67
+ reset()
53
68
// clear the environment to avoid the local env pollute the test env
54
69
SysEnv . push([:])
70
+ tmpDir = Files . createTempDirectory(' tmp' )
55
71
storeLocation = tmpDir. resolve(" store" )
56
72
configMap = new ConfigMap ([lineage : [enabled : true , store : [location : storeLocation. toString(), logLocation : storeLocation. resolve(" .log" ). toString()]]])
57
73
}
@@ -60,11 +76,13 @@ class LinCommandImplTest extends Specification{
60
76
Plugins . stop()
61
77
LinStoreFactory . reset()
62
78
SysEnv . pop()
79
+ tmpDir?. deleteDir()
63
80
}
64
81
65
82
def setupSpec () {
66
- LinStoreFactory . reset()
83
+ reset()
67
84
}
85
+
68
86
/*
69
87
* Read more http://mrhaki.blogspot.com.es/2015/02/spocklight-capture-and-assert-system.html
70
88
*/
@@ -488,6 +506,42 @@ class LinCommandImplTest extends Specification{
488
506
stdout. join(' \n ' ) == expectedOutput1 || stdout. join(' \n ' ) == expectedOutput2
489
507
}
490
508
509
+ def ' should print correct validate path' () {
510
+ given :
511
+ def outputFolder = tmpDir. resolve(' output' )
512
+ Files . createDirectories(outputFolder)
513
+ def outputFile = outputFolder. resolve(' file1.txt' )
514
+ outputFile. text = " this is file1 == "
515
+
516
+ and :
517
+ def encoder = new LinEncoder (). withPrettyPrint(true )
518
+ def hash = CacheHelper . hasher(outputFile). hash(). toString()
519
+ def correctData = new FileOutput (outputFile. toString(), new Checksum (hash," nextflow" , " standard" ))
520
+ def incorrectData = new FileOutput (outputFile. toString(), new Checksum (" incorrectHash" ," nextflow" , " standard" ))
521
+ def lid1 = storeLocation. resolve(' 12345/output/file1.txt/.data.json' )
522
+ Files . createDirectories(lid1. parent)
523
+ lid1. text = encoder. encode(correctData)
524
+ def lid2 = storeLocation. resolve(' 12345/output/file2.txt/.data.json' )
525
+ Files . createDirectories(lid2. parent)
526
+ lid2. text = encoder. encode(incorrectData)
527
+ when :
528
+ new LinCommandImpl (). check(configMap, [" lid://12345/output/file1.txt" ])
529
+ def stdout = capture
530
+ .toString()
531
+ .readLines()// remove the log part
532
+ .findResults { line -> ! line. contains(' DEBUG' ) ? line : null }
533
+ .findResults { line -> ! line. contains(' INFO' ) ? line : null }
534
+ .findResults { line -> ! line. contains(' plugin' ) ? line : null }
535
+ def expectedOutput1 = " Checksum validation succeed"
536
+ then :
537
+ stdout. size() == 1
538
+ stdout[0 ] == expectedOutput1
491
539
540
+ when :
541
+ new LinCommandImpl (). check(configMap, [" lid://12345/output/file2.txt" ])
542
+ then :
543
+ def err = thrown(AbortOperationException )
544
+ err. message == " Checksum of '${ outputFile} ' does not match with lineage metadata"
545
+ }
492
546
493
547
}
0 commit comments