Commit Graph
18590 Commits
Author SHA1 Message Date
Lucas Bajolet 1345183a30 packer_test: add test with both pre/meta in plugin
To make sure we do scrub the metadata in the plugin name when installing
it from a local binary, we add a test that does that installation with
both alternatives: 1.0.0-dev and 1.0.0-dev+metadata, which should result
in only one alternative being installed (the last one that succeeded).
2024-06-07 14:38:20 -04:00
Lucas Bajolet 57d965411f packer_test: amend installation with meta test
The installation with a metadata part in the version for a plugin had
one test that relied on the plugin directories being populated with
packer plugins install --path.
This could change in the future, while the command should remain
functional, so we explicitely call it in the test instead of through the
function that creates/populates a temp plugin dir.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 6f299f5228 packer_test: add convenience func for line count
When building a pipeline to count the number of lines returned by
Packer, it can be a bit cumbersome to have to chain the calls to
MkPipeCheck to do that check, so we add one convenience function for the
simplest case: counting the number of lines on stdout, without any kind
of filtering.
2024-06-07 14:38:20 -04:00
Wilken Rivera 6bffafaec5 packer_test: Add tests for invalid plugin remove use cases 2024-06-07 14:38:20 -04:00
Wilken Rivera cde531107d packer_test: Add tests for valid plugin remove use cases 2024-06-07 14:38:20 -04:00
Lucas Bajolet a2431ce651 packer_test: fix typo in error message for cleanup 2024-06-07 14:38:20 -04:00
Lucas Bajolet 40a23400e9 packer_test: fix shasum file name for tests
When manually installing a plugin to the plugin directory, we compute a
SHA256SUM file from the plugin binary, and install it alongside it so we
can test the loading process for Packer.

In the introduction of the function, we added a check that if we were
running on Windows, we'd remove the extension of the sumfile's name
before writing it.

This is actually not necessary (and breaks the loading logic) as Packer
looks for the name of the plugin with extension, followed by
_SHA256SUM in order to compare the effective digest of the file to the
one written to this file.

Since this prevents the tests that use this function from succeeding in
a Windows environment, we remove this extra step.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 60d46ec146 packer_test: set TMP envvar for commands
Windows relies on the `TMP` (or alternatives) being set in the
environment in order to be able to create temporary directories and
files.

If this is not set, the `os.TempDir` function defaults on the windows
installation root directory (typically C:\Windows), leading to
permission errors when running Packer in the context of a test, as we're
installing plugins in a temporary directory.

To avoid this problem, we get the current setting from the test's
invocation environment, and forward it to the subcommand we execute for
our tests.
2024-06-07 14:38:20 -04:00
Lucas Bajolet d223d2117f packer_test: compile packer with .exe for Windows
Since on Windows extensions are mandatory in order to have something
executable, we compile Packer with a `.exe` suffix during tests, so we
can use the executable afterwards to run tests with.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 76dbc54dc8 packer_test: test build/validate with ignore flag
As we're introducing a --ignore-prerelease-plugins flag to both the
validate and build subcommands, we need to make sure they work as we
expect it to, so we add a test case for that.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 02da4b28e0 packer_test: add test for plugin with meta in name
Plugins with metadata information in their file name (i.e.
v1.0.0+metadata) should be ignored by Packer as they could introduce
ambiguity since the metadata is free-form, so we add that test to make
sure Packer behaves coherently.
2024-06-07 14:38:20 -04:00
Lucas Bajolet a976197bbf packer_test: test non-canonical plugin loading
If a plugin is installed with a non-canonical version in its name (e.g.
01.01.01), Packer rejects it with a message to that effect in stderr, so
we add a test for this use-case.
2024-06-07 14:38:20 -04:00
Lucas Bajolet f5ca6f0c4f packer_test: add func for "manual" plugin install
Installing a plugin manually to a directory is something needed for some
tests, especially those not relying on packer commands to install
plugins as they reject/correct the path/version.

Therefore this function is introduced so we have an easy way to install
a binary as a plugin somewhere on the provided plugin directory.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 2bdf006638 packer_test: fix ExpectedName to not clean version
The ExpectedInstalledName function used to compute the expected name of
a plugin binary for a given version, based on the invoker's environment,
used to cleanup the version string passed in parameter of the function,
which could be problematic.
Besides the logic applied would produce some invalid binary names as the
prerelease plugin would not have a `-` separator, so the resulting
plugin would be ignored, and we couldn't test metadata rejection with
this logic.

This commit therefore changes how the function works: the version string
is still parsed to account for manipulation errors, but the string is
left as-is for the final binary name.
2024-06-07 14:38:20 -04:00
Lucas Bajolet c856674a3e packer_test: add init test on non-gh source URI 2024-06-07 14:38:20 -04:00
Lucas Bajolet 0f0c059631 packer_test: don't error on empty pipeline
If for some reason we only want to run a test on either stream without
doing some manipulation beforehand, we can run a PipeChecker, however
these would error if no pipe gadget was defined, preventing this
use-case.

Instead of errorring then, this commit just ignores if no pipe is
present, as none is required for the test to run.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 706a59ecaf packer_test: add test for plugin remove with path 2024-06-07 14:38:20 -04:00
Lucas Bajolet 22711d176e packer_test: rename mini_plugin to plugin_tester
Since the tester plugin used for blackbox testing is called
packer-plugin-tester, we rename the directory it's stored in to
plugin_tester.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 99248cdcc2 packer_test: remove testing.T arg on Assert
Since the command object is created using the TestSuite as argument, we
can keep a reference to the test suite's scoped T() instance for the
command's lifecycle, and reuse it later during `Assert`, instead of
needing to pass it as argument when invoking the function.
2024-06-07 14:38:20 -04:00
Lucas Bajolet a701c3a14b packer_test: migrate envvar test to pipe funcs 2024-06-07 14:38:20 -04:00
Lucas Bajolet 5ee3044402 packer_test: remove local alias to ts.T() 2024-06-07 14:38:20 -04:00
Lucas Bajolet 8724e5a422 packer_test: add functions for managing pipechecks
Instead of manually creating and populating a PipeChecker, we add
functions to do this.
2024-06-07 14:38:20 -04:00
Lucas Bajolet 032114b3fc 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-07 14:38:20 -04:00
Lucas Bajolet 28bf784869 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-07 14:38:20 -04:00
Lucas Bajolet 2d293e6504 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-07 14:38:20 -04:00
Wilken Rivera 124a8d8d5d Move into a packer_test pkg for black-box testing 2024-06-07 14:38:20 -04:00
Lucas Bajolet 7fbef0f5a7 test: add more tests for Packer core 2024-06-07 14:38:20 -04:00
Lucas Bajolet 9c3f45f574 test: fix name for the Grep gadget 2024-06-07 14:38:20 -04:00
Lucas Bajolet 299a5af5c5 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-07 14:38:20 -04:00
Lucas Bajolet 1e126da916 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-07 14:38:20 -04:00
Lucas Bajolet 6f93eec99b 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-07 14:38:20 -04:00
Lucas Bajolet 91eaf93375 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-07 14:38:20 -04:00
Lucas Bajolet f00a49ddc9 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-07 14:38:20 -04:00
Lucas Bajolet c69ab08f9a test: add documentation on Checker interface 2024-06-07 14:38:20 -04:00
Lucas Bajolet 7aa9bac256 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-07 14:38:20 -04:00
Lucas Bajolet d15e32cacb 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-07 14:38:20 -04:00
Lucas Bajolet 0c2cfe3745 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-07 14:38:20 -04:00
Lucas Bajolet 0a5bdb5b78 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-07 14:38:20 -04:00
Lucas Bajolet b41c052c84 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-07 14:38:20 -04:00
Lucas Bajolet b31b8d3067 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-07 14:38:20 -04:00
Lucas Bajolet bd79b37aa7 test: add PipeGrep to grep an input 2024-06-07 14:38:20 -04:00
Lucas Bajolet c3e4c5cde4 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-07 14:38:20 -04:00
Lucas Bajolet 4d6d3cc81e 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-07 14:38:20 -04:00
Lucas Bajolet 96892fbca0 test: add loading tests with legacy/valid plugins 2024-06-07 14:38:20 -04:00
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 e7e8ad07d4 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-07 14:38:20 -04:00
Lucas Bajolet 464dbd34dd 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-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