From 59bff3bdbe910907a5b9d6f0f09ad35c19d7655c Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Wed, 29 May 2024 14:59:45 -0400 Subject: [PATCH] packer_test: add remote install with pre-rel test Remotely installing plugins with a pre-release as part of the constraint is unsupported by Packer, and should error if that happens. This test makes sure that this gets treated as an error if that's the case, even before attempting to connect to the source. --- packer_test/install_test.go | 20 ++++++++++++++++--- .../templates/pre-release_constraint.pkr.hcl | 14 +++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) create mode 100644 packer_test/templates/pre-release_constraint.pkr.hcl diff --git a/packer_test/install_test.go b/packer_test/install_test.go index abc017dd3..1f039b51e 100644 --- a/packer_test/install_test.go +++ b/packer_test/install_test.go @@ -77,10 +77,24 @@ func (ts *PackerTestSuite) TestRemoteInstallWithPluginsInstall() { SetArgs("plugins", "install", "github.com/hashicorp/hashicups"). Assert(MustSucceed()) }) +} + +func (ts *PackerTestSuite) TestRemoteInstallOfPreReleasePlugin() { + pluginPath, cleanup := ts.MakePluginDir() + defer cleanup() + + ts.Run("try to init with a pre-release constraint - should fail", func() { + ts.PackerCommand().UsePluginDir(pluginPath). + SetArgs("init", "templates/pre-release_constraint.pkr.hcl"). + Assert(MustFail(), + Grep("Invalid version constraint", grepStdout), + Grep("Unsupported prerelease for constraint", grepStdout)) + }) - ts.Run("install dev version of a remote plugin with packer plugins install - must fail", func() { + ts.Run("try to plugins install with a pre-release version - should fail", func() { ts.PackerCommand().UsePluginDir(pluginPath). - SetArgs("plugins", "install", "github.com/hashicorp/hashicups", "v1.0.2-dev"). - Assert(MustFail(), Grep("Remote installation of pre-release plugin versions is unsupported.", grepStdout)) + SetArgs("plugin", "install", "github.com/hashicorp/hashicups", "1.0.2-dev"). + Assert(MustFail(), + Grep("Unsupported prerelease for constraint", grepStdout)) }) } diff --git a/packer_test/templates/pre-release_constraint.pkr.hcl b/packer_test/templates/pre-release_constraint.pkr.hcl new file mode 100644 index 000000000..c1e56b583 --- /dev/null +++ b/packer_test/templates/pre-release_constraint.pkr.hcl @@ -0,0 +1,14 @@ +packer { + required_plugins { + tester = { + source = "github.com/hashicorp/hashicups" + version = "= 1.0.2-dev" + } + } +} + +source "tester-dynamic" "test" {} + +build { + sources = ["tester-dynamic.test"] +}