From 1345183a3093f2bbfb2176bb43d1fbcc5aa55bb3 Mon Sep 17 00:00:00 2001 From: Lucas Bajolet Date: Thu, 16 May 2024 10:29:16 -0400 Subject: [PATCH] packer_test: add test with both pre/meta in plugin To make sure we do scrub the metadata in the plugin name when installing it from a local binary, we add a test that does that installation with both alternatives: 1.0.0-dev and 1.0.0-dev+metadata, which should result in only one alternative being installed (the last one that succeeded). --- packer_test/install_test.go | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/packer_test/install_test.go b/packer_test/install_test.go index c3982e50e..a16c3e575 100644 --- a/packer_test/install_test.go +++ b/packer_test/install_test.go @@ -29,6 +29,32 @@ func (ts *PackerTestSuite) TestInstallPluginWithMetadata() { }) } +func (ts *PackerTestSuite) TestInstallPluginWithPath() { + tempPluginDir, cleanup := ts.MakePluginDir() + defer cleanup() + + ts.Run("install plugin with pre-release only", func() { + ts.PackerCommand().UsePluginDir(tempPluginDir). + SetArgs("plugins", "install", "--path", BuildSimplePlugin("1.0.0-dev", ts.T()), "github.com/hashicorp/tester"). + Assert(MustSucceed(), Grep("Successfully installed plugin", grepStdout)) + }) + + ts.Run("install same plugin with pre-release + metadata", func() { + ts.PackerCommand().UsePluginDir(tempPluginDir). + SetArgs("plugins", "install", "--path", BuildSimplePlugin("1.0.0-dev+metadata", ts.T()), "github.com/hashicorp/tester"). + Assert(MustSucceed(), Grep("Successfully installed plugin", grepStdout)) + }) + + ts.Run("list plugins, should only report one plugin", func() { + ts.PackerCommand().UsePluginDir(tempPluginDir). + SetArgs("plugins", "installed"). + Assert(MustSucceed(), + Grep("plugin-tester_v1.0.0-dev[^+]", grepStdout), + Grep("plugin-tester_v1.0.0-dev\\+", grepStdout, grepInvert), + LineCountCheck(1)) + }) +} + func (ts *PackerTestSuite) TestInstallPluginPrerelease() { pluginPath := BuildSimplePlugin("1.0.1-alpha1", ts.T())