Skip to content

Commit 5fb2d48

Browse files
author
Alan Christie
committed
- SD file only required if a test uses params
(i.e. SD file not required if all you're doing is defining commands) - Fixed leaky creates - the creates array wasn't being cleared between test files
1 parent 2ed7bfd commit 5fb2d48

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/groovy/PipelineTester.groovy

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,7 @@ class Tester {
114114
sectionNumber = 0
115115
testScriptVersion = 0
116116
testTimeoutSeconds = 30
117+
collectionCreates = []
117118

118119
// We must not have duplicate test files -
119120
// this indicates there are pipelines in different projects
@@ -127,10 +128,17 @@ class Tester {
127128
observedFiles.add(currentTestFilename)
128129

129130
// Guess the Service Descriptor path and filename
130-
// and try to extract the command and the supported options...
131+
// and try to extract the command and the supported options.
132+
// The SD file must exist if the user has defined a set of
133+
// parameters. The SD file is not required if the test
134+
// contains just raw commands.
131135
String sdFilename = path.take(path.length() - testExt.length()) + sdExt
132-
currentServiceDescriptor = new JsonSlurper().parse(new File(sdFilename).toURI().toURL())
133-
extractOptionsFromCurrentServiceDescriptor()
136+
currentServiceDescriptor = null
137+
File sdFilenameFile = new File(sdFilename)
138+
if (sdFilenameFile.exists()) {
139+
currentServiceDescriptor = new JsonSlurper().parse(sdFilenameFile.toURI().toURL())
140+
extractOptionsFromCurrentServiceDescriptor()
141+
}
134142

135143
// Now run each test found in the test spec
136144
// (also checking for `setup_collection` and `version` sections).
@@ -477,7 +485,6 @@ class Tester {
477485
}
478486

479487
// Globally-defined created files?
480-
collectionCreates = []
481488
if (setupSection.value.creates != null) {
482489
collectionCreates = setupSection.value.get('creates')
483490
}
@@ -565,10 +572,15 @@ class Tester {
565572
String pipelineCommand
566573
if (command == null) {
567574

568-
if (!checkAllOptionsHaveBeenUsed(paramsBlock)) {
575+
if (currentServiceDescriptor == null) {
576+
err('Found "params" but there was no service descriptor file.')
577+
recordFailedTest(section.key)
578+
return
579+
} else if (!checkAllOptionsHaveBeenUsed(paramsBlock)) {
569580
recordFailedTest(section.key)
570581
return
571582
}
583+
572584
// No raw command defined in the test block,
573585
// so use the command defined in the service descriptor...
574586
String the_command = currentServiceDescriptor.command

0 commit comments

Comments
 (0)