|
|
|
|
@ -12,108 +12,8 @@ import (
|
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
|
|
packersdk "github.com/hashicorp/packer/packer-plugin-sdk/packer"
|
|
|
|
|
"github.com/hashicorp/packer/packer/plugin"
|
|
|
|
|
)
|
|
|
|
|
|
|
|
|
|
func newConfig() config {
|
|
|
|
|
var conf config
|
|
|
|
|
conf.PluginMinPort = 10000
|
|
|
|
|
conf.PluginMaxPort = 25000
|
|
|
|
|
conf.Builders = packersdk.MapOfBuilder{}
|
|
|
|
|
conf.PostProcessors = packersdk.MapOfPostProcessor{}
|
|
|
|
|
conf.Provisioners = packersdk.MapOfProvisioner{}
|
|
|
|
|
|
|
|
|
|
return conf
|
|
|
|
|
}
|
|
|
|
|
func TestDiscoverReturnsIfMagicCookieSet(t *testing.T) {
|
|
|
|
|
config := newConfig()
|
|
|
|
|
|
|
|
|
|
os.Setenv(plugin.MagicCookieKey, plugin.MagicCookieValue)
|
|
|
|
|
defer os.Unsetenv(plugin.MagicCookieKey)
|
|
|
|
|
|
|
|
|
|
err := config.Discover()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Should not have errored: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(config.Builders) != 0 {
|
|
|
|
|
t.Fatalf("Should not have tried to find builders")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEnvVarPackerPluginPath(t *testing.T) {
|
|
|
|
|
// Create a temporary directory to store plugins in
|
|
|
|
|
dir, _, cleanUpFunc, err := generateFakePlugins("custom_plugin_dir",
|
|
|
|
|
[]string{"packer-provisioner-partyparrot"})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error creating fake custom plugins: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer cleanUpFunc()
|
|
|
|
|
|
|
|
|
|
// Add temp dir to path.
|
|
|
|
|
os.Setenv("PACKER_PLUGIN_PATH", dir)
|
|
|
|
|
defer os.Unsetenv("PACKER_PLUGIN_PATH")
|
|
|
|
|
|
|
|
|
|
config := newConfig()
|
|
|
|
|
|
|
|
|
|
err = config.Discover()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Should not have errored: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(config.Provisioners) == 0 {
|
|
|
|
|
t.Fatalf("Should have found partyparrot provisioner")
|
|
|
|
|
}
|
|
|
|
|
if _, ok := config.Provisioners["partyparrot"]; !ok {
|
|
|
|
|
t.Fatalf("Should have found partyparrot provisioner.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestEnvVarPackerPluginPath_MultiplePaths(t *testing.T) {
|
|
|
|
|
// Create a temporary directory to store plugins in
|
|
|
|
|
dir, _, cleanUpFunc, err := generateFakePlugins("custom_plugin_dir",
|
|
|
|
|
[]string{"packer-provisioner-partyparrot"})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Error creating fake custom plugins: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
defer cleanUpFunc()
|
|
|
|
|
|
|
|
|
|
pathsep := ":"
|
|
|
|
|
if runtime.GOOS == "windows" {
|
|
|
|
|
pathsep = ";"
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Create a second dir to look in that will be empty
|
|
|
|
|
decoyDir, err := ioutil.TempDir("", "decoy")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Failed to create a temporary test dir.")
|
|
|
|
|
}
|
|
|
|
|
defer os.Remove(decoyDir)
|
|
|
|
|
|
|
|
|
|
pluginPath := dir + pathsep + decoyDir
|
|
|
|
|
|
|
|
|
|
// Add temp dir to path.
|
|
|
|
|
os.Setenv("PACKER_PLUGIN_PATH", pluginPath)
|
|
|
|
|
defer os.Unsetenv("PACKER_PLUGIN_PATH")
|
|
|
|
|
|
|
|
|
|
config := newConfig()
|
|
|
|
|
|
|
|
|
|
err = config.Discover()
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatalf("Should not have errored: %s", err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if len(config.Provisioners) == 0 {
|
|
|
|
|
t.Fatalf("Should have found partyparrot provisioner")
|
|
|
|
|
}
|
|
|
|
|
if _, ok := config.Provisioners["partyparrot"]; !ok {
|
|
|
|
|
t.Fatalf("Should have found partyparrot provisioner.")
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
>>>>>>> move packer config constants next to the packer config
|
|
|
|
|
func TestDecodeConfig(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
packerConfig := `
|
|
|
|
|
|