Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,6 @@ testing*
null/
.idea/
test_data

# Ignore Nextflow test output files, which may contain sensitive information and are not relevant to the repository.
.nf-test*
23 changes: 15 additions & 8 deletions modules/local/ena_webin_cli/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ process ENA_WEBIN_CLI {
container "quay.io/biocontainers/ena-webin-cli:9.0.1--hdfd78af_1"

stageInMode 'copy'
secret 'WEBIN_ACCOUNT'
secret 'WEBIN_PASSWORD'
// Require authentication secrets for real runs, but not for mock testing.
if (!params.webincli_mock) {
secret 'WEBIN_ACCOUNT'
secret 'WEBIN_PASSWORD'
}

input:
tuple val(meta), path(submission_item), path(manifest)
Expand All @@ -29,12 +32,12 @@ process ENA_WEBIN_CLI {
export ITEM_FULL_PATH=\$(readlink -f ${submission_item})
sed 's|^FASTA\t.*|FASTA\t'"\${ITEM_FULL_PATH}"'|g' ${manifest} > ${prefix}_updated_manifest.manifest

ena-webin-cli \\
-context=genome \\
-manifest=${prefix}_updated_manifest.manifest \\
-userName="\${WEBIN_ACCOUNT}" \\
-password="\${WEBIN_PASSWORD}" \\
${submit_or_validate} \\
ena-webin-cli \
-context=genome \
-manifest=${prefix}_updated_manifest.manifest \
-userName="\${WEBIN_ACCOUNT}" \
-password="\${WEBIN_PASSWORD}" \
${submit_or_validate} \
${mode}

mv webin-cli.report "${prefix}_webin-cli.report"
Expand All @@ -53,6 +56,10 @@ process ENA_WEBIN_CLI {
# there was attempt to re-submit already submitted genome
export STATUS="success"
true
elif grep -q "Submission(s) validated successfully" "${prefix}_webin-cli.report"; then
# we ran with -validate flag
export STATUS="success"
true
else
export STATUS="failed"
false
Expand Down
119 changes: 119 additions & 0 deletions modules/local/ena_webin_cli/main.nf.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
nextflow_process {
name "Test Process ENA_WEBIN_CLI"
script "modules/local/ena_webin_cli/main.nf"
process "ENA_WEBIN_CLI"

// Set WEBINCLI_TEST_MOCK=true to run against a mocked ena-webin-cli.
def useMocking = (System.getenv('WEBINCLI_TEST_MOCK') ?: 'false').toBoolean()
def launchDir = System.getProperty('user.dir')
def mockConfigPath = "${launchDir}/modules/local/ena_webin_cli/test-mocking/nextflow.config"

test("Run validate with no failures") {

if (useMocking) {
options "-c ${mockConfigPath}"
}

when {
params {
webincli_submit = false
webincli_mock = useMocking
}
process {
"""
input[0] = Channel.of(
tuple(
[id: 'lachnospira_eligens'],
file("https://github.com/nf-core/test-datasets/raw/refs/heads/seqsubmit/test_data/bins/bin_lachnospira_eligens.fa.gz", checkIfExists: true),
file("https://github.com/nf-core/test-datasets/raw/refs/heads/seqsubmit/test_data/lachnospira_eligens.manifest", checkIfExists: true)
)
)
"""
}
}

then {
assertAll {
assert process.success
assert process.out.upload_status[0][1] == 'success'
def report_lines = path(process.out.webin_report[0][1]).readLines()
// When mocking it validates the parameters are passed correctly, but doesn't actually run the submission,
// so we check for the presence of the parameters in the report.
if (useMocking) {
assert report_lines.any { it.contains("MOCK WEBIN RUN") }
assert report_lines.any { it.contains("-context=genome") }
assert report_lines.any { it.contains("-manifest=lachnospira_eligens_updated_manifest.manifest") }
assert report_lines.any { it.contains("-validate") }
}
assert report_lines.any { it.contains("Submission(s) validated successfully") }
assert snapshot(process.out.versions).match()
}
}

}

test("Run push with no failures") {
if (useMocking) {
options "-c ${mockConfigPath}"
}

setup {
run("GENERATE_TEST_DATA") {
script "./setup_test.nf"
process {
"""
input[0] = Channel.of(
file("https://github.com/nf-core/test-datasets/raw/refs/heads/seqsubmit/test_data/lachnospira_eligens.manifest", checkIfExists: true)
)
"""
}
}

}

when {
params {
webincli_submit = true
test_upload = true
webincli_mock = useMocking
}
process {
"""
def fasta = file("https://github.com/nf-core/test-datasets/raw/refs/heads/seqsubmit/test_data/bins/bin_lachnospira_eligens.fa.gz", checkIfExists: true)

input[0] = GENERATE_TEST_DATA.out.test_manifest.map { manifest ->
tuple(
[id: 'lachnospira_eligens'],
fasta,
file(manifest)
)
}
"""
}
}

then {
assertAll {
assert process.success
assert process.out.upload_status[0][1] == 'success'
def report_lines = path(process.out.webin_report[0][1]).readLines()
// When mocking it validates the parameters are passed correctly, but doesn't actually run the submission,
// so we check for the presence of the parameters in the report.
if (useMocking) {
assert report_lines.any { it.contains("MOCK WEBIN RUN") }
assert report_lines.any { it.contains("-context=genome") }
assert report_lines.any { it.contains("-manifest=lachnospira_eligens_updated_manifest.manifest") }
assert report_lines.any { it.contains("-submit") }
assert report_lines.any { it.contains("-test") }
}
assert report_lines.any { it.contains("Submission(s) validated successfully") }
assert report_lines.any { it.contains("The submission has been completed successfully") }
assert report_lines.any { it.contains("This was a TEST submission(s)") }
assert snapshot(process.out.versions).match()

}
}

}

}
26 changes: 26 additions & 0 deletions modules/local/ena_webin_cli/main.nf.test.snap
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
{
"Run validate with no failures": {
"content": [
[
"versions.yml:md5,a38fb03bead632d71062a101d7889ded"
]
],
"meta": {
"nf-test": "0.9.3",
"nextflow": "25.04.8"
},
"timestamp": "2025-10-29T14:09:00.202532371"
},
"Run push with no failures": {
"content": [
[
"versions.yml:md5,a38fb03bead632d71062a101d7889ded"
]
],
"meta": {
"nf-test": "0.9.3",
"nextflow": "25.04.8"
},
"timestamp": "2025-10-29T14:01:42.491885321"
}
}
17 changes: 17 additions & 0 deletions modules/local/ena_webin_cli/setup_test.nf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
process GENERATE_TEST_DATA {
label 'process_low'
container "quay.io/biocontainers/ena-webin-cli:9.0.1--hdfd78af_1"

input:
path(manifest_template)

output:
path("*.manifest"), emit: test_manifest

script:
"""
timestamp="\$(date +%s)"

sed -E "s/^(ASSEMBLYNAME\t[^\t]+)/\\1_\${timestamp}/" "${manifest_template}" > "lachnospira_eligens_dynamic_fixture.manifest"
"""
}
60 changes: 60 additions & 0 deletions modules/local/ena_webin_cli/test-mocking/ena-webin-cli
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#!/usr/bin/env bash
# Mock ena-webin-cli script for testing without credentials.
set -euo pipefail

# Verify that a real ena-webin-cli exists somewhere in PATH beyond this mock.
real_bin="$(which -a ena-webin-cli 2>/dev/null | grep -v "$(realpath "$0")" | head -1 || true)"
if [[ -z "$real_bin" ]]; then
echo "FATAL: No real ena-webin-cli found in PATH besides this mock." >&2
exit 666
fi

# Outputs the version of the real ena-webin-cli when called with -version, to allow testing of version parsing logic.
if [[ "${1:-}" == "-version" ]]; then
echo $(${real_bin} -version 2>&1)
exit 0
fi

manifest=""
action=""
mode=""

for arg in "$@"; do
case "$arg" in
-manifest=*)
manifest="${arg#-manifest=}"
;;
-submit|-validate)
action="$arg"
;;
-test)
mode="$arg"
;;
esac
done

if [[ -z "$manifest" || -z "$action" ]]; then
echo "Mock ena-webin-cli: missing required arguments" >&2
exit 1
fi

prefix="$(basename "$manifest")"
prefix="${prefix%_updated_manifest.manifest}"

template_dir="${WEBINCLI_MOCK_TEMPLATE_DIR:-.}"
if [[ "$action" == "-submit" ]]; then
template="$template_dir/mock_submit.report"
else
template="$template_dir/mock_validate.report"
fi

if [[ ! -f "$template" ]]; then
echo "Mock template file not found: $template" >&2
exit 1
fi

sed \
-e "s|<PREFIX>|$prefix|g" \
-e "s|<ACTION>|$action|g" \
-e "s|<MODE>|$mode|g" \
"$template" > webin-cli.report
5 changes: 5 additions & 0 deletions modules/local/ena_webin_cli/test-mocking/mock_submit.report
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
INFO : MOCK WEBIN RUN
INFO : command=ena-webin-cli -context=genome -manifest=<PREFIX>_updated_manifest.manifest <ACTION> <MODE>
INFO : Submission(s) validated successfully
INFO : The submission has been completed successfully
INFO : This was a TEST submission(s)
3 changes: 3 additions & 0 deletions modules/local/ena_webin_cli/test-mocking/mock_validate.report
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
INFO : MOCK WEBIN RUN
INFO : command=ena-webin-cli -context=genome -manifest=<PREFIX>_updated_manifest.manifest <ACTION> <MODE>
INFO : Submission(s) validated successfully
12 changes: 12 additions & 0 deletions modules/local/ena_webin_cli/test-mocking/nextflow.config
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
params.testMockingDir = "${projectDir}/modules/local/ena_webin_cli/test-mocking"
env {
WEBIN_ACCOUNT = "mock_account"
WEBIN_PASSWORD = "mock_password"
PATH = "${params.testMockingDir}:\$PATH"
WEBINCLI_MOCK_TEMPLATE_DIR = "${params.testMockingDir}"
}
process {
withName: 'ENA_WEBIN_CLI' {
containerOptions = "-v ${params.testMockingDir}:${params.testMockingDir}"
}
}
Loading