1
0
mirror of https://github.com/hashicorp/packer.git synced 2026-02-06 06:45:07 +01:00
Files
packer/packer_test/plugin_tests/init_test.go
Lucas Bajolet 3c449430e1 packer_test: make PluginTestDir a structure
In order for the creation of a temporary directory to install plugins
into to be simpler to understand and use, we change how the directory is
created, cleaned-up, and installs plugins into.

Now, instead of a tuple of a string (path) and a cleanup function, we
return a structure that comprises the test suite, and the temporary
directory, along with methods to handle those steps independently.
2024-09-12 13:36:14 -04:00

81 lines
3.1 KiB
Go

package plugin_tests
import (
"github.com/hashicorp/packer/packer_test/common/check"
)
func (ts *PackerPluginTestSuite) TestPackerInitForce() {
ts.SkipNoAcc()
pluginPath := ts.MakePluginDir()
defer pluginPath.Cleanup()
ts.Run("installs any missing plugins", func() {
ts.PackerCommand().UsePluginDir(pluginPath).
SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl").
Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout))
})
ts.Run("reinstalls plugins matching version constraints", func() {
ts.PackerCommand().UsePluginDir(pluginPath).
SetArgs("init", "--force", "./templates/init/hashicups.pkr.hcl").
Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout))
})
}
func (ts *PackerPluginTestSuite) TestPackerInitUpgrade() {
ts.SkipNoAcc()
pluginPath := ts.MakePluginDir()
defer pluginPath.Cleanup()
cmd := ts.PackerCommand().UsePluginDir(pluginPath)
cmd.SetArgs("plugins", "install", "github.com/hashicorp/hashicups", "1.0.1")
cmd.SetAssertFatal()
cmd.Assert(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.1", check.GrepStdout))
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(check.MustSucceed(), check.Grep("Installed plugin github.com/hashicorp/hashicups v1.0.2", check.GrepStdout))
})
}
func (ts *PackerPluginTestSuite) TestPackerInitWithNonGithubSource() {
pluginPath := ts.MakePluginDir()
defer pluginPath.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(check.MustFail(), check.Grep(`doesn't appear to be a valid "github.com" source address`, check.GrepStdout))
})
ts.Run("manually install plugin to the expected source", func() {
ts.PackerCommand().UsePluginDir(pluginPath).
SetArgs("plugins", "install", "--path", ts.GetPluginPath(ts.T(), "1.0.10"), "hubgit.com/hashicorp/tester").
Assert(check.MustSucceed(), check.Grep("packer-plugin-tester_v1.0.10", check.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(check.MustSucceed(),
check.MkPipeCheck("no output in stdout").SetTester(check.ExpectEmptyInput()).SetStream(check.OnlyStdout))
})
}
func (ts *PackerPluginTestSuite) TestPackerInitWithMixedVersions() {
ts.SkipNoAcc()
pluginPath := ts.MakePluginDir()
defer pluginPath.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(check.MustFail(),
check.Grep("binary reported a pre-release version of 10.7.3-dev", check.GrepStdout))
})
}