Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

acctest: Gadgets for testing files #13231

Merged
merged 2 commits into from
Dec 16, 2024
Merged

acctest: Gadgets for testing files #13231

merged 2 commits into from
Dec 16, 2024

Conversation

lbajolet-hashicorp
Copy link
Contributor

This PR adds two new checkers to the acceptance testing library, related to files; those gadgets have been extracted from two open PRs:

  1. datasource: add file datasource #12397 : the original implementation of the FileExists checker, which ensures a file exists after a run, and optionally if it is a directory that we expect.
  2. [POC] Provisioner for SBOM #13171 : the FileGlob checker, which essentially does the same thing as FileExists, but with a glob expression instead, so that if the output filename isn't known with certainty beforehand, we can still check that a file exists that matches the expression we're looking for.

Some tests will create files and directories as part of the execution
path for Packer, and we need a way to check this, so this commit adds a
new file gadget to do those checks after a command executes.
When trying to validate that a particular file exists after a run of
Packer in a test suite, we can use the FileExists checker that we
provide as part of the gadgets we added for the acceptance test suites.

This approach works well, but only if we can extract a file name
reliably from the output of Packer core, or if we know what to look for
exactly beforehand. For other cases with a generated name however, the
FileExists checker is not enough, and therefore to accomodate for those
cases, we are introducing a new checker for this purpose: FileGlob.

FileGlob, as its name suggests, runs a glob expression on the
filesystem, and returns an error if no match was found regarding this
glob expression.
Copy link
Contributor

@mogrogan mogrogan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see it's not currently used and probably going to be in followings PRs

LGTM

@lbajolet-hashicorp
Copy link
Contributor Author

Yep, the plan is to have those merged already, so we don't have a dependency problem when/if we revisit those, as that code will already have been merged into main!

Thanks for the approval, merging this now!

@lbajolet-hashicorp lbajolet-hashicorp merged commit 11c238b into main Dec 16, 2024
12 checks passed
@lbajolet-hashicorp lbajolet-hashicorp deleted the test_file_gadgets branch December 16, 2024 18:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants