Files
Packer-Cn/test/loading_test.go
T
Lucas Bajolet 6a8e888b0d test: return cleanup function for temp plugin dirs
When creating a temporary plugin directory, we had to build a cleanup
function, which could be as simple as `os.Mkdirall` without any kind of
warning that a directory failed to be cleaned-up, or we could do some
more work in order to report the possible issues around this.

That code would quickly be redundant, as there's not a ton of
variability in the code that can be written for this step, so we
abstract it through a pre-defined cancellation function which can be
safely defer invoked.
2024-06-10 09:59:32 -04:00

49 lines
1.2 KiB
Go

package test
import (
"testing"
)
func (ts *PackerTestSuite) TestLoadingOrder() {
t := ts.T()
pluginDir, cleanup := ts.MakePluginDir(t, "1.0.9", "1.0.10")
defer cleanup()
for _, command := range []string{"build", "validate"} {
tests := []struct {
name string
templatePath string
grepStr string
}{
{
"HCL2 " + command + " - With required_plugins, 1.0.10 is the most recent and should load",
"./templates/simple.pkr.hcl",
"packer-plugin-tester_v1\\.0\\.10[^\n]+ plugin:",
},
{
"JSON " + command + " - No required_plugins, 1.0.10 is the most recent and should load",
"./templates/simple.json",
"packer-plugin-tester_v1\\.0\\.10[^\n]+ plugin:",
},
{
"HCL2 " + command + " - With required_plugins, 1.0.9 is pinned, so 1.0.9 should be used",
"./templates/pin_1.0.9.pkr.hcl",
"packer-plugin-tester_v1\\.0\\.9[^\n]+ plugin:",
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
ts.PackerCommand().
SetArgs(command, tt.templatePath).
AddEnv("PACKER_PLUGIN_PATH", pluginDir).
Assert(t, MustSucceed{}, Grep{
streams: BothStreams,
expect: tt.grepStr,
})
})
}
}
}