Skip to content

Commit 1809a04

Browse files
committed
Test minor refactoring
1 parent 607103c commit 1809a04

File tree

4 files changed

+19
-25
lines changed

4 files changed

+19
-25
lines changed

modules/nf-google/src/main/nextflow/cloud/google/util/GsPathFactory.groovy

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ import com.google.cloud.storage.contrib.nio.CloudStorageConfiguration
2222
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem
2323
import groovy.transform.CompileStatic
2424
import nextflow.Global
25+
import nextflow.Session
2526
import nextflow.cloud.google.lifesciences.GoogleLifeSciencesConfig
2627
import nextflow.file.FileSystemPathFactory
2728

@@ -39,7 +40,7 @@ class GsPathFactory extends FileSystemPathFactory {
3940
} ()
4041

4142
static private CloudStorageConfiguration getCloudStorageConfig() {
42-
def session = Global.getSession() as nextflow.Session
43+
final session = (Session) Global.getSession()
4344
if (!session)
4445
new IllegalStateException("Cannot initialize GsPathFactory: missing session")
4546

modules/nf-google/src/test/nextflow/cloud/google/util/GsPathPathFactoryTest.groovy renamed to modules/nf-google/src/test/nextflow/cloud/google/util/GsPathFactoryTest.groovy

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -16,27 +16,21 @@
1616

1717
package nextflow.cloud.google.util
1818

19-
20-
import spock.lang.Specification
21-
22-
import com.google.cloud.storage.contrib.nio.CloudStorageConfiguration
23-
import com.google.cloud.storage.contrib.nio.CloudStorageFileSystem
2419
import nextflow.Global
2520
import nextflow.Session
26-
import nextflow.cloud.google.lifesciences.GoogleLifeSciencesConfig
27-
import nextflow.config.ConfigBuilder
28-
21+
import spock.lang.Specification
2922
/**
3023
*
3124
* @author Paolo Di Tommaso <[email protected]>
3225
*/
33-
class GsPathPathFactoryTest extends Specification {
26+
class GsPathFactoryTest extends Specification {
3427

3528
def 'should create gs path' () {
3629
given:
37-
def sess = new Session()
38-
sess.config = [google:[project:'foo', region:'x']]
39-
Global.session = sess
30+
Global.session = Mock(Session) {
31+
getConfig() >> [google:[project:'foo', region:'x']]
32+
}
33+
and:
4034
def factory = new GsPathFactory()
4135

4236
expect:
@@ -53,9 +47,9 @@ class GsPathPathFactoryTest extends Specification {
5347

5448
def 'should use requester pays' () {
5549
given:
56-
def sess = new Session()
57-
sess.config = [google:[project:'foo', region:'x', enableRequesterPaysBuckets:true]]
58-
Global.session = sess
50+
Global.session = Mock(Session) {
51+
getConfig() >> [google:[project:'foo', region:'x', enableRequesterPaysBuckets:true]]
52+
}
5953

6054
when:
6155
def storageConfig = GsPathFactory.getCloudStorageConfig()

modules/nf-google/src/test/nextflow/extension/FilesExTest2.groovy

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ class FilesExTest2 extends Specification {
3333

3434
@Unroll
3535
def 'should return uri string for #PATH' () {
36+
given:
37+
Global.session = Mock(Session) {
38+
getConfig() >> [google:[project:'foo', region:'x']]
39+
}
3640

3741
when:
38-
def sess = new Session()
39-
sess.config = [google:[project:'foo', region:'x']]
40-
Global.session = sess
4142
def path = PATH as Path
4243
then:
4344
path instanceof CloudStoragePath

modules/nf-google/src/test/nextflow/file/FileHelperGsTest.groovy

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,9 +34,9 @@ class FileHelperGsTest extends Specification {
3434
def 'should parse google storage path' () {
3535

3636
given:
37-
def sess = new Session()
38-
sess.config = [google:[project:'foo', region:'x']]
39-
Global.session = sess
37+
Global.session = Mock(Session) {
38+
getConfig() >> [google:[project:'foo', region:'x']]
39+
}
4040

4141
expect:
4242
FileHelper.asPath('file.txt') ==
@@ -65,9 +65,7 @@ class FileHelperGsTest extends Specification {
6565

6666
def 'should strip ending slash' () {
6767
given:
68-
def sess = new Session()
69-
sess.config = [google:[project:'foo', region:'x']]
70-
Global.session = sess
68+
Global.session = Mock(Session) { getConfig() >> [google:[project:'foo', region:'x']] }
7169
def nxFolder = Paths.get('/my-bucket/foo')
7270
def nxNested = Paths.get('/my-bucket/foo/bar/')
7371
and:

0 commit comments

Comments
 (0)