github.phpd.cn/hashicorp/packer@v1.3.2/builder/hyperv/common/output_config_test.go (about) 1 package common 2 3 import ( 4 "io/ioutil" 5 "os" 6 "testing" 7 8 "github.com/hashicorp/packer/common" 9 ) 10 11 func TestOutputConfigPrepare(t *testing.T) { 12 c := new(OutputConfig) 13 if c.OutputDir != "" { 14 t.Fatalf("what: %s", c.OutputDir) 15 } 16 17 pc := &common.PackerConfig{PackerBuildName: "foo"} 18 errs := c.Prepare(testConfigTemplate(t), pc) 19 if len(errs) > 0 { 20 t.Fatalf("err: %#v", errs) 21 } 22 23 if c.OutputDir == "" { 24 t.Fatal("should have output dir") 25 } 26 } 27 28 func TestOutputConfigPrepare_exists(t *testing.T) { 29 td, err := ioutil.TempDir("", "packer") 30 if err != nil { 31 t.Fatalf("err: %s", err) 32 } 33 defer os.RemoveAll(td) 34 35 c := new(OutputConfig) 36 c.OutputDir = td 37 38 pc := &common.PackerConfig{ 39 PackerBuildName: "foo", 40 PackerForce: false, 41 } 42 errs := c.Prepare(testConfigTemplate(t), pc) 43 if len(errs) != 0 { 44 t.Fatal("should not have errors") 45 } 46 }