github.com/StackPointCloud/packer@v0.10.2-0.20180716202532-b28098e0f79b/builder/azure/arm/tempname_test.go (about) 1 package arm 2 3 import ( 4 "strings" 5 "testing" 6 ) 7 8 func TestTempNameShouldCreatePrefixedRandomNames(t *testing.T) { 9 tempName := NewTempName() 10 11 if strings.Index(tempName.ComputeName, "pkrvm") != 0 { 12 t.Errorf("Expected ComputeName to begin with 'pkrvm', but got '%s'!", tempName.ComputeName) 13 } 14 15 if strings.Index(tempName.DeploymentName, "pkrdp") != 0 { 16 t.Errorf("Expected ComputeName to begin with 'pkrdp', but got '%s'!", tempName.ComputeName) 17 } 18 19 if strings.Index(tempName.OSDiskName, "pkros") != 0 { 20 t.Errorf("Expected OSDiskName to begin with 'pkros', but got '%s'!", tempName.OSDiskName) 21 } 22 23 if strings.Index(tempName.NicName, "pkrni") != 0 { 24 t.Errorf("Expected NicName to begin with 'pkrni', but got '%s'!", tempName.NicName) 25 } 26 27 if strings.Index(tempName.PublicIPAddressName, "pkrip") != 0 { 28 t.Errorf("Expected PublicIPAddressName to begin with 'pkrip', but got '%s'!", tempName.PublicIPAddressName) 29 } 30 31 if strings.Index(tempName.ResourceGroupName, "packer-Resource-Group-") != 0 { 32 t.Errorf("Expected ResourceGroupName to begin with 'packer-Resource-Group-', but got '%s'!", tempName.ResourceGroupName) 33 } 34 35 if strings.Index(tempName.SubnetName, "pkrsn") != 0 { 36 t.Errorf("Expected SubnetName to begin with 'pkrip', but got '%s'!", tempName.SubnetName) 37 } 38 39 if strings.Index(tempName.VirtualNetworkName, "pkrvn") != 0 { 40 t.Errorf("Expected VirtualNetworkName to begin with 'pkrvn', but got '%s'!", tempName.VirtualNetworkName) 41 } 42 } 43 44 func TestTempNameShouldHaveSameSuffix(t *testing.T) { 45 tempName := NewTempName() 46 suffix := tempName.ComputeName[5:] 47 48 if strings.HasSuffix(tempName.ComputeName, suffix) != true { 49 t.Errorf("Expected ComputeName to end with '%s', but the value is '%s'!", suffix, tempName.ComputeName) 50 } 51 52 if strings.HasSuffix(tempName.DeploymentName, suffix) != true { 53 t.Errorf("Expected DeploymentName to end with '%s', but the value is '%s'!", suffix, tempName.DeploymentName) 54 } 55 56 if strings.HasSuffix(tempName.OSDiskName, suffix) != true { 57 t.Errorf("Expected OSDiskName to end with '%s', but the value is '%s'!", suffix, tempName.OSDiskName) 58 } 59 60 if strings.HasSuffix(tempName.NicName, suffix) != true { 61 t.Errorf("Expected NicName to end with '%s', but the value is '%s'!", suffix, tempName.PublicIPAddressName) 62 } 63 64 if strings.HasSuffix(tempName.PublicIPAddressName, suffix) != true { 65 t.Errorf("Expected PublicIPAddressName to end with '%s', but the value is '%s'!", suffix, tempName.PublicIPAddressName) 66 } 67 68 if strings.HasSuffix(tempName.ResourceGroupName, suffix) != true { 69 t.Errorf("Expected ResourceGroupName to end with '%s', but the value is '%s'!", suffix, tempName.ResourceGroupName) 70 } 71 72 if strings.HasSuffix(tempName.SubnetName, suffix) != true { 73 t.Errorf("Expected SubnetName to end with '%s', but the value is '%s'!", suffix, tempName.SubnetName) 74 } 75 76 if strings.HasSuffix(tempName.VirtualNetworkName, suffix) != true { 77 t.Errorf("Expected VirtualNetworkName to end with '%s', but the value is '%s'!", suffix, tempName.VirtualNetworkName) 78 } 79 }