Skip to content

Commit c51be76

Browse files
author
Alan Christie
committed
- Supports 'creates' in the setup_collection section
- Refined template
1 parent d47ad5d commit c51be76

File tree

2 files changed

+45
-22
lines changed

2 files changed

+45
-22
lines changed

src/groovy/PipelineTester.groovy

Lines changed: 29 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,8 @@ class Tester {
4949
// Controlled by command-line
5050
boolean verbose = false
5151

52-
// Controlled by setup sections
53-
int testTimeoutSeconds = 30
54-
5552
// Constants?
53+
int defaultTimeoutSeconds = 30
5654
String testExt = '.test'
5755
String executeAnchorDir = '/src/'
5856
String testFileSpec = "**/*${testExt}"
@@ -68,6 +66,9 @@ class Tester {
6866
String testPrefix = 'test_'
6967
String ignorePrefix = 'ignore_'
7068

69+
// Controlled by setup sections
70+
int testTimeoutSeconds = defaultTimeoutSeconds
71+
7172
// Material accumulated as the tests execute
7273
int testScriptVersion = 0
7374
int sectionNumber = 0
@@ -84,6 +85,9 @@ class Tester {
8485
// i.e. 'arg.volumes' becomes 'volumes' (also contains expanded ranges)
8586
List<String> optionNames = []
8687
def optionDefaults = [:]
88+
// Files created by the entire test collection.
89+
// Defined in the 'setup_collection.creates' block.
90+
def collectionCreates = []
8791

8892
/**
8993
* The run method.
@@ -108,6 +112,7 @@ class Tester {
108112
take(currentTestFilename.length() - testExt.length())
109113
sectionNumber = 0
110114
testScriptVersion = 0
115+
testTimeoutSeconds = 30
111116

112117
// We must not have duplicate test files -
113118
// this indicates there are pipelines in different projects
@@ -127,7 +132,7 @@ class Tester {
127132
extractOptionsFromCurrentServiceDescriptor()
128133

129134
// Now run each test found in the test spec
130-
// (also checking for a `setup_collection` and `version` sections).
135+
// (also checking for `setup_collection` and `version` sections).
131136
def test_spec = new ConfigSlurper().parse(new File(path).toURI().toURL())
132137
for (def section : test_spec) {
133138

@@ -462,10 +467,18 @@ class Tester {
462467
info('Processing setup_collection section')
463468

464469
// Extract key setup values, supplying defaults
465-
int timeoutSeconds = setupSection.value.get('timeout')
466-
if (timeoutSeconds != null) {
467-
info("Setup timeout=$timeoutSeconds")
468-
testTimeoutSeconds = timeoutSeconds
470+
if (setupSection.value.timeout != null) {
471+
int timeoutSeconds = setupSection.value.get('timeout')
472+
if (timeoutSeconds != null) {
473+
info("Setup timeout=$timeoutSeconds")
474+
testTimeoutSeconds = timeoutSeconds
475+
}
476+
}
477+
478+
// Globally-defined created files?
479+
collectionCreates = []
480+
if (setupSection.value.creates != null) {
481+
collectionCreates = setupSection.value.get('creates')
469482
}
470483

471484
}
@@ -519,6 +532,8 @@ class Tester {
519532
*
520533
* - creates
521534
* An optional list of file names (regular expressions).
535+
* Entries in this list are added to any defined in the creates
536+
* block in the setup_collection section.
522537
*
523538
* - does_not_create
524539
* An optional list of file names (regular expressions).
@@ -632,13 +647,17 @@ class Tester {
632647
boolean validated = true
633648
if (exitValue == 0) {
634649

650+
List<String> testCreates = collectionCreates
651+
if (createsBlock != null) {
652+
testCreates.addAll(createsBlock)
653+
}
635654
// Do we expect output files?
636655
// Here we look for things like "output*" in the
637656
// redirected output path.
638-
if (testOutputPath != null && createsBlock != null) {
657+
if (testOutputPath != null && testCreates.size() > 0) {
639658
def createdFiles = new FileNameFinder().
640659
getFileNames(testOutputPath.toString(), "*")
641-
for (String expectedFile in createsBlock) {
660+
for (String expectedFile in testCreates.unique()) {
642661
boolean found = false
643662
for (String createdFile in createdFiles) {
644663
if (createdFile.endsWith(expectedFile)) {

src/groovy/pipeline.test.template

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,16 @@
2626
// timeout: The time allowed for each pipeline test to complete.
2727
// Use this to override the default of 30 seconds.
2828
//
29+
// creates: A list of file names that each test is expected to create.
30+
// Tests can define test-specific files with their own
31+
// 'creates' block.
32+
//
2933
// There can only be one setup_collection section and it must be
3034
// the first section.
3135

3236
setup_collection = [
33-
timeout: 10
37+
timeout: 10,
38+
creates: [ 'output.txt' ]
3439
],
3540

3641
// Individual tests.
@@ -67,7 +72,7 @@
6772

6873
command: ```python my_own_command
6974
--my-own-param-1 32
70-
--my-own-param-2 18.5```
75+
--my-own-param-2 18.5```,
7176

7277
// Test parameters.
7378
//
@@ -92,17 +97,16 @@
9297

9398
see: [ 'Computation = 4.5673' ],
9499

95-
// Files created and not created.
100+
// Files created.
96101
//
97-
// If your pipeline creates files you can and should declare
98-
// their names in a `creates` block. The test utility will make
99-
// sure they exist when your pipeline completes (successfully).
100-
// Additionally, if you are not expecting certain files for the test
101-
// you can also name them. Here we expect to see the file 'output.png'
102-
// but not the file 'output.txt'
103-
104-
creates: [ 'output.png' ],
105-
does_not_create: [ 'output.txt' ]
102+
// If your pipeline test creates files you can and should declare
103+
// their names in a `creates` block, either here or in the
104+
// `setup_collection` section. All files defined in the creates blocks
105+
// must exist for the test to pass. Here we expect 'output.png'
106+
// but the test also expects 'output.txt' as that's defined in the
107+
// 'setup_collection' block above.
108+
109+
creates: [ 'output.png' ]
106110

107111
],
108112

0 commit comments

Comments
 (0)