github.com/kikitux/packer@v0.10.1-0.20160322154024-6237df566f9f/builder/azure/arm/deployment_factory_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  	"testing"
     8  )
     9  
    10  func TestDeploymentFactoryShouldBeIncremental(t *testing.T) {
    11  	var testSubject = newDeploymentFactory(Linux)
    12  
    13  	deployment, err := testSubject.create(getTemplateParameters())
    14  	if err != nil {
    15  		t.Fatalf("ERROR: %s\n", err)
    16  	}
    17  
    18  	if deployment.Properties.Mode != "Incremental" {
    19  		t.Fatalf("Expected the mode to be 'Incremental', but got '%s'.", deployment.Properties.Mode)
    20  	}
    21  }
    22  
    23  // Either {Template,Parameter} are set or {Template,Parameter}Link values are
    24  // set, but never both.
    25  func TestDeploymentFactoryShouldNotSetLinks(t *testing.T) {
    26  	testSubject := newDeploymentFactory(Linux)
    27  
    28  	deployment, err := testSubject.create(getTemplateParameters())
    29  	if err != nil {
    30  		t.Fatalf("ERROR: %s\n", err)
    31  	}
    32  
    33  	if deployment.Properties.ParametersLink != nil {
    34  		t.Fatalf("Expected the ParametersLink to be nil!")
    35  	}
    36  
    37  	if deployment.Properties.TemplateLink != nil {
    38  		t.Fatalf("Expected the TemplateLink to be nil!")
    39  	}
    40  
    41  	if deployment.Properties.Parameters == nil {
    42  		t.Fatalf("Expected the Parameters to not be nil!")
    43  	}
    44  
    45  	if deployment.Properties.Template == nil {
    46  		t.Fatalf("Expected the Template to not be nil!")
    47  	}
    48  }
    49  
    50  func TestFactoryShouldCreateDeploymentInstance(t *testing.T) {
    51  	testSubject := newDeploymentFactory(Linux)
    52  
    53  	deployment, err := testSubject.create(getTemplateParameters())
    54  	if err != nil {
    55  		t.Fatalf("ERROR: %s\n", err)
    56  	}
    57  
    58  	// spot check well known values to ensure correct serialization.
    59  
    60  	parametersMap := *deployment.Properties.Parameters
    61  	if _, ok := parametersMap["adminUsername"]; ok == false {
    62  		t.Fatalf("Expected the parameter value 'adminUsername' to be set, but it was not")
    63  	}
    64  
    65  	templateMap := *deployment.Properties.Template
    66  	if _, ok := templateMap["contentVersion"]; ok == false {
    67  		t.Fatalf("Expected the parameter value 'contentVersion' to be set, but it was not")
    68  	}
    69  }
    70  
    71  func TestMalformedTemplatesShouldReturnError(t *testing.T) {
    72  	testSubject := newDeploymentFactory("")
    73  
    74  	_, err := testSubject.create(getTemplateParameters())
    75  	if err == nil {
    76  		t.Fatalf("Expected an error, but did not receive one!\n")
    77  	}
    78  }
    79  
    80  func getTemplateParameters() TemplateParameters {
    81  	templateParameters := TemplateParameters{
    82  		AdminUsername:      &TemplateParameter{"adminusername00"},
    83  		DnsNameForPublicIP: &TemplateParameter{"dnsnameforpublicip00"},
    84  		OSDiskName:         &TemplateParameter{"osdiskname00"},
    85  		SshAuthorizedKey:   &TemplateParameter{"sshkeydata00"},
    86  		StorageAccountName: &TemplateParameter{"storageaccountname00"},
    87  		VMName:             &TemplateParameter{"vmname00"},
    88  		VMSize:             &TemplateParameter{"vmsize00"},
    89  	}
    90  
    91  	return templateParameters
    92  }