Skip to content

Commit b0bc928

Browse files
author
Alan Christie
committed
- First working output descriptor checking
1 parent 278d2b8 commit b0bc928

File tree

5 files changed

+215
-104
lines changed

5 files changed

+215
-104
lines changed

src/groovy/Log.groovy

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// Number of warnings generated
2+
def warningCount = 7
3+
4+
/**
5+
* Print a simple separator (a bar) to stdout.
6+
* Used to visually separate generated output into logical blocks.
7+
*/
8+
static separate() {
9+
10+
// To look 'pretty' this should align with the field width
11+
// used in the info() function
12+
println "+----------------+"
13+
14+
}
15+
16+
/**
17+
* Print an 'info' message prefixed with `->` string. You can specify a
18+
* tag and a message which is printed as "-> <tag> : <msg>"
19+
*/
20+
static info(String tag, String msg) {
21+
22+
println ":" + sprintf('%16s: %s', tag, msg)
23+
24+
}
25+
26+
/**
27+
* Print a warning message (and counts it).
28+
*/
29+
static warning(String msg) {
30+
31+
println "WARNING: $msg"
32+
Log.warningCount += 1
33+
34+
}
35+
36+
/**
37+
* Print an error message.
38+
*/
39+
static err(String msg) {
40+
41+
println "ERROR: $msg"
42+
43+
}

src/groovy/MediaChecker.groovy

Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
#!/usr/bin/env groovy
2+
3+
/**
4+
* Copyright (c) 2018 Informatics Matters Ltd.
5+
*
6+
* Licensed under the Apache License, Version 2.0 (the "License");
7+
* you may not use this file except in compliance with the License.
8+
* You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing, software
13+
* distributed under the License is distributed on an "AS IS" BASIS,
14+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15+
* See the License for the specific language governing permissions and
16+
* limitations under the License.
17+
*/
18+
19+
/**
20+
* The MediaTypes class. A class to provide validation of files produced
21+
* by an executing pipeline.
22+
*/
23+
class MediaChecker {
24+
25+
final static String mediaTypesFile = 'MediaTypes.txt'
26+
27+
// A map of media type and expected file extension(s).
28+
// This is populated by the constructor, which reads the content
29+
// of 'mediaTypesFile'.
30+
def mediaTypesLookup = null
31+
32+
/**
33+
* Default constructor.
34+
* Reads media types config file.
35+
*/
36+
MediaChecker() {
37+
38+
mediaTypesLookup = new ConfigSlurper().parse(new File(mediaTypesFile).toURI().toURL())
39+
40+
}
41+
42+
/**
43+
* Checks that a pipeline's expected files exist.
44+
*
45+
* @param serviceDescriptor The test service descriptor
46+
* @param path The test path (where the pipeline's files are to be found)
47+
* @return True on success, False otherwise.
48+
*/
49+
boolean check(serviceDescriptor, File path) {
50+
51+
boolean retVal = true
52+
53+
// Check output descriptors for expected output file names...
54+
// Do all, regardless of individual failure.
55+
def opDescriptors = serviceDescriptor.serviceConfig.outputDescriptors
56+
opDescriptors.each { desc ->
57+
58+
// Expected extension...
59+
// (use the media type to lookup it up)
60+
// And construct full path to the expected file...
61+
String opExt = mediaTypesLookup.media_type[desc.mediaType]
62+
String opName = desc.name + opExt
63+
String opPath = path.toString() + File.separator + opName
64+
if (!new File(opPath).exists()) {
65+
Log.err("The pipeline's 'outputDescriptor'" +
66+
" expected '$opName' but the file wasn't found")
67+
retVal = false
68+
}
69+
70+
}
71+
72+
return retVal
73+
74+
}
75+
76+
}

src/groovy/MediaTypes.txt

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// Input/Output Descriptor dictionary for use with the PipelineTester.
2+
// This is a map of input/output descriptor `mediaType` identifiers,
3+
// with expected filename extension(s).
4+
//
5+
// Read by MediaChecker.groovy
6+
7+
media_type = [
8+
9+
// Please keep the keys in alphabetical order...
10+
11+
'application/x-squonk-dataset-molecule+json': '.data.gz',
12+
'application/x-squonk-dataset-basic+json': '.data.gz',
13+
14+
'image/gif': '.gif',
15+
'image/jpeg': '.jpg',
16+
'image/png': '.png',
17+
18+
]

src/groovy/PipelineTester.groovy

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131

3232
// Version
3333
// Update with every change/release
34-
String version = '2.0.0'
34+
String version = '2.1.0'
3535

3636
println "+----------------+"
3737
println "| PipelineTester | v$version"

0 commit comments

Comments
 (0)