-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
Add factory SPI for @TempDir
#2958
Conversation
6fe1a40
to
9b5da1b
Compare
2790fad
to
0201d9b
Compare
0201d9b
to
1d9ed4d
Compare
I like what you did with this PR. I wonder if passing I also see this PR as a good way to customize the behaviour of the temporary directory, such as including a space. We have a custom test directory provider that namespace the directory per-class/method, i.e. Finally, I think having a way to pass a global I hope this PR gets a bit more traction because it provides the last bit of customization that |
@lacasseio thanks for the feedback! I have to admit I've put this topic a bit aside lately, there are still some points to clarify and test coverage to improve... I'll get it finalized sooner or later 🙂
Indeed, the prefix doesn't seem so useful right now but I'd let the JUnit team judge what to do there.
I agree
That was exactly my idea, I've mentioned it in the middle of the description:
|
1d9ed4d
to
d1eb18a
Compare
This pull request has been automatically marked as stale because it has not had recent activity. Given the limited bandwidth of the team, it will be closed if no further activity occurs. If you intend to work on this pull request, please reopen the PR. Thank you for your contributions. |
d1eb18a
to
5d72429
Compare
14485f4
to
4ec2a79
Compare
Looking at implementing something similar as part of my current "TempDir" extension, I think it would be important to ensure |
Thanks for your feedback, @lacasseio! I need to refresh this topic and will check how to apply what you mentioned, as what the factory produces is already wrapped in a |
Great, I just noticed the example didn't close the FileSystem object and though about mentioning it for completeness. You are right that it won't change the current architecture. |
junit-jupiter-api/src/main/java/org/junit/jupiter/api/io/TempDirFactory.java
Outdated
Show resolved
Hide resolved
Team Decision: Check whether |
very good idea! This would be fantastic to have this available soon. |
junit-jupiter-api/src/main/java/org/junit/jupiter/api/io/TempDirFactory.java
Outdated
Show resolved
Hide resolved
4ec2a79
to
917de16
Compare
9223b97
to
40a297b
Compare
junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java
Outdated
Show resolved
Hide resolved
40a297b
to
c3f795b
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks very promising! Could you please add an integration test using jimfs or memoryfilesystem by introducing an additional test dependency?
junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java
Outdated
Show resolved
Hide resolved
junit-jupiter-engine/src/main/java/org/junit/jupiter/engine/extension/TempDirectory.java
Show resolved
Hide resolved
junit-jupiter-api/src/main/java/org/junit/jupiter/api/io/TempDirFactory.java
Show resolved
Hide resolved
...ngine/src/test/java/org/junit/jupiter/engine/extension/TempDirectoryPerDeclarationTests.java
Show resolved
Hide resolved
Thanks, @marcphilipp for all your feedback. I think only documentation and changelog are left, I plan to work on them in the evening and I'll also raise a separate PR for the global configuration property. |
4b54c0a
to
6fc70a9
Compare
6fc70a9
to
a2da46b
Compare
@marcphilipp I think I'm done with my changes, all the open points should be covered. Please, let me know if there is anything to adjust. |
Initial draft at scordio/junit5@2400_temp_dir_factory...scordio:junit5:gh-2400_temp_dir_factory_config_property. I'll raise a PR once this one is merged. |
@scordio Thanks a lot for the productive collaboration on this one! 🎉 |
TL;DR
This could solve:
@TempDir
#2088@TempDir
#2400@TempDir
via a configuration parameter #2889Overview
This adds a factory SPI to
@TempDir
, allowing to define how the temporary directory is created.My initial target was to support a custom file system (#2400), but it may also be a solution for the issues mentioned above.
The intended usage is to extend
TempDirFactory
and provide the class to the newfactory
attribute of@TempDir
:Example with Custom Parent Directory
Example with Custom File System
Using marschall/memoryfilesystem:
Using google/jimfs:
I would be happy to receive any feedback on the direction I have taken.
If this feature gets accepted, I would like to add a global configuration parameter like
junit.jupiter.tempdir.factory.default
in a separate PR.Open points
junit.jupiter.tempdir.scope=PER_CONTEXT
: the extension fails if a custom factory is setPath::toFile
call:To solve this, I catched the
UnsupportedOperationException
inTempDirectory.CloseablePath::resetPermissions
and ignored it (b284505). In support of this, thePath::toFile
javadoc mentions that the exception can be thrown if thePath
is not associated with the default file system, which can be a potential use case once this SPI is offered.I hereby agree to the terms of the JUnit Contributor License Agreement.
Definition of Done
@API
annotations