add a couple of extra tests and reword documentation

This commit is contained in:
Megan Marsh 2017-10-20 14:06:02 -07:00
parent c3a00993d0
commit 4721b48c70
2 changed files with 31 additions and 4 deletions

View File

@ -7,18 +7,33 @@ func Test_templateCleanImageName(t *testing.T) {
origName string
expected string
}{
// test that valid name is unchanged
{
origName: "abcde-012345xyz",
expected: "abcde-012345xyz",
},
//test that capital letters are converted to lowercase
{
origName: "ABCDE-012345xyz",
expected: "abcde-012345xyz",
},
// test that periods and colons are converted to hyphens
{
origName: "abcde-012345v1.0.0",
origName: "abcde-012345v1.0:0",
expected: "abcde-012345v1-0-0",
},
// Name starting with number is not valid, but not in scope of this
// function to correct
{
origName: "012345v1.0:0",
expected: "012345v1-0-0",
},
// Name over 64 chars is not valid, but not corrected by this function.
{
origName: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
expected: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
},
}
for _, v := range vals {

View File

@ -55,10 +55,22 @@ Here is a full list of the available functions for reference.
- `clean_image_name` - GCE image names can only contain certain characters and
the maximum length is 63. This function will convert upper cases to lower cases
and replace illegal characters with a "-" character.
Example usage since ":" is not a legal image name is: `"a-{{isotime | clean_image_name}}"` -> `a-2017-10-18t02-06-30z`.
Example:
Note that image name must be a match of regex `(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)`
but this function won't truncate and replace with valid character such as 'a' except '-'.
`"mybuild-{{isotime | clean_image_name}}"`
will become
`mybuild-2017-10-18t02-06-30z`.
Note: Valid GCE image names must match the regex
`(?:[a-z](?:[-a-z0-9]{0,61}[a-z0-9])?)`
This engine does not guarantee that the final image name will match the
regex; it will not truncate your name if it exceeds 63 characters, and it
will not valiate that the beginning and end of the engine's output are
valid. For example,
`"image_name": {{isotime | clean_image_name}}"` will cause your build to
fail because the image name will start with a number, which is why in the
above example we prepend the isotime with "mybuild".
## Template variables