Commit Graph
74 Commits
Author SHA1 Message Date
Lucas Bajolet 3661d97fc0 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-10 09:59:32 -04:00
Wilken Rivera c6388d4680 packer_test: Add tests for invalid plugin remove use cases 2024-06-10 09:59:32 -04:00
Wilken Rivera 1cace90289 packer_test: Add tests for valid plugin remove use cases 2024-06-10 09:59:32 -04:00
Lucas Bajolet 9f7098b230 packer_test: fix typo in error message for cleanup 2024-06-10 09:59:32 -04:00
Lucas Bajolet a2e08329a3 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-10 09:59:32 -04:00
Lucas Bajolet 2a414af35f 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-10 09:59:32 -04:00
Lucas Bajolet f77da46b3f 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-10 09:59:32 -04:00
Lucas Bajolet 7124cf81fa 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-10 09:59:32 -04:00
Lucas Bajolet 66e70a863d 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-10 09:59:32 -04:00
Lucas Bajolet a49da98350 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-10 09:59:32 -04:00
Lucas Bajolet 707e40e2e6 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-10 09:59:32 -04:00
Lucas Bajolet 901f31ad82 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-10 09:59:32 -04:00
Lucas Bajolet 7e0b27adaa packer_test: add init test on non-gh source URI 2024-06-10 09:59:32 -04:00
Lucas Bajolet 4e20956bae 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-10 09:59:32 -04:00
Lucas Bajolet 7943b8ce4e packer_test: add test for plugin remove with path 2024-06-10 09:59:32 -04:00
Lucas Bajolet 7f9276d439 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-10 09:59:32 -04:00
Lucas Bajolet 9ebc961374 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-10 09:59:32 -04:00
Lucas Bajolet 95b9a3c03e packer_test: migrate envvar test to pipe funcs 2024-06-10 09:59:32 -04:00
Lucas Bajolet ee9b4943da packer_test: remove local alias to ts.T() 2024-06-10 09:59:32 -04:00
Lucas Bajolet 2d114a044a packer_test: add functions for managing pipechecks
Instead of manually creating and populating a PipeChecker, we add
functions to do this.
2024-06-10 09:59:32 -04:00
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