packer_test: add test with config.json/components

Since legacy config files may declare single plugin components, we need
to warn that they're not supported anymore.
This is in process of being PR'd into main, but to ensure the config
works as intended and we do get the error, we add some tests for that.
This commit is contained in:
Lucas Bajolet 2024-05-29 10:52:24 -04:00 committed by Lucas Bajolet
parent 1d65ad676f
commit 8402e00222
2 changed files with 35 additions and 0 deletions

View file

@ -209,3 +209,31 @@ func (ts *PackerTestSuite) TestLoadWithOnlyReleaseFlag() {
})
}
}
func (ts *PackerTestSuite) TestWithLegacyConfigAndComponents() {
pluginDir, cleanup := ts.MakePluginDir("1.0.0")
defer cleanup()
workdir, cleanup := TempWorkdir(ts.T(), "./sample_config.json", "./templates/simple.json", "./templates/simple.pkr.hcl")
defer cleanup()
for _, cmd := range []string{"validate", "build"} {
ts.Run(fmt.Sprintf("%s simple JSON template with config.json and components defined", cmd), func() {
ts.PackerCommand().UsePluginDir(pluginDir).SetWD(workdir).
SetArgs(cmd, "simple.json").
AddEnv("PACKER_CONFIG", filepath.Join(workdir, "sample_config.json")).
Assert(MustFail(),
Grep("Your configuration file describes some legacy components", grepStderr),
Grep("packer-provisioner-super-shell", grepStderr))
})
ts.Run(fmt.Sprintf("%s simple HCL2 template with config.json and components defined", cmd), func() {
ts.PackerCommand().UsePluginDir(pluginDir).SetWD(workdir).
SetArgs(cmd, "simple.pkr.hcl").
AddEnv("PACKER_CONFIG", filepath.Join(workdir, "sample_config.json")).
Assert(MustFail(),
Grep("Your configuration file describes some legacy components", grepStderr),
Grep("packer-provisioner-super-shell", grepStderr))
})
}
}

View file

@ -0,0 +1,7 @@
{
"disable_checkpoint": true,
"disable_checkpoint_signature": true,
"provisioners": {
"super-shell": "packer-provisioner-super-shell"
}
}