-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
131 additions
and
0 deletions.
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
plugins/nf-iridanext/src/test/nextflow/iridanext/SamplesheetParserTest.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,131 @@ | ||
package nextflow.iridanext | ||
|
||
import java.nio.file.Paths | ||
import java.nio.file.FileSystems | ||
import nextflow.iridanext.SamplesheetParser | ||
|
||
import nextflow.Session | ||
import spock.lang.Specification | ||
import net.jimblackler.jsonschemafriend.Schema | ||
import net.jimblackler.jsonschemafriend.SchemaStore | ||
import groovy.util.logging.Slf4j | ||
import groovyx.gpars.dataflow.DataflowReadChannel | ||
|
||
import nextflow.iridanext.TestHelper | ||
|
||
import java.nio.file.Files | ||
import java.util.jar.Manifest | ||
|
||
import nextflow.Channel | ||
import nextflow.plugin.Plugins | ||
import nextflow.plugin.TestPluginDescriptorFinder | ||
import nextflow.plugin.TestPluginManager | ||
import nextflow.plugin.extension.PluginExtensionProvider | ||
import org.pf4j.PluginDescriptorFinder | ||
import spock.lang.Shared | ||
import spock.lang.Timeout | ||
import test.Dsl2Spec | ||
|
||
import java.nio.file.Path | ||
|
||
|
||
@Slf4j | ||
class SamplesheetParserTest extends Dsl2Spec { | ||
|
||
@Shared String pluginsMode | ||
|
||
// NOTE: This setup() may fail if updated to Nextflow v24.01. | ||
// Please refer to these changes for a possible fix: | ||
// https://github.com/nextflow-io/nf-hello/commit/f686fbcf2346f3fc02b2288f567c016ab6bf2e50#diff-ae2fcafb7e787d2831f4cc882f85884ac2a100c5183b014baee656e96ddd69a6 | ||
def setup() { | ||
// reset previous instances | ||
PluginExtensionProvider.reset() | ||
// this need to be set *before* the plugin manager class is created | ||
pluginsMode = System.getProperty('pf4j.mode') | ||
System.setProperty('pf4j.mode', 'dev') | ||
// the plugin root should | ||
def root = Path.of('.').toAbsolutePath().normalize() | ||
def manager = new TestPluginManager(root){ | ||
@Override | ||
protected PluginDescriptorFinder createPluginDescriptorFinder() { | ||
return new TestPluginDescriptorFinder(){ | ||
@Override | ||
protected Path getManifestPath(Path pluginPath) { | ||
return pluginPath.resolve('build/resources/main/META-INF/MANIFEST.MF') | ||
} | ||
} | ||
} | ||
} | ||
Plugins.init(root, 'dev', manager) | ||
} | ||
|
||
def cleanup() { | ||
Plugins.stop() | ||
PluginExtensionProvider.reset() | ||
pluginsMode ? System.setProperty('pf4j.mode',pluginsMode) : System.clearProperty('pf4j.mode') | ||
} | ||
|
||
def 'Test loadIridaSampleIds only metadata' () { | ||
when: | ||
def config = [ | ||
iridanext: [ | ||
enabled: true, | ||
output: [ | ||
path: "/tmp/output/output.json.gz" | ||
] | ||
] | ||
] | ||
def session = Spy(Session) { | ||
getConfig() >> config | ||
} | ||
def SCRIPT = ''' | ||
include { loadIridaSampleIds } from 'plugin/nf-iridanext' | ||
channel | ||
.of([["id":"sample1"]], [["id":"sample2"]], [["id":"sample3"]]) | ||
.loadIridaSampleIds() | ||
''' | ||
|
||
final IridaNextJSONOutput iridaNextJSONOutput = IridaNextJSONOutput.getInstance() | ||
|
||
and: | ||
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() | ||
|
||
then: | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample1") | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample2") | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample3") | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample4") == false | ||
} | ||
|
||
def 'Test loadIridaSampleIds metadata and data' () { | ||
when: | ||
def config = [ | ||
iridanext: [ | ||
enabled: true, | ||
output: [ | ||
path: "/tmp/output/output.json.gz" | ||
] | ||
] | ||
] | ||
def session = Spy(Session) { | ||
getConfig() >> config | ||
} | ||
def SCRIPT = ''' | ||
include { loadIridaSampleIds } from 'plugin/nf-iridanext' | ||
channel | ||
.of([["id":"sample1"], "data1"], [["id":"sample2"], "data2"], [["id":"sample3"], "data3"]) | ||
.loadIridaSampleIds() | ||
''' | ||
|
||
final IridaNextJSONOutput iridaNextJSONOutput = IridaNextJSONOutput.getInstance() | ||
|
||
and: | ||
def result = new MockScriptRunner([:]).setScript(SCRIPT).execute() | ||
|
||
then: | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample1") | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample2") | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample3") | ||
iridaNextJSONOutput.isValidId(iridaNextJSONOutput.SAMPLES, "sample4") == false | ||
} | ||
} |