github.phpd.cn/hashicorp/packer@v1.3.2/builder/azure/arm/template_funcs_test.go (about) 1 package arm 2 3 import "testing" 4 5 func TestTemplateCleanImageName(t *testing.T) { 6 vals := []struct { 7 origName string 8 expected string 9 }{ 10 // test that valid name is unchanged 11 { 12 origName: "abcde-012345xyz", 13 expected: "abcde-012345xyz", 14 }, 15 // test that colons are converted to hyphens 16 { 17 origName: "abcde-012345v1.0:0", 18 expected: "abcde-012345v1.0-0", 19 }, 20 // Name starting with number is not valid, but not in scope of this 21 // function to correct 22 { 23 origName: "012345v1.0:0", 24 expected: "012345v1.0-0", 25 }, 26 // Name over 80 chars is not valid, but not corrected by this function. 27 { 28 origName: "l012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", 29 expected: "l012345678901234567890123456789012345678901234567890123456789012345678901234567890123456789", 30 }, 31 // Name cannot end in a -Name over 80 chars is not valid, but not corrected by this function. 32 { 33 origName: "abcde-:_", 34 expected: "abcde", 35 }, 36 // Lost of special characters 37 { 38 origName: "My()./-_:&^ $%[]#'@name", 39 expected: "My--.--_-----------name", 40 }, 41 } 42 43 for _, v := range vals { 44 name := templateCleanImageName(v.origName) 45 if name != v.expected { 46 t.Fatalf("template names do not match: expected %s got %s\n", v.expected, name) 47 } 48 } 49 }