github.phpd.cn/hashicorp/packer@v1.3.2/builder/azure/arm/tempname_test.go (about) 1 package arm 2 3 import ( 4 "strings" 5 "testing" 6 7 "github.com/hashicorp/packer/common/random" 8 ) 9 10 func TestTempNameShouldCreatePrefixedRandomNames(t *testing.T) { 11 tempName := NewTempName() 12 13 if strings.Index(tempName.ComputeName, "pkrvm") != 0 { 14 t.Errorf("Expected ComputeName to begin with 'pkrvm', but got '%s'!", tempName.ComputeName) 15 } 16 17 if strings.Index(tempName.DeploymentName, "pkrdp") != 0 { 18 t.Errorf("Expected ComputeName to begin with 'pkrdp', but got '%s'!", tempName.ComputeName) 19 } 20 21 if strings.Index(tempName.OSDiskName, "pkros") != 0 { 22 t.Errorf("Expected OSDiskName to begin with 'pkros', but got '%s'!", tempName.OSDiskName) 23 } 24 25 if strings.Index(tempName.NicName, "pkrni") != 0 { 26 t.Errorf("Expected NicName to begin with 'pkrni', but got '%s'!", tempName.NicName) 27 } 28 29 if strings.Index(tempName.PublicIPAddressName, "pkrip") != 0 { 30 t.Errorf("Expected PublicIPAddressName to begin with 'pkrip', but got '%s'!", tempName.PublicIPAddressName) 31 } 32 33 if strings.Index(tempName.ResourceGroupName, "packer-Resource-Group-") != 0 { 34 t.Errorf("Expected ResourceGroupName to begin with 'packer-Resource-Group-', but got '%s'!", tempName.ResourceGroupName) 35 } 36 37 if strings.Index(tempName.SubnetName, "pkrsn") != 0 { 38 t.Errorf("Expected SubnetName to begin with 'pkrip', but got '%s'!", tempName.SubnetName) 39 } 40 41 if strings.Index(tempName.VirtualNetworkName, "pkrvn") != 0 { 42 t.Errorf("Expected VirtualNetworkName to begin with 'pkrvn', but got '%s'!", tempName.VirtualNetworkName) 43 } 44 } 45 46 func TestTempAdminPassword(t *testing.T) { 47 tempName := NewTempName() 48 49 if !strings.ContainsAny(tempName.AdminPassword, random.PossibleNumbers) { 50 t.Errorf("Expected AdminPassword to contain at least one of '%s'!", random.PossibleNumbers) 51 } 52 if !strings.ContainsAny(tempName.AdminPassword, random.PossibleLowerCase) { 53 t.Errorf("Expected AdminPassword to contain at least one of '%s'!", random.PossibleLowerCase) 54 } 55 if !strings.ContainsAny(tempName.AdminPassword, random.PossibleUpperCase) { 56 t.Errorf("Expected AdminPassword to contain at least one of '%s'!", random.PossibleUpperCase) 57 } 58 } 59 60 func TestTempNameShouldHaveSameSuffix(t *testing.T) { 61 tempName := NewTempName() 62 suffix := tempName.ComputeName[5:] 63 64 if strings.HasSuffix(tempName.ComputeName, suffix) != true { 65 t.Errorf("Expected ComputeName to end with '%s', but the value is '%s'!", suffix, tempName.ComputeName) 66 } 67 68 if strings.HasSuffix(tempName.DeploymentName, suffix) != true { 69 t.Errorf("Expected DeploymentName to end with '%s', but the value is '%s'!", suffix, tempName.DeploymentName) 70 } 71 72 if strings.HasSuffix(tempName.OSDiskName, suffix) != true { 73 t.Errorf("Expected OSDiskName to end with '%s', but the value is '%s'!", suffix, tempName.OSDiskName) 74 } 75 76 if strings.HasSuffix(tempName.NicName, suffix) != true { 77 t.Errorf("Expected NicName to end with '%s', but the value is '%s'!", suffix, tempName.PublicIPAddressName) 78 } 79 80 if strings.HasSuffix(tempName.PublicIPAddressName, suffix) != true { 81 t.Errorf("Expected PublicIPAddressName to end with '%s', but the value is '%s'!", suffix, tempName.PublicIPAddressName) 82 } 83 84 if strings.HasSuffix(tempName.ResourceGroupName, suffix) != true { 85 t.Errorf("Expected ResourceGroupName to end with '%s', but the value is '%s'!", suffix, tempName.ResourceGroupName) 86 } 87 88 if strings.HasSuffix(tempName.SubnetName, suffix) != true { 89 t.Errorf("Expected SubnetName to end with '%s', but the value is '%s'!", suffix, tempName.SubnetName) 90 } 91 92 if strings.HasSuffix(tempName.VirtualNetworkName, suffix) != true { 93 t.Errorf("Expected VirtualNetworkName to end with '%s', but the value is '%s'!", suffix, tempName.VirtualNetworkName) 94 } 95 }