add a test

This commit is contained in:
Adrien Delorme 2020-10-30 12:41:29 +01:00
parent 91d7332471
commit 4e08ea6a92
2 changed files with 31 additions and 0 deletions

View File

@ -0,0 +1,9 @@
variable "image_id" {
type = string
default = "ami-something-something"
validation {
condition = length(var.image_id) > 4 && substr(var.image_id, 0, 4) == "ami-"
error_message = "The image_id value must be a valid AMI id, starting with \"ami-\"."
}
}

View File

@ -357,6 +357,28 @@ func TestParse_variables(t *testing.T) {
},
false,
},
{"valid validation block",
defaultParser,
parseTestArgs{"testdata/variables/validation/valid.pkr.hcl", nil, nil},
&PackerConfig{
Basedir: filepath.Join("testdata", "variables", "validation"),
InputVariables: Variables{
"image_id": &Variable{
DefaultValue: cty.StringVal("ami-something-something"),
Name: "image_id",
Validations: []*VariableValidation{
&VariableValidation{
ErrorMessage: `The image_id value must be a valid AMI id, starting with "ami-".`,
},
},
},
},
},
false, false,
[]packer.Build{},
false,
},
}
testParse(t, tests)
}