Commit Graph
5 Commits
Author SHA1 Message Date
Lucas Bajolet 08b5011582 packer_test: add build customisation capabilities
When building a plugin, we may want some customisation capabilities
beyond changing the version/pre-release/metadata, and instead run
commands or change files on the filesystem.

To do so, we introduce functions under the BuildCustomisation type,
which have two responsabilities: changing the current state of the
plugin's directory, and cleaning up afterwards.
These customisations are passed as parameters to the BuildSimplePlugin
function, and are called one-by-one, deferring their cleanup after the
build process is finished.

A first implementation of such a customisation is added with this
commit, in order to change the version of a module that the plugin
depends on, which we'll use to change the version of the plugin SDK in
order to test how Packer behaves with different versions of the SDK for
a single plugin.
2024-08-06 11:11:03 -04:00
Lucas Bajolet a8dc5c9de9 packer_test: move some plugin functions to fs.go
As a small reorganisation attempt, this commit moves some file-system
oriented functions from plugin.go into its own file so they are more
logically grouped.
2024-08-06 11:09:43 -04:00
Lucas Bajolet 88611f9fe7 packer_test: move BuildSimplePlugin to plugin.go
In terms of organisation, we keep functions that interact with plugins
into its own file, therefore the function that build plugin versions
should really be in plugin.go, not in suite.go.
2024-08-06 11:09:31 -04:00
Lucas Bajolet d4ea91b478 packer_test: move compiledPlugins to attribute
The compiledPlugins map used to be a global variable, which can be
problematic as we move to independent test suites, since those test
suites run in the same process space, the global variable could point to
now deleted plugin versions/paths in separate suites, which would make
tests fail with random errors.

To avoid this, the map is now scoped to the test suite, and a new copy
is created lazily if used by the test suite.
2024-08-06 11:09:31 -04:00
Lucas Bajolet 47a4ad201b packer_test: make packer test suite modular
Having only one test suite for the whole of Packer makes it harder to
segregate between test types, and makes for a longer runtime as no tests
run in parallel by default.

This commit splits the packer_test suite into several components in
order to make extension easier.

First we have `lib`: this package embeds the core for running Packer
test suites. This ships facilities to build your own test suite for
Packer core, and exposes convenience methods and structures for building
plugins, packer core, and use it to run a test suite in a temporary
directory.

Then we have two separate test suites: one for plugins, and one for core
itself, the latter of which does not depend on plugins being compiled at
all.

This sets the stage for more specialised test suites in the future, each
of which can run in parallel on different parts of the code.
2024-08-06 11:09:31 -04:00