Skip to content

Commit

Permalink
packer_test: add remote install with pre-rel test
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
lbajolet-hashicorp committed Jun 10, 2024
1 parent 8d7a8f1 commit 6e45bf3
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
20 changes: 17 additions & 3 deletions packer_test/install_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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))
})
}
14 changes: 14 additions & 0 deletions packer_test/templates/pre-release_constraint.pkr.hcl
Original file line number Diff line number Diff line change
@@ -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"]
}

0 comments on commit 6e45bf3

Please sign in to comment.