Skip to content

Commit 71e699a

Browse files
committed
Add a few tests for invalid OS or platform
1 parent efcee20 commit 71e699a

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

src/main/groovy/net/gleske/jervis/lang/MultiPlatformValidator.groovy

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,22 @@ getGeneratorFromJervis(yaml: '', folder_listing: []
319319
}
320320
// TODO verify neither os nor platform are named as keys.
321321
}
322+
// If jenkins.platform is provided, all values MUST be known platforms
323+
List user_platforms = YamlOperator.getObjectValue(jervis_yaml, 'jenkins.platform', [[], '']).with {
324+
(it in List) ? it : [it]
325+
}.findAll { it instanceof String && it.trim() }
326+
List unknown_platforms = user_platforms - this.known_platforms
327+
if(unknown_platforms) {
328+
errors << "jenkins.platform contains unknown platforms: ${unknown_platforms.inspect()}. Known platforms: ${this.known_platforms.inspect()}"
329+
}
330+
// If jenkins.os is provided, all values MUST be known operating systems
331+
List user_os = YamlOperator.getObjectValue(jervis_yaml, 'jenkins.os', [[], '']).with {
332+
(it in List) ? it : [it]
333+
}.findAll { it instanceof String && it.trim() }
334+
List unknown_os = user_os - this.known_operating_systems
335+
if(unknown_os) {
336+
errors << "jenkins.os contains unknown operating systems: ${unknown_os.inspect()}. Known operating systems: ${this.known_operating_systems.inspect()}"
337+
}
322338
if(errors) {
323339
// TODO MultiPlatformException
324340
throw new Exception("Multi-platform YAML validation has failed:\n\n - " + errors.sort().unique().join('\n - ') + "\n\nSee one or more errors above.")

src/test/groovy/net/gleske/jervis/lang/MultiPlatformValidatorTest.groovy

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,30 @@ class MultiPlatformValidatorTest extends GroovyTestCase {
322322
platforms.validateJervisYaml(jervisYaml)
323323
}
324324
}
325+
@Test public void test_MultiPlatformValidator_validateJervisYaml_invalid_platform_value() {
326+
loadFullMultiPlatformResources()
327+
Map jervisYaml = [
328+
language: 'groovy',
329+
jenkins: [
330+
platform: ['x86_64', 'foo'] // 'foo' is not a valid platform
331+
]
332+
]
333+
shouldFail(Exception) {
334+
platforms.validateJervisYaml(jervisYaml)
335+
}
336+
}
337+
@Test public void test_MultiPlatformValidator_validateJervisYaml_invalid_os_value() {
338+
loadFullMultiPlatformResources()
339+
Map jervisYaml = [
340+
language: 'groovy',
341+
jenkins: [
342+
os: ['alpine3', 'foo'] // 'foo' is not a valid os
343+
]
344+
]
345+
shouldFail(Exception) {
346+
platforms.validateJervisYaml(jervisYaml)
347+
}
348+
}
325349
//serialization tests
326350
@Test public void test_MultiPlatformValidator_serialization() {
327351
loadFullMultiPlatformResources()

0 commit comments

Comments
 (0)