File: template_funcs_test.go

package info (click to toggle)
packer 1.3.4%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,324 kB
  • sloc: python: 619; sh: 557; makefile: 111
file content (45 lines) | stat: -rw-r--r-- 1,133 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
package googlecompute

import "testing"

func Test_templateCleanImageName(t *testing.T) {
	vals := []struct {
		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",
			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 {
		name := templateCleanImageName(v.origName)
		if name != v.expected {
			t.Fatalf("template names do not match: expected %s got %s\n", v.expected, name)
		}
	}
}