Commit Graph
18569 Commits
Author SHA1 Message Date
Lucas Bajolet d175625869 packer_test: add Tee pipe gadget
When troubleshooting a pipeline for a test, it can be useful to print
the input out without necessarily preventing the pipeline to work.

The Tee gadget is exactly made for this purpose, the input of the Tee is
printed out through `t.Log`, and the input is forwarded to the next step
in the pipeline.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 830ac98e39 packer_test: add test for multiple plugin paths
When the PACKER_PLUGIN_PATH envvar is defined in the environment, Packer
uses it as the source of truth for the directories in which to look for
plugins to load.

Previously, we used to support multiple directories separated by the
OS-specific path separator (i.e. : on UNIX, ; on Windows).

Since this changed, and Packer returns an error to the user, we make
sure that this is well-documented and tested through this extra test.
2024-06-10 09:59:32 -04:00
Lucas Bajolet ae78d78736 packer_test: fix int compare checker
The IntCompare checker converts the input string into an int through
strconv.Atoi, which fails when the string isn't valid base 10. This
definition of "valid" also excludes whitespace, which occurs often
through piping gadgets, but shouldn't be a reason to fail that check, so
we trim the whitespace from the input string.
2024-06-10 09:59:32 -04:00
Wilken Rivera 2fe567d3d5 Move into a packer_test pkg for black-box testing 2024-06-10 09:59:32 -04:00
Lucas Bajolet 4a028ec735 test: add more tests for Packer core 2024-06-10 09:59:32 -04:00
Lucas Bajolet c04ac1cb1c test: fix name for the Grep gadget 2024-06-10 09:59:32 -04:00
Lucas Bajolet 646f1c46a1 test: allow custom Packer executable for acctests
When running the core acceptance tests we compile a temporary Packer
binary to run the tests with.

However in some cases we may want to run a test with another,
pre-compiled version of Packer.

For this use-case, we introduce an environment variable to change the
executable we're running tests with.
2024-06-10 09:59:32 -04:00
Lucas Bajolet a31507d575 test: fix packerCommand to use the right binary
When the Run command was introduced, despite the path to the temporary
packer binary being stored in the command, we were invoking Packer
through "packer", which would resolve whatever is in our PATH that
resolves first.

This was not the intention, so we fix this problem with this commit.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 4717955e2e test: add test for loading plugins with wd plugin
Add one more test to ensure we don't load plugins with the old naming
convention in the workdir for a packer run.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 055d46c59e test: add TempWorkdir function to test suite
When a test has to run in a working directory that is not the current
one we're running tests from, this may imply creating a temporary
directory, moving files into it, and then running the test from this
directory.

This can be a bit verbose to write all this code, so we abstract the
easy case through the TempWorkdir function, which works similarly to the
MakePluginDir function, by creating a temp dir, populating it with the
requested files, and returning a function to clean it up if needed.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 8f7efe0d57 test: add SetWD function to packerCommand
For some tests we may need Packer to run in another directory than the
one we're invoking the tests from, so we add a new function to the
packerCommand structure to change that.
2024-06-10 09:59:32 -04:00
Lucas Bajolet f48f4e786b test: add documentation on Checker interface 2024-06-10 09:59:32 -04:00
Lucas Bajolet 995b232464 test: make must succeed/fail gadgets functions
For consistency with other gadgets like Grep, we make the MustSucceed
and MustFail gadgets private with a function to return an instance of
it.
2024-06-10 09:59:32 -04:00
Lucas Bajolet afb4340539 test: rename empty/non-empty pipe testers
The name and semantics were a bit unclear with how they were previously
named, so this commit changes the name of those functions so it's
clearer they are expecting something, and what they're expecting.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 8e282d4100 test: reimplement Grep with a pipe
As we've introduced pipelines, we can use those to compose a version of
grep that doesn't have specific logic.

Besides, this refactor allows us to expose grep as a function with
variadic options, so this makes it more concise and clear to assert an
input with Grep.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 0f14b1d3fc test: add NoVerbose function on PackerCommand
By default PackerCommands are run with PACKER_LOG=1.
If for any reason we don't want that, we can remove it from the
environment so we only see the user-facing logs.
2024-06-10 09:59:32 -04:00
Lucas Bajolet c6e38690be test: add LineCount/Compare pipe/tester
As a common use case in console-oriented pipelines, we check that a
specific command returned a certain number of lines.
With the combination of LineCount and Compare, we can do exactly this.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 1278d50cd2 test: add empty/non-empty input checkers
When running a pipeline on a command's output, a simple check is making
sure the pipeline returned something empty or not.

This is the goal of those two implementations, basically either the
input is empty as expected, or it errors, and the reverse.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 7ab8511f1c test: add PipeGrep to grep an input 2024-06-10 09:59:32 -04:00
Lucas Bajolet b32ef74941 test: add pipe checker to test dir
The pipe checker is an attempt at replicating how one would go to write
commands on a CLI and piping them together, coupled with a `test`.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 75e4a47686 test: add generic gadget for testing
When writing tests, one may need to write a one-off checker for a
packer command that ran, without having to completely implement the
Checker interface.

This commit introduces a generic CustomChecker implementation (i.e. a
function) that can be one-off implemented by developers if their test
doesn't fit the existing gadgets, and the need is not generic/reusable
enough to justify introducing a new gadget for other users.
2024-06-10 09:59:32 -04:00
Lucas Bajolet 829b942206 test: add loading tests with legacy/valid plugins 2024-06-10 09:59:32 -04:00
Lucas Bajolet df9012dfbe test: add WriteFile convenience function
The WriteFile function creates a new file to the specified location, and
writes some contents to it.
2024-06-10 09:59:32 -04:00
Lucas Bajolet da41272df5 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-10 09:59:32 -04:00
Lucas Bajolet 54a1d28525 test: add inverse mode for Grep gadget
Since sometimes we want to check for matches, and sometimes we want to
check for a lack of match, we add one more option for the Grep gadget:
inverse.

This essentially replicates `grep -v`, and will succeed only if the
regex provided did NOT match on the requested streams.
2024-06-10 09:59:32 -04:00
Lucas Bajolet ad4631fb67 test: add installation tests to acceptance tests
This commit adds a few scenarios of plugin installations to the test
suite, in order to document and ensure we behave appropriately when
installing pre-releases/metadata.
2024-06-10 09:59:32 -04:00
Lucas Bajolet fe564c579b 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-10 09:59:32 -04:00
Lucas Bajolet 3d437ede99 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-10 09:59:32 -04:00
Lucas Bajolet fc056a4594 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-10 09:59:32 -04:00
Lucas Bajolet fde79cc667 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-10 09:59:32 -04:00