mirror of https://github.com/hashicorp/packer
These changes include a series of test cases for validating packer init
using the force and upgrade flag. Include in this test is a test case
for validating the plugin installation error when init encounters a
plugin whose reported version does not match the version within the
plugin name.
```
--- PASS: Test_PackerCoreSuite (18.66s)
--- PASS: Test_PackerCoreSuite/TestPackerInitForce (4.91s)
--- PASS: Test_PackerCoreSuite/TestPackerInitForce/installs_any_missing_plugins (2.76s)
--- PASS: Test_PackerCoreSuite/TestPackerInitForce/reinstalls_plugins_matching_version_constraints (2.14s)
--- PASS: Test_PackerCoreSuite/TestPackerInitUpgrade (3.70s)
--- PASS: Test_PackerCoreSuite/TestPackerInitUpgrade/upgrades_a_plugin_to_the_latest_matching_version_constraints (2.02s)
--- PASS: Test_PackerCoreSuite/TestPackerInitWithMixedVersions (1.96s)
--- PASS: Test_PackerCoreSuite/TestPackerInitWithMixedVersions/skips_the_plugin_installation_with_mixed_versions_before_exiting_with_an_error (1.96s)
--- PASS: Test_PackerCoreSuite/TestPackerInitWithNonGithubSource (1.22s)
--- PASS: Test_PackerCoreSuite/TestPackerInitWithNonGithubSource/try_installing_from_a_non-github_source,_should_fail (0.07s)
--- PASS: Test_PackerCoreSuite/TestPackerInitWithNonGithubSource/manually_install_plugin_to_the_expected_source (0.59s)
--- PASS: Test_PackerCoreSuite/TestPackerInitWithNonGithubSource/re-run_packer_init_on_same_template,_should_succeed_silently (0.55s)
```
pull/13032/head
parent
19594be808
commit
1d65ad676f
@ -0,0 +1,74 @@
|
||||
package packer_test
|
||||
|
||||
func (ts *PackerTestSuite) TestPackerInitForce() {
|
||||
pluginPath, cleanup := ts.MakePluginDir()
|
||||
defer cleanup()
|
||||
|
||||
ts.Run("installs any missing plugins", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl").
|
||||
Assert(MustSucceed(), Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", grepStdout))
|
||||
})
|
||||
|
||||
ts.Run("reinstalls plugins matching version constraints", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl").
|
||||
Assert(MustSucceed(), Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", grepStdout))
|
||||
})
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestPackerInitUpgrade() {
|
||||
pluginPath, cleanup := ts.MakePluginDir()
|
||||
defer cleanup()
|
||||
|
||||
cmd := ts.PackerCommand().UsePluginDir(pluginPath)
|
||||
cmd.SetArgs("plugins", "install", "github.com/hashicorp/hashicups", "1.0.1")
|
||||
cmd.Assert(MustSucceed(), Grep("Installed plugin github.com/hashicorp/hashicups v1.0.1", grepStdout))
|
||||
|
||||
_, _, err := cmd.Run()
|
||||
if err != nil {
|
||||
ts.T().Fatalf("packer plugins install failed to install previous version of hashicups: %q", err)
|
||||
}
|
||||
|
||||
ts.Run("upgrades a plugin to the latest matching version constraints", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("init", "--upgrade", "./templates/init/hashicups.pkr.hcl").
|
||||
Assert(MustSucceed(), Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", grepStdout))
|
||||
})
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestPackerInitWithNonGithubSource() {
|
||||
pluginPath, cleanup := ts.MakePluginDir()
|
||||
defer cleanup()
|
||||
|
||||
ts.Run("try installing from a non-github source, should fail", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("init", "./templates/init/non_gh.pkr.hcl").
|
||||
Assert(MustFail(), Grep(`doesn't appear to be a valid "github.com" source address`, grepStdout))
|
||||
})
|
||||
|
||||
ts.Run("manually install plugin to the expected source", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "install", "--path", BuildSimplePlugin("1.0.10", ts.T()), "hubgit.com/hashicorp/tester").
|
||||
Assert(MustSucceed(), Grep("packer-plugin-tester_v1.0.10", grepStdout))
|
||||
})
|
||||
|
||||
ts.Run("re-run packer init on same template, should succeed silently", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("init", "./templates/init/non_gh.pkr.hcl").
|
||||
Assert(MustSucceed(),
|
||||
MkPipeCheck("no output in stdout").SetTester(ExpectEmptyInput()).SetStream(OnlyStdout))
|
||||
})
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestPackerInitWithMixedVersions() {
|
||||
pluginPath, cleanup := ts.MakePluginDir()
|
||||
defer cleanup()
|
||||
|
||||
ts.Run("skips the plugin installation with mixed versions before exiting with an error", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("init", "./templates/init/mixed_versions.pkr.hcl").
|
||||
Assert(MustFail(),
|
||||
Grep("binary reported a pre-release version of 10.7.3-dev", grepStdout))
|
||||
})
|
||||
}
|
||||
@ -0,0 +1,9 @@
|
||||
packer {
|
||||
required_plugins {
|
||||
tester = {
|
||||
source = "github.com/hashicorp/hashicups"
|
||||
version = ">= 1.0.2"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,9 @@
|
||||
packer {
|
||||
required_plugins {
|
||||
tester = {
|
||||
source = "github.com/mondoohq/cnspec"
|
||||
version = "= 10.7.3" # plugin describe reports 10.7.x-dev so init must fail
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in new issue