Skip to content

Commit 767f2ad

Browse files
committed
Add config tests
1 parent 5d297a1 commit 767f2ad

File tree

1 file changed

+162
-0
lines changed

1 file changed

+162
-0
lines changed
Lines changed: 162 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,162 @@
1+
package nextflow.validation
2+
3+
import java.nio.file.Path
4+
5+
import nextflow.plugin.Plugins
6+
import nextflow.plugin.TestPluginDescriptorFinder
7+
import nextflow.plugin.TestPluginManager
8+
import nextflow.plugin.extension.PluginExtensionProvider
9+
import org.pf4j.PluginDescriptorFinder
10+
import nextflow.Session
11+
import spock.lang.Specification
12+
import spock.lang.Shared
13+
import org.slf4j.Logger
14+
import org.junit.Rule
15+
import test.Dsl2Spec
16+
import test.OutputCapture
17+
18+
import nextflow.validation.config.ValidationConfig
19+
20+
/**
21+
* @author : nvnieuwk <[email protected]>
22+
*/
23+
class ConfigTest extends Dsl2Spec{
24+
25+
@Rule
26+
OutputCapture capture = new OutputCapture()
27+
28+
@Shared String pluginsMode
29+
30+
Path root = Path.of('.').toAbsolutePath().normalize()
31+
Path getRoot() { this.root }
32+
String getRootString() { this.root.toString() }
33+
34+
private Session session
35+
36+
def setup() {
37+
session = Mock(Session)
38+
session.getBaseDir() >> getRoot()
39+
}
40+
41+
def 'test valid config' () {
42+
given:
43+
def config = [
44+
lenientMode: true,
45+
monochromeLogs: true,
46+
failUnrecognisedParams: true,
47+
failUnrecognisedHeaders: true,
48+
maxErrValSize: 20,
49+
parametersSchema: 'src/testResources/nextflow_schema.json',
50+
ignoreParams: ['some_random_param'],
51+
help: [
52+
enabled: true,
53+
showHidden: true,
54+
showHiddenParameter: 'stopHiding',
55+
shortParameter: 'short',
56+
fullParameter: 'full',
57+
beforeText: 'before',
58+
afterText: 'after',
59+
command: 'command'
60+
],
61+
summary: [
62+
beforeText: 'before',
63+
afterText: 'after',
64+
hideParams: ['some_random_param'],
65+
]
66+
]
67+
def params = [:]
68+
69+
when:
70+
new ValidationConfig(config, params)
71+
def stdout = capture
72+
.toString()
73+
.readLines()
74+
.findResults { it.contains('WARN') ? it : null }
75+
76+
then:
77+
noExceptionThrown()
78+
!stdout
79+
}
80+
81+
def 'test valid config - GStrings' () {
82+
given:
83+
def randomString = 'randomString'
84+
def config = [
85+
lenientMode: true,
86+
monochromeLogs: true,
87+
failUnrecognisedParams: true,
88+
failUnrecognisedHeaders: true,
89+
maxErrValSize: 20,
90+
parametersSchema: "${randomString}",
91+
ignoreParams: ["${randomString}"],
92+
help: [
93+
enabled: true,
94+
showHidden: true,
95+
showHiddenParameter: "${randomString}",
96+
shortParameter: "${randomString}",
97+
fullParameter: "${randomString}",
98+
beforeText: "${randomString}",
99+
afterText: "${randomString}",
100+
command: "${randomString}"
101+
],
102+
summary: [
103+
beforeText: "${randomString}",
104+
afterText: "${randomString}",
105+
hideParams: ["${randomString}"],
106+
]
107+
]
108+
def params = [:]
109+
110+
when:
111+
new ValidationConfig(config, params)
112+
def stdout = capture
113+
.toString()
114+
.readLines()
115+
.findResults { it.contains('WARN') ? it : null }
116+
117+
then:
118+
noExceptionThrown()
119+
!stdout
120+
}
121+
122+
def 'test invalid config' () {
123+
given:
124+
def config = [
125+
lenientMode: 'notABoolean',
126+
monochromeLogs: 12,
127+
failUnrecognisedParams: 'notABoolean',
128+
failUnrecognisedHeaders: 'notABoolean',
129+
showHiddenParams: 'notABoolean',
130+
maxErrValSize: ["notAnInteger"],
131+
parametersSchema: 42,
132+
ignoreParams: true,
133+
help: [
134+
enabled: 'notABoolean',
135+
showHidden: 'notABoolean',
136+
showHiddenParameter: 123456789,
137+
shortParameter: false,
138+
fullParameter: [im:'a_map'],
139+
beforeText: true,
140+
afterText: ['im','a','list'],
141+
command: 0
142+
],
143+
summary: [
144+
beforeText: 63,
145+
afterText: false,
146+
hideParams: 'randomString',
147+
]
148+
]
149+
def params = [:]
150+
151+
when:
152+
new ValidationConfig(config, params)
153+
def stdout = capture
154+
.toString()
155+
.readLines()
156+
.findResults { it.contains('WARN') ? it : null }
157+
158+
then:
159+
noExceptionThrown()
160+
stdout
161+
}
162+
}

0 commit comments

Comments
 (0)