From e1c18b7980e99da841e7d2b31ce90bb7deb1c026 Mon Sep 17 00:00:00 2001 From: Markus Krogemann Date: Sat, 20 Jul 2013 01:23:38 +0200 Subject: [PATCH] fix issue #338: Make devPhase part of groupName --- .../netflix/asgard/GroupCreateCommand.groovy | 10 ++++++++++ grails-app/i18n/messages.properties | 2 ++ .../asgard/GroupCreateCommandSpec.groovy | 17 +++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/grails-app/controllers/com/netflix/asgard/GroupCreateCommand.groovy b/grails-app/controllers/com/netflix/asgard/GroupCreateCommand.groovy index 2dd11c82..617f44d0 100644 --- a/grails-app/controllers/com/netflix/asgard/GroupCreateCommand.groovy +++ b/grails-app/controllers/com/netflix/asgard/GroupCreateCommand.groovy @@ -27,6 +27,7 @@ import grails.validation.Validateable String stack String newStack String detail + String devPhase String chaosMonkey String region String imageId @@ -35,6 +36,15 @@ import grails.validation.Validateable static constraints = { + devPhase(nullable: true, validator: { value, command -> + if (value && !Relationships.checkName(value)) { + return "devPhase.illegalChar" + } + if (Relationships.usesReservedFormat(value)) { + return "name.usesReservedFormat" + } + }) + appName(nullable: false, blank: false, validator: { value, command -> if (!Relationships.checkName(value)) { return "application.name.illegalChar" diff --git a/grails-app/i18n/messages.properties b/grails-app/i18n/messages.properties index ece1a386..7b4c80fe 100644 --- a/grails-app/i18n/messages.properties +++ b/grails-app/i18n/messages.properties @@ -56,6 +56,8 @@ groupName.exists=There is already an auto scaling group named {3} stack.illegalChar=The new stack field must be empty or consist of alphanumeric characters stack.matchesNewStack=You cannot use both an existing stack and a new stack +devPhase.illegalChar=DevPhase can only contain letters, numbers, underscores, and dots + name.usesReservedFormat=The format "v###" (where # is any digit) and the format "[a-z]0" (where [a-z] is any letter) are reserved. Please use a different name. snapshotCommand.volumeSize.matches.error=Volume size must be an integer diff --git a/test/unit/com/netflix/asgard/GroupCreateCommandSpec.groovy b/test/unit/com/netflix/asgard/GroupCreateCommandSpec.groovy index 78dec294..46d01a66 100644 --- a/test/unit/com/netflix/asgard/GroupCreateCommandSpec.groovy +++ b/test/unit/com/netflix/asgard/GroupCreateCommandSpec.groovy @@ -132,6 +132,23 @@ class GroupCreateCommandSpec extends Specification { 'blah-v305' | 'name.usesReservedFormat' } + @Unroll("""should validate devPhase input '#devPhase' with error code '#error'""") + def 'devPhase constraints'() { + cmd.stack = 'iphone' + cmd.devPhase = devPhase + + when: + cmd.validate() + + then: + cmd.errors.devPhase == error + + where: + devPhase | error + 'v305' | 'name.usesReservedFormat' + 'foo-bar' | 'devPhase.illegalChar' + } + @Unroll("""should validate chaosMonkey input '#chaosMonkey' with error code '#error' when requestedFromGui is \ '#requestedFromGui' and isChaosMonkeyActive is '#isChaosMonkeyActive' and optLevel is '#optLevel'""") def 'chaosMonkey constraints'() {