github.com/alouche/packer@v0.3.7/builder/openstack/builder_test.go (about)

     1  package openstack
     2  
     3  import (
     4  	"github.com/mitchellh/packer/packer"
     5  	"testing"
     6  )
     7  
     8  func testConfig() map[string]interface{} {
     9  	return map[string]interface{}{
    10  		"username":     "foo",
    11  		"password":     "bar",
    12  		"provider":     "foo",
    13  		"region":       "DFW",
    14  		"image_name":   "foo",
    15  		"source_image": "foo",
    16  		"flavor":       "foo",
    17  		"ssh_username": "root",
    18  	}
    19  }
    20  
    21  func TestBuilder_ImplementsBuilder(t *testing.T) {
    22  	var raw interface{}
    23  	raw = &Builder{}
    24  	if _, ok := raw.(packer.Builder); !ok {
    25  		t.Fatalf("Builder should be a builder")
    26  	}
    27  }
    28  
    29  func TestBuilder_Prepare_BadType(t *testing.T) {
    30  	b := &Builder{}
    31  	c := map[string]interface{}{
    32  		"password": []string{},
    33  	}
    34  
    35  	err := b.Prepare(c)
    36  	if err == nil {
    37  		t.Fatalf("prepare should fail")
    38  	}
    39  }
    40  
    41  func TestBuilderPrepare_ImageName(t *testing.T) {
    42  	var b Builder
    43  	config := testConfig()
    44  
    45  	// Test good
    46  	config["image_name"] = "foo"
    47  	err := b.Prepare(config)
    48  	if err != nil {
    49  		t.Fatalf("should not have error: %s", err)
    50  	}
    51  
    52  	// Test bad
    53  	config["image_name"] = "foo {{"
    54  	b = Builder{}
    55  	err = b.Prepare(config)
    56  	if err == nil {
    57  		t.Fatal("should have error")
    58  	}
    59  
    60  	// Test bad
    61  	delete(config, "image_name")
    62  	b = Builder{}
    63  	err = b.Prepare(config)
    64  	if err == nil {
    65  		t.Fatal("should have error")
    66  	}
    67  }
    68  
    69  func TestBuilderPrepare_InvalidKey(t *testing.T) {
    70  	var b Builder
    71  	config := testConfig()
    72  
    73  	// Add a random key
    74  	config["i_should_not_be_valid"] = true
    75  	err := b.Prepare(config)
    76  	if err == nil {
    77  		t.Fatal("should have error")
    78  	}
    79  }