github.phpd.cn/hashicorp/packer@v1.3.2/builder/googlecompute/template_funcs_test.go (about)

     1  package googlecompute
     2  
     3  import "testing"
     4  
     5  func Test_templateCleanImageName(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  
    16  		//test that capital letters are converted to lowercase
    17  		{
    18  			origName: "ABCDE-012345xyz",
    19  			expected: "abcde-012345xyz",
    20  		},
    21  		// test that periods and colons are converted to hyphens
    22  		{
    23  			origName: "abcde-012345v1.0:0",
    24  			expected: "abcde-012345v1-0-0",
    25  		},
    26  		// Name starting with number is not valid, but not in scope of this
    27  		// function to correct
    28  		{
    29  			origName: "012345v1.0:0",
    30  			expected: "012345v1-0-0",
    31  		},
    32  		// Name over 64 chars is not valid, but not corrected by this function.
    33  		{
    34  			origName: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
    35  			expected: "loooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooong",
    36  		},
    37  	}
    38  
    39  	for _, v := range vals {
    40  		name := templateCleanImageName(v.origName)
    41  		if name != v.expected {
    42  			t.Fatalf("template names do not match: expected %s got %s\n", v.expected, name)
    43  		}
    44  	}
    45  }