github.com/sneal/packer@v0.5.2/builder/virtualbox/common/output_config_test.go (about)

     1  package common
     2  
     3  import (
     4  	"github.com/mitchellh/packer/common"
     5  	"io/ioutil"
     6  	"os"
     7  	"testing"
     8  )
     9  
    10  func TestOutputConfigPrepare(t *testing.T) {
    11  	c := new(OutputConfig)
    12  	if c.OutputDir != "" {
    13  		t.Fatalf("what: %s", c.OutputDir)
    14  	}
    15  
    16  	pc := &common.PackerConfig{PackerBuildName: "foo"}
    17  	errs := c.Prepare(testConfigTemplate(t), pc)
    18  	if len(errs) > 0 {
    19  		t.Fatalf("err: %#v", errs)
    20  	}
    21  
    22  	if c.OutputDir == "" {
    23  		t.Fatal("should have output dir")
    24  	}
    25  }
    26  
    27  func TestOutputConfigPrepare_exists(t *testing.T) {
    28  	td, err := ioutil.TempDir("", "packer")
    29  	if err != nil {
    30  		t.Fatalf("err: %s", err)
    31  	}
    32  	defer os.RemoveAll(td)
    33  
    34  	c := new(OutputConfig)
    35  	c.OutputDir = td
    36  
    37  	pc := &common.PackerConfig{
    38  		PackerBuildName: "foo",
    39  		PackerForce:     false,
    40  	}
    41  	errs := c.Prepare(testConfigTemplate(t), pc)
    42  	if len(errs) == 0 {
    43  		t.Fatal("should have errors")
    44  	}
    45  }
    46  
    47  func TestOutputConfigPrepare_forceExists(t *testing.T) {
    48  	td, err := ioutil.TempDir("", "packer")
    49  	if err != nil {
    50  		t.Fatalf("err: %s", err)
    51  	}
    52  	defer os.RemoveAll(td)
    53  
    54  	c := new(OutputConfig)
    55  	c.OutputDir = td
    56  
    57  	pc := &common.PackerConfig{
    58  		PackerBuildName: "foo",
    59  		PackerForce:     true,
    60  	}
    61  	errs := c.Prepare(testConfigTemplate(t), pc)
    62  	if len(errs) > 0 {
    63  		t.Fatal("should not have errors")
    64  	}
    65  }