Skip to content

Commit

Permalink
🐛 : correct mandatory variables with default value mgmt
Browse files Browse the repository at this point in the history
resolves #140
  • Loading branch information
juwit committed Sep 24, 2019
1 parent e18cdeb commit ba0feac
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ class MandatoryStackVariablesValidator(@Autowired val moduleRepository: Terrafor
val module = this.moduleRepository.findByIdOrNull(stack.moduleId) ?: return true

return module.variables.filter { it.isMandatory }
.filter { it.defaultValue.isNullOrBlank() }
.all { ! stack.variableValues[it.name].isNullOrBlank() }
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,24 @@ void validator_shouldReturnFalse_whenMandatoryVariableIsBlank(){
assertThat(validator.isValid(stack, null)).isFalse();
}

@Test
void validator_shouldReturnTrue_whenMandatoryVariableWithDefaultValueIsBlank(){
var variable = new TerraformVariable();
variable.setName("test");
variable.setMandatory(true);
variable.setDefaultValue("default");

var module = new TerraformModule();
module.setVariables(List.of(variable));

when(moduleRepository.findById("12")).thenReturn(Optional.of(module));

var stack = new Stack();
stack.setModuleId("12");

assertThat(validator.isValid(stack, null)).isTrue();
}

@Test
void validator_shouldReturnTrue_whenMandatoryVariableIsNotBlank(){
var variable = new TerraformVariable();
Expand Down

0 comments on commit ba0feac

Please sign in to comment.