add affirmative test case for #4762
This commit is contained in:
parent
dba189f587
commit
3f6b5165f2
|
@ -73,8 +73,8 @@ func (c *AMIConfig) Prepare(ctx *interpolate.Context) []error {
|
||||||
errs = append(errs, fmt.Errorf("AMIName must be between 3 and 128 characters long"))
|
errs = append(errs, fmt.Errorf("AMIName must be between 3 and 128 characters long"))
|
||||||
}
|
}
|
||||||
|
|
||||||
var IsValidName = regexp.MustCompile(`^[a-zA-Z().-/_]+$`).MatchString
|
amiNameRe := regexp.MustCompile(`^[a-zA-Z().\-/_]+$`)
|
||||||
if !IsValidName(c.AMIName) {
|
if !amiNameRe.MatchString(c.AMIName) {
|
||||||
errs = append(errs, fmt.Errorf("AMIName should only contain letters, numbers, '(', ')', '.', '-', '/' and '_'"))
|
errs = append(errs, fmt.Errorf("AMIName should only contain letters, numbers, '(', ')', '.', '-', '/' and '_'"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -96,4 +96,10 @@ func TestAMINameValidation(t *testing.T) {
|
||||||
if err := c.Prepare(nil); err == nil {
|
if err := c.Prepare(nil); err == nil {
|
||||||
t.Fatal("shouldn't be able to have an ami name with invalid characters")
|
t.Fatal("shouldn't be able to have an ami name with invalid characters")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
c.AMIName = "foo().-/_bar"
|
||||||
|
if err := c.Prepare(nil); err != nil {
|
||||||
|
t.Fatal("expected 'foobar' to be a valid ami name")
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue