mirror of
https://github.com/hashicorp/packer.git
synced 2026-04-23 15:18:40 -04:00
packer_test: Add tests for valid plugin remove use cases
This commit is contained in:
parent
9f7098b230
commit
1cace90289
2 changed files with 118 additions and 43 deletions
|
|
@ -1,9 +1,5 @@
|
|||
package packer_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (ts *PackerTestSuite) TestInstallPluginWithMetadata() {
|
||||
tempPluginDir, cleanup := ts.MakePluginDir("1.0.0+metadata")
|
||||
defer cleanup()
|
||||
|
|
@ -57,45 +53,6 @@ func (ts *PackerTestSuite) TestRemoteInstallWithPluginsInstall() {
|
|||
})
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestRemovePluginWithLocalPath() {
|
||||
pluginPath, cleanup := ts.MakePluginDir("1.0.9", "1.0.10")
|
||||
defer cleanup()
|
||||
|
||||
// Get installed plugins
|
||||
cmd := ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "installed")
|
||||
cmd.Assert(MustSucceed())
|
||||
if ts.T().Failed() {
|
||||
return
|
||||
}
|
||||
|
||||
plugins, _, _ := cmd.Run()
|
||||
pluginList := strings.Split(strings.TrimSpace(plugins), "\n")
|
||||
if len(pluginList) != 2 {
|
||||
ts.T().Fatalf("Not the expected installed plugins: %v; expected 2", pluginList)
|
||||
}
|
||||
|
||||
ts.Run("remove one plugin version with its local path", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "remove", pluginList[0]).
|
||||
Assert(MustSucceed(), Grep("packer-plugin-tester_v1.0.9", grepStdout))
|
||||
})
|
||||
ts.Run("ensure one plugin remaining only", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "installed").
|
||||
Assert(
|
||||
MustSucceed(),
|
||||
Grep("packer-plugin-tester_v1.0.10", grepStdout),
|
||||
Grep("packer-plugin-tester_v1.0.9", grepInvert, grepStdout),
|
||||
)
|
||||
})
|
||||
ts.Run("remove plugin with version", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "remove", "github.com/hashicorp/tester", "1.0.10").
|
||||
Assert(MustSucceed(), Grep("packer-plugin-tester_v1.0.10", grepStdout))
|
||||
})
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestInitWithNonGithubSource() {
|
||||
pluginPath, cleanup := ts.MakePluginDir()
|
||||
defer cleanup()
|
||||
|
|
|
|||
118
packer_test/plugins_remove_test.go
Normal file
118
packer_test/plugins_remove_test.go
Normal file
|
|
@ -0,0 +1,118 @@
|
|||
package packer_test
|
||||
|
||||
import (
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (ts *PackerTestSuite) TestPluginsRemoveWithSourceAddress() {
|
||||
pluginPath, cleanup := ts.MakePluginDir("1.0.9", "1.0.10", "2.0.0")
|
||||
defer cleanup()
|
||||
|
||||
// Get installed plugins
|
||||
if n := InstalledPlugins(ts, pluginPath); len(n) != 3 {
|
||||
ts.T().Fatalf("Expected there to be 3 installed plugins but we got %v", n)
|
||||
}
|
||||
|
||||
ts.Run("plugins remove with source address removes all installed plugin versions", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "remove", "github.com/hashicorp/tester").
|
||||
Assert(MustSucceed(),
|
||||
Grep("packer-plugin-tester_v1.0.9", grepStdout),
|
||||
Grep("packer-plugin-tester_v1.0.10", grepStdout),
|
||||
Grep("packer-plugin-tester_v2.0.0", grepStdout),
|
||||
)
|
||||
})
|
||||
|
||||
// Get installed plugins after removal
|
||||
if n := InstalledPlugins(ts, pluginPath); len(n) != 0 {
|
||||
ts.T().Fatalf("Expected there to be 0 installed plugins but we got %v", n)
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestPluginsRemoveWithSourceAddressAndVersion() {
|
||||
pluginPath, cleanup := ts.MakePluginDir("1.0.9", "1.0.10", "2.0.0")
|
||||
defer cleanup()
|
||||
|
||||
// Get installed plugins
|
||||
if n := InstalledPlugins(ts, pluginPath); len(n) != 3 {
|
||||
ts.T().Fatalf("Expected there to be 3 installed plugins but we got %v", n)
|
||||
}
|
||||
|
||||
ts.Run("plugins remove with source address and version removes only the versioned plugin", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "remove", "github.com/hashicorp/tester", ">= 2.0.0").
|
||||
Assert(MustSucceed(), Grep("packer-plugin-tester_v2.0.0", grepStdout))
|
||||
})
|
||||
|
||||
ts.Run("plugins installed after single plugins remove outputs remaining installed plugins", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "installed").
|
||||
Assert(
|
||||
MustSucceed(),
|
||||
Grep("packer-plugin-tester_v1.0.9", grepStdout),
|
||||
Grep("packer-plugin-tester_v1.0.10", grepStdout),
|
||||
Grep("packer-plugin-tester_v2.0.0", grepInvert, grepStdout),
|
||||
)
|
||||
})
|
||||
|
||||
// Get installed plugins after removal
|
||||
if n := InstalledPlugins(ts, pluginPath); len(n) != 2 {
|
||||
ts.T().Fatalf("Expected there to be 2 installed plugins but we got %v", n)
|
||||
}
|
||||
}
|
||||
|
||||
func (ts *PackerTestSuite) TestPluginsRemoveWithLocalPath() {
|
||||
pluginPath, cleanup := ts.MakePluginDir("1.0.9", "1.0.10")
|
||||
defer cleanup()
|
||||
|
||||
// Get installed plugins
|
||||
plugins := InstalledPlugins(ts, pluginPath)
|
||||
if len(plugins) != 2 {
|
||||
ts.T().Fatalf("Expected there to be 2 installed plugins but we got %v", len(plugins))
|
||||
}
|
||||
|
||||
ts.Run("plugins remove with a local path removes only the specified plugin", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "remove", plugins[0]).
|
||||
Assert(
|
||||
MustSucceed(),
|
||||
Grep("packer-plugin-tester_v1.0.9", grepStdout),
|
||||
Grep("packer-plugin-tester_v1.0.10", grepInvert, grepStdout),
|
||||
)
|
||||
})
|
||||
ts.Run("plugins installed after calling plugins remove outputs remaining installed plugins", func() {
|
||||
ts.PackerCommand().UsePluginDir(pluginPath).
|
||||
SetArgs("plugins", "installed").
|
||||
Assert(
|
||||
MustSucceed(),
|
||||
Grep("packer-plugin-tester_v1.0.10", grepStdout),
|
||||
Grep("packer-plugin-tester_v1.0.9", grepInvert, grepStdout),
|
||||
)
|
||||
})
|
||||
|
||||
// Get installed plugins after removal
|
||||
if n := InstalledPlugins(ts, pluginPath); len(n) != 1 {
|
||||
ts.T().Fatalf("Expected there to be 1 installed plugins but we got %v", n)
|
||||
}
|
||||
}
|
||||
|
||||
func InstalledPlugins(ts *PackerTestSuite, dir string) []string {
|
||||
ts.T().Helper()
|
||||
|
||||
cmd := ts.PackerCommand().UsePluginDir(dir).
|
||||
SetArgs("plugins", "installed")
|
||||
cmd.Assert(MustSucceed())
|
||||
if ts.T().Failed() {
|
||||
ts.T().Fatalf("Failed to execute plugin installed for %q", dir)
|
||||
}
|
||||
|
||||
out, _, _ := cmd.Run()
|
||||
// Output will be split on '\n' after trimming all other white space
|
||||
out = strings.TrimSpace(out)
|
||||
plugins := strings.Fields(out)
|
||||
n := len(plugins)
|
||||
if n == 0 {
|
||||
return nil
|
||||
}
|
||||
return plugins
|
||||
}
|
||||
Loading…
Reference in a new issue