From d9b48a20a06e816a7d13293b3a95acc3e4341d33 Mon Sep 17 00:00:00 2001 From: "Dr. Ernie Prabhakar" <19791+drernie@users.noreply.github.com> Date: Wed, 11 Sep 2024 16:59:52 -0700 Subject: [PATCH] improve coverage --- .../src/main/nextflow/quilt/QuiltObserver.groovy | 6 ++++-- .../test/nextflow/quilt/QuiltObserverTest.groovy | 13 ++++++++----- .../quilt/nio/QuiltFileSystemProviderTest.groovy | 12 ++++++++++++ 3 files changed, 24 insertions(+), 7 deletions(-) diff --git a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy index 3828e5f4..d7d85880 100644 --- a/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy +++ b/plugins/nf-quilt/src/main/nextflow/quilt/QuiltObserver.groovy @@ -135,9 +135,11 @@ class QuiltObserver implements TraceObserver { String destString = QuiltPackage.osConvert(dest.toAbsolutePath().normalize().toString()) // find pkgKey in destination.toString() int index = destString.indexOf(pkgKey) + println("pkgRelative[$index]: $pkgKey in $destString") // return the portion after the end of pkgKey - if (index >= 0) { - return destString.substring(index + pkgKey.length() + 1) + int len = index + pkgKey.length() + 1 + if (index >= 0 && len < destString.length()) { + return destString.substring(len) } return null } diff --git a/plugins/nf-quilt/src/test/nextflow/quilt/QuiltObserverTest.groovy b/plugins/nf-quilt/src/test/nextflow/quilt/QuiltObserverTest.groovy index 4b46d3be..c672261f 100644 --- a/plugins/nf-quilt/src/test/nextflow/quilt/QuiltObserverTest.groovy +++ b/plugins/nf-quilt/src/test/nextflow/quilt/QuiltObserverTest.groovy @@ -161,13 +161,16 @@ class QuiltObserverTest extends QuiltSpecification { void 'should addOverlay logical path with subfolders'() { given: QuiltObserver observer = makeObserver() - String file_path = 'file.txt' - String full_path = "output/${file_path}" - Path source = Paths.get(TEST_KEY, file_path) - Path dest = Paths.get(TEST_KEY, full_path) + String file_path = 'source' + Path source = Paths.get(root, file_path) + Path dest = Paths.get(root, path) expect: String relPath = observer.addOverlay(TEST_KEY, dest, source) - relPath == full_path + relPath == result + where: + root | path | result + TEST_KEY | SPEC_KEY | SPEC_KEY + SPEC_KEY | TEST_KEY | null } void 'should not error on onFlowComplete success'() { diff --git a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy index a8019693..a4a71f6c 100644 --- a/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy +++ b/plugins/nf-quilt/src/test/nextflow/quilt/nio/QuiltFileSystemProviderTest.groovy @@ -95,6 +95,18 @@ class QuiltFileSystemProviderTest extends QuiltSpecification { Files.list(tempFolder).count() > 0 } + void 'should fail to download a file if already exists'() { + given: + QuiltFileSystemProvider provider = new QuiltFileSystemProvider() + Path remoteFolder = parsedURIWithPath(false) + Path tempFolder = Files.createTempDirectory('quilt') + when: + provider.download(remoteFolder, tempFolder, null) + + then: + thrown java.nio.file.FileAlreadyExistsException + } + @IgnoreIf({ env.WRITE_BUCKET == null }) void 'should upload file to test bucket'() { given: