Commit Graph
12 Commits
Author SHA1 Message Date
Lucas Bajolet 1b643125c0 test: add WriteFile convenience function
The WriteFile function creates a new file to the specified location, and
writes some contents to it.
2024-06-07 14:38:20 -04:00
Lucas Bajolet c1a0002a10 test: add ExpectedInstalledName function
The ExpectedInstalledName function returns the expected full name of a
plugin binary after it's installed.

This is used for tests that need to copy the binary to some place before
they can run commands and ensure the logic for managing plugins conforms
to the docs/specs.
2024-06-07 14:38:20 -04:00
Lucas Bajolet a62dab8ae7 test: error on plugin loading if not compiled
When building the temporary plugin directory for a test, we didn't check
that the LoadPluginVersion call succeeded and returned a path, which
may cause errors down the line when attempting to install the plugin.

To avoid this problem, we do the check at that time, and immediately
fail if a plugin isn't found.
2024-06-07 14:38:20 -04:00
Lucas Bajolet aa455014f5 test: compile plugins on call to MakePluginDir
MakePluginDir used to only load plugins that were precompiled at the
start of the tests, but now when invoked with any list of plugins, this
will attempt to compile plugins one-by-one, so we don't need to modify
the tests in several places when running tests.

There's still value in compiling the plugins in advance though: as they
run in parallel, they all get compiled at once, so we shave off a few
seconds from the test run.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 848188d705 test: only build plugins if not already done
Calling BuildSimplePlugin for a particular version used to mean that we
had to build it regardless of if it was previously done or not.
This commit changes this behaviour so that it checks first that the
plugin wasn't pre-compiled, and if it was, we immediately return.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 430f2d15cd test: make PanicCheck an implicit Assert gadget
When running "Assert" on a packer command, we run a series of checkers
on the command's output/error code, which provoke test failures if they
fail.

Panic checking used to be part of Run, but in the end this would make
more sense to have that as a regular checker if asserting the results of
a packer command, so that's the approach we adopt with this commit.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 03bb62cd99 test: simplify plugin build function
The NewPluginBuildConfig function was essentially a shortcut to
`version.Must(version.NewSemver(v))', which is superfluous at this
point, we can directly pass the version string to BuildSimplePlugin and
let that function do the creation/check.
2024-06-07 14:38:20 -04:00
Lucas Bajolet fbb8cac698 test: remove unnecessary testing.T arg
Since the MakePluginDir function takes the TestSuite as receiver, we
don't need to additionally pass in a reference to testing.T, since the
test suite already contains one instance, and offers a function to get
it from.
2024-06-07 14:38:20 -04:00
Lucas Bajolet d1b431ae27 test: remove PluginVersionConfig struct
The PluginVersionConfig structure was first introduced when building
the early versions of the test package, but it was an unnecessary
abstraction over go-version.Version.

So we remove that structure definition, and instead we directly use the
version for building those temporary plugins.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 6ab7f670ad test: add CopyFile convenience function to pkg
The CopyFile function is essentially a go recreation of the `cp'
command, which copies one file from a source path to a destination
directory or file.

This can be used for several tests in the future.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 0e2695d3e2 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-07 14:38:20 -04:00
Lucas Bajolet ef50474a9f test: add base suite for core acceptance testing
Acceptance testing, i.e. running Packer core commands in a controlled
environment and ensuring the behaviour is consistent to what we
expect/document, is not something we have a robust and usable framework
for at the moment.

This commit is a proposal for a base testing framework of the sort, that
is meant to be shipped with packer core, and which will eventually host
most of the tests we currently do in command where we mock an
environment.
2024-06-07 14:38:20 -04:00