2024-06-12 15:38:21 -04:00
|
|
|
package plugin_tests
|
2024-05-03 15:41:36 -04:00
|
|
|
|
2024-06-12 15:38:21 -04:00
|
|
|
import "github.com/hashicorp/packer/packer_test/lib"
|
|
|
|
|
|
|
|
|
|
func (ts *PackerPluginTestSuite) TestInstallPluginWithMetadata() {
|
2024-05-16 10:27:19 -04:00
|
|
|
tempPluginDir, cleanup := ts.MakePluginDir()
|
2024-05-03 15:41:36 -04:00
|
|
|
defer cleanup()
|
|
|
|
|
|
2024-05-16 10:27:19 -04:00
|
|
|
ts.Run("install plugin with metadata in version", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
2024-06-12 15:38:21 -04:00
|
|
|
SetArgs("plugins", "install", "--path", ts.BuildSimplePlugin("1.0.0+metadata", ts.T()), "github.com/hashicorp/tester").
|
|
|
|
|
Assert(lib.MustSucceed(), lib.Grep("Successfully installed plugin", lib.GrepStdout))
|
2024-05-16 10:27:19 -04:00
|
|
|
})
|
|
|
|
|
|
2024-05-03 15:41:36 -04:00
|
|
|
ts.Run("metadata plugin installed must not have metadata in its path", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
|
|
|
|
SetArgs("plugins", "installed").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.0[^+]", lib.GrepStdout))
|
2024-05-03 15:41:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts.Run("plugin with metadata should work with validate", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
|
|
|
|
SetArgs("validate", "./templates/simple.pkr.hcl").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.0[^+][^\\n]+plugin:", lib.GrepStderr))
|
2024-05-03 15:41:36 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts.Run("plugin with metadata should work with build", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
|
|
|
|
SetArgs("build", "./templates/simple.pkr.hcl").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustSucceed(), lib.Grep("packer-plugin-tester_v1.0.0[^+][^\\n]+plugin:", lib.GrepStderr))
|
2024-05-03 15:41:36 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 15:38:21 -04:00
|
|
|
func (ts *PackerPluginTestSuite) TestInstallPluginWithPath() {
|
2024-05-16 10:29:16 -04:00
|
|
|
tempPluginDir, cleanup := ts.MakePluginDir()
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
ts.Run("install plugin with pre-release only", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
2024-06-12 15:38:21 -04:00
|
|
|
SetArgs("plugins", "install", "--path", ts.BuildSimplePlugin("1.0.0-dev", ts.T()), "github.com/hashicorp/tester").
|
|
|
|
|
Assert(lib.MustSucceed(), lib.Grep("Successfully installed plugin", lib.GrepStdout))
|
2024-05-16 10:29:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts.Run("install same plugin with pre-release + metadata", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
2024-06-12 15:38:21 -04:00
|
|
|
SetArgs("plugins", "install", "--path", ts.BuildSimplePlugin("1.0.0-dev+metadata", ts.T()), "github.com/hashicorp/tester").
|
|
|
|
|
Assert(lib.MustSucceed(), lib.Grep("Successfully installed plugin", lib.GrepStdout))
|
2024-05-16 10:29:16 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts.Run("list plugins, should only report one plugin", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(tempPluginDir).
|
|
|
|
|
SetArgs("plugins", "installed").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustSucceed(),
|
|
|
|
|
lib.Grep("plugin-tester_v1.0.0-dev[^+]", lib.GrepStdout),
|
|
|
|
|
lib.Grep("plugin-tester_v1.0.0-dev\\+", lib.GrepStdout, lib.GrepInvert),
|
|
|
|
|
lib.LineCountCheck(1))
|
2024-05-16 10:29:16 -04:00
|
|
|
})
|
|
|
|
|
}
|
|
|
|
|
|
2024-06-12 15:38:21 -04:00
|
|
|
func (ts *PackerPluginTestSuite) TestInstallPluginPrerelease() {
|
|
|
|
|
pluginPath := ts.BuildSimplePlugin("1.0.1-alpha1", ts.T())
|
2024-05-03 15:41:36 -04:00
|
|
|
|
|
|
|
|
pluginDir, cleanup := ts.MakePluginDir()
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
ts.Run("try install plugin with alpha1 prerelease - should fail", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(pluginDir).
|
|
|
|
|
SetArgs("plugins", "install", "--path", pluginPath, "github.com/hashicorp/tester").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustFail(), lib.Grep("Packer can only install plugin releases with this command", lib.GrepStdout))
|
2024-05-03 15:41:36 -04:00
|
|
|
})
|
|
|
|
|
}
|
2024-05-07 16:26:20 -04:00
|
|
|
|
2024-06-12 15:38:21 -04:00
|
|
|
func (ts *PackerPluginTestSuite) TestRemoteInstallWithPluginsInstall() {
|
2024-06-12 15:54:03 -04:00
|
|
|
ts.SkipNoAcc()
|
|
|
|
|
|
2024-05-07 16:26:20 -04:00
|
|
|
pluginPath, cleanup := ts.MakePluginDir()
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
ts.Run("install latest version of a remote plugin with packer plugins install", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(pluginPath).
|
|
|
|
|
SetArgs("plugins", "install", "github.com/hashicorp/hashicups").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustSucceed())
|
2024-05-07 16:26:20 -04:00
|
|
|
})
|
2024-05-29 14:59:45 -04:00
|
|
|
}
|
2024-05-07 16:26:20 -04:00
|
|
|
|
2024-06-12 15:38:21 -04:00
|
|
|
func (ts *PackerPluginTestSuite) TestRemoteInstallOfPreReleasePlugin() {
|
2024-06-12 15:54:03 -04:00
|
|
|
ts.SkipNoAcc()
|
|
|
|
|
|
2024-05-29 14:59:45 -04:00
|
|
|
pluginPath, cleanup := ts.MakePluginDir()
|
|
|
|
|
defer cleanup()
|
|
|
|
|
|
|
|
|
|
ts.Run("try to init with a pre-release constraint - should fail", func() {
|
2024-05-07 16:26:20 -04:00
|
|
|
ts.PackerCommand().UsePluginDir(pluginPath).
|
2024-05-29 14:59:45 -04:00
|
|
|
SetArgs("init", "templates/pre-release_constraint.pkr.hcl").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustFail(),
|
|
|
|
|
lib.Grep("Invalid version constraint", lib.GrepStdout),
|
|
|
|
|
lib.Grep("Unsupported prerelease for constraint", lib.GrepStdout))
|
2024-05-29 14:59:45 -04:00
|
|
|
})
|
|
|
|
|
|
|
|
|
|
ts.Run("try to plugins install with a pre-release version - should fail", func() {
|
|
|
|
|
ts.PackerCommand().UsePluginDir(pluginPath).
|
|
|
|
|
SetArgs("plugin", "install", "github.com/hashicorp/hashicups", "1.0.2-dev").
|
2024-06-12 15:38:21 -04:00
|
|
|
Assert(lib.MustFail(),
|
|
|
|
|
lib.Grep("Unsupported prerelease for constraint", lib.GrepStdout))
|
2024-05-15 14:16:31 -04:00
|
|
|
})
|
|
|
|
|
}
|