github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/tempname_test.go (about)

     1  // Copyright (c) Microsoft Corporation. All rights reserved.
     2  // Licensed under the MIT License. See the LICENSE file in builder/azure for license information.
     3  
     4  package arm
     5  
     6  import (
     7  	"strings"
     8  	"testing"
     9  )
    10  
    11  func TestTempNameShouldCreatePrefixedRandomNames(t *testing.T) {
    12  	tempName := NewTempName()
    13  
    14  	if strings.Index(tempName.ComputeName, "pkrvm") != 0 {
    15  		t.Errorf("Expected ComputeName to begin with 'pkrvm', but got '%s'!", tempName.ComputeName)
    16  	}
    17  
    18  	if strings.Index(tempName.DeploymentName, "pkrdp") != 0 {
    19  		t.Errorf("Expected ComputeName to begin with 'pkrdp', but got '%s'!", tempName.ComputeName)
    20  	}
    21  
    22  	if strings.Index(tempName.OSDiskName, "pkros") != 0 {
    23  		t.Errorf("Expected OSDiskName to begin with 'pkros', but got '%s'!", tempName.OSDiskName)
    24  	}
    25  
    26  	if strings.Index(tempName.ResourceGroupName, "packer-Resource-Group-") != 0 {
    27  		t.Errorf("Expected ResourceGroupName to begin with 'packer-Resource-Group-', but got '%s'!", tempName.ResourceGroupName)
    28  	}
    29  }
    30  
    31  func TestTempNameShouldHaveSameSuffix(t *testing.T) {
    32  	tempName := NewTempName()
    33  	suffix := tempName.ComputeName[5:]
    34  
    35  	if strings.HasSuffix(tempName.DeploymentName, suffix) != true {
    36  		t.Errorf("Expected DeploymentName to end with '%s', but the value is '%s'!", suffix, tempName.DeploymentName)
    37  	}
    38  
    39  	if strings.HasSuffix(tempName.OSDiskName, suffix) != true {
    40  		t.Errorf("Expected OSDiskName to end with '%s', but the value is '%s'!", suffix, tempName.OSDiskName)
    41  	}
    42  
    43  	if strings.HasSuffix(tempName.ResourceGroupName, suffix) != true {
    44  		t.Errorf("Expected ResourceGroupName to end with '%s', but the value is '%s'!", suffix, tempName.ResourceGroupName)
    45  	}
    46  
    47  }