2018-10-17 03:59:13 -04:00
|
|
|
// +build !windows
|
|
|
|
|
2014-04-06 13:21:22 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"io/ioutil"
|
|
|
|
"os"
|
|
|
|
"testing"
|
2016-12-11 14:13:37 -05:00
|
|
|
|
2020-12-17 16:29:25 -05:00
|
|
|
"github.com/hashicorp/packer-plugin-sdk/common"
|
|
|
|
"github.com/hashicorp/packer-plugin-sdk/template/interpolate"
|
2014-04-06 13:21:22 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestOutputConfigPrepare(t *testing.T) {
|
|
|
|
c := new(OutputConfig)
|
|
|
|
if c.OutputDir != "" {
|
|
|
|
t.Fatalf("what: %s", c.OutputDir)
|
|
|
|
}
|
|
|
|
|
|
|
|
pc := &common.PackerConfig{PackerBuildName: "foo"}
|
2019-06-14 04:55:10 -04:00
|
|
|
errs := c.Prepare(interpolate.NewContext(), pc)
|
2014-04-06 13:21:22 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("err: %#v", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.OutputDir == "" {
|
|
|
|
t.Fatal("should have output dir")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputConfigPrepare_exists(t *testing.T) {
|
|
|
|
td, err := ioutil.TempDir("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
|
|
|
c := new(OutputConfig)
|
|
|
|
c.OutputDir = td
|
|
|
|
|
|
|
|
pc := &common.PackerConfig{
|
|
|
|
PackerBuildName: "foo",
|
|
|
|
PackerForce: false,
|
|
|
|
}
|
2019-06-14 04:55:10 -04:00
|
|
|
errs := c.Prepare(interpolate.NewContext(), pc)
|
2014-04-06 13:21:22 -04:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatal("should have errors")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestOutputConfigPrepare_forceExists(t *testing.T) {
|
|
|
|
td, err := ioutil.TempDir("", "packer")
|
|
|
|
if err != nil {
|
|
|
|
t.Fatalf("err: %s", err)
|
|
|
|
}
|
|
|
|
defer os.RemoveAll(td)
|
|
|
|
|
|
|
|
c := new(OutputConfig)
|
|
|
|
c.OutputDir = td
|
|
|
|
|
|
|
|
pc := &common.PackerConfig{
|
|
|
|
PackerBuildName: "foo",
|
|
|
|
PackerForce: true,
|
|
|
|
}
|
2019-06-14 04:55:10 -04:00
|
|
|
errs := c.Prepare(interpolate.NewContext(), pc)
|
2014-04-06 13:21:22 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatal("should not have errors")
|
|
|
|
}
|
|
|
|
}
|