2014-09-02 03:53:21 -04:00
|
|
|
package common
|
|
|
|
|
|
|
|
import (
|
|
|
|
"testing"
|
2019-06-14 04:55:10 -04:00
|
|
|
|
2020-11-11 13:21:37 -05:00
|
|
|
"github.com/hashicorp/packer/packer-plugin-sdk/template/interpolate"
|
2014-09-02 03:53:21 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func testToolsConfig() *ToolsConfig {
|
|
|
|
return &ToolsConfig{
|
|
|
|
ParallelsToolsFlavor: "foo",
|
|
|
|
ParallelsToolsGuestPath: "foo",
|
|
|
|
ParallelsToolsMode: "attach",
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToolsConfigPrepare(t *testing.T) {
|
|
|
|
c := testToolsConfig()
|
2019-06-14 04:55:10 -04:00
|
|
|
errs := c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("bad err: %#v", errs)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToolsConfigPrepare_ParallelsToolsMode(t *testing.T) {
|
|
|
|
var c *ToolsConfig
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
// Test default mode
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsMode = ""
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("should not have error: %#v", errs)
|
|
|
|
}
|
|
|
|
if c.ParallelsToolsMode != ParallelsToolsModeUpload {
|
|
|
|
t.Errorf("bad parallels tools mode: %s", c.ParallelsToolsMode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test another mode
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsMode = "attach"
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("should not have error: %#v", errs)
|
|
|
|
}
|
|
|
|
if c.ParallelsToolsMode != ParallelsToolsModeAttach {
|
|
|
|
t.Fatalf("bad mode: %s", c.ParallelsToolsMode)
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test invalid mode
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsMode = "invalid_mode"
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToolsConfigPrepare_ParallelsToolsGuestPath(t *testing.T) {
|
|
|
|
var c *ToolsConfig
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
// Test default path
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsGuestPath = ""
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("should not have error: %#v", errs)
|
|
|
|
}
|
|
|
|
if c.ParallelsToolsGuestPath == "" {
|
|
|
|
t.Fatal("should not be empty")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsGuestPath = "foo"
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("should not have error: %s", errs)
|
|
|
|
}
|
|
|
|
|
|
|
|
if c.ParallelsToolsGuestPath != "foo" {
|
|
|
|
t.Fatalf("bad guest path: %s", c.ParallelsToolsGuestPath)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func TestToolsConfigPrepare_ParallelsToolsFlavor(t *testing.T) {
|
|
|
|
var c *ToolsConfig
|
|
|
|
var errs []error
|
|
|
|
|
|
|
|
// Test with a default value
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsFlavor = ""
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with an bad value
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsMode = "attach"
|
|
|
|
c.ParallelsToolsFlavor = ""
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) == 0 {
|
|
|
|
t.Fatal("should have error")
|
|
|
|
}
|
|
|
|
|
|
|
|
// Test with a good one
|
|
|
|
c = testToolsConfig()
|
|
|
|
c.ParallelsToolsMode = "disable"
|
|
|
|
c.ParallelsToolsFlavor = ""
|
2019-06-14 04:55:10 -04:00
|
|
|
errs = c.Prepare(interpolate.NewContext())
|
2014-09-02 03:53:21 -04:00
|
|
|
if len(errs) > 0 {
|
|
|
|
t.Fatalf("should not have error: %s", errs)
|
|
|
|
}
|
|
|
|
}
|