github.com/amanya/packer@v0.12.1-0.20161117214323-902ac5ab2eb6/builder/profitbricks/builder_test.go (about)

     1  package profitbricks
     2  
     3  import (
     4  	"fmt"
     5  	"github.com/mitchellh/packer/packer"
     6  	"testing"
     7  )
     8  
     9  func testConfig() map[string]interface{} {
    10  	return map[string]interface{}{
    11  		"image":         "Ubuntu-16.04",
    12  		"password":      "password",
    13  		"username":      "username",
    14  		"snapshot_name": "packer",
    15  		"type":          "profitbricks",
    16  	}
    17  }
    18  
    19  func TestImplementsBuilder(t *testing.T) {
    20  	var raw interface{}
    21  	raw = &Builder{}
    22  	if _, ok := raw.(packer.Builder); !ok {
    23  		t.Fatalf("Builder should be a builder")
    24  	}
    25  }
    26  
    27  func TestBuilder_Prepare_BadType(t *testing.T) {
    28  	b := &Builder{}
    29  	c := map[string]interface{}{
    30  		"api_key": []string{},
    31  	}
    32  
    33  	warns, err := b.Prepare(c)
    34  	if len(warns) > 0 {
    35  		t.Fatalf("bad: %#v", warns)
    36  	}
    37  	if err == nil {
    38  		fmt.Println(err)
    39  		fmt.Println(warns)
    40  		t.Fatalf("prepare should fail")
    41  	}
    42  }
    43  
    44  func TestBuilderPrepare_InvalidKey(t *testing.T) {
    45  	var b Builder
    46  	config := testConfig()
    47  
    48  	config["i_should_not_be_valid"] = true
    49  	warnings, err := b.Prepare(config)
    50  	if len(warnings) > 0 {
    51  		t.Fatalf("bad: %#v", warnings)
    52  	}
    53  	if err == nil {
    54  		t.Fatal("should have error")
    55  	}
    56  }