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

packer_test: make PluginTestDir a structure #13163

Merged
merged 1 commit into from
Sep 12, 2024

Conversation

lbajolet-hashicorp
Copy link
Contributor

In order for the creation of a temporary directory to install plugins into to be simpler to understand and use, we change how the directory is created, cleaned-up, and installs plugins into.

Now, instead of a tuple of a string (path) and a cleanup function, we return a structure that comprises the test suite, and the temporary directory, along with methods to handle those steps independently.

@lbajolet-hashicorp lbajolet-hashicorp marked this pull request as ready for review September 12, 2024 13:53
@lbajolet-hashicorp lbajolet-hashicorp requested a review from a team as a code owner September 12, 2024 13:53
@lbajolet-hashicorp lbajolet-hashicorp added the tech-debt Issues and pull requests related to addressing technical debt or improving the codebase label Sep 12, 2024
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

I left a few thoughts about plugin setting and cleanup but overall this looks good to me.

}
t.Fatalf("failed to prepare temporary plugin directory %q: %s", pluginTempDir, err)
t.Fatalf("failed to install plugins to temporary plugin directory %q: %s", ps.dirPath, err)
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it makes sense to use the accessor method ps.Dir() here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I believe it does yes! I'll have to double-check why I didn't use it in the first place, but I assume this would be safe to use

return ps.dirPath
}

func (ps *PluginDirSpec) Cleanup() {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it make sense to check that ps.dirPath is not an empty string?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah can't hurt

pluginDir, cleanup := ts.MakePluginDir()
defer cleanup()
pluginDir := ts.MakePluginDir()
defer pluginDir.Cleanup()
Copy link
Contributor

@nywilken nywilken Sep 12, 2024

Choose a reason for hiding this comment

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

My only nit here is that by making this a method on pluginDir as opposed to an anonymous returned function you can easily change the value of pluginDir.dirPath and remove some other directory.

Copy link
Contributor Author

@lbajolet-hashicorp lbajolet-hashicorp Sep 12, 2024

Choose a reason for hiding this comment

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

That's a valid concern, but I wouldn't think this is a huge problem since the dir argument is private, and therefore can only be changed from within the package it's defined in. Since tests are in a separate package, it's not really something you can accidentally change

Copy link
Contributor

Choose a reason for hiding this comment

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

Yeah that's fair. This concern is solely from this package as I saw a reference to ps.dirPath up above.

It is not a show stopper TBH honest. I called it out because we sometimes change the plugin directory for testing purposes.

packer_test/common/commands.go Show resolved Hide resolved
In order for the creation of a temporary directory to install plugins
into to be simpler to understand and use, we change how the directory is
created, cleaned-up, and installs plugins into.

Now, instead of a tuple of a string (path) and a cleanup function, we
return a structure that comprises the test suite, and the temporary
directory, along with methods to handle those steps independently.
Copy link
Contributor

@nywilken nywilken left a comment

Choose a reason for hiding this comment

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

👍🏽

@lbajolet-hashicorp lbajolet-hashicorp merged commit 3c44943 into main Sep 12, 2024
11 checks passed
@lbajolet-hashicorp lbajolet-hashicorp deleted the PluginTestDir_struct branch September 12, 2024 17:36
Copy link

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Oct 19, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
tech-debt Issues and pull requests related to addressing technical debt or improving the codebase
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants