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

propertySources attribute behavior in @MicronautTest is confusing #401

Open
2 of 4 tasks
asarkar opened this issue Mar 25, 2021 · 7 comments
Open
2 of 4 tasks

propertySources attribute behavior in @MicronautTest is confusing #401

asarkar opened this issue Mar 25, 2021 · 7 comments
Labels

Comments

@asarkar
Copy link

asarkar commented Mar 25, 2021

Task List

  • Steps to reproduce provided
  • Stacktrace (if present) provided
  • Example that reproduces the problem uploaded to Github
  • Full description of the issue provided (see below)

Actual Behaviour

Screen Shot 2021-03-25 at 4 37 54 PM

Given the project structure above, and @MicronautTest(propertySources = ["persistence.yml"]), ProjectRepositoryTest fails with the following exception:

No bean of type [io.micronaut.data.operations.PrimaryRepositoryOperations] exists in the test

Upon chatting on Gitter with @jameskleeh, turned out this is due to the fact that the file persistence.yml is searched for relative to the test class in the same package. No warning is logged when it's not found.

Tell us what should happen

propertySources should always be prefixed with either classpath or file. If a path starts with /, it's considered to be from the root of the classpath or file system, otherwise relative to the test class.

Better yet, deprecate propertySources in favor of micronaut-projects/micronaut-core#5176.

@jeffscottbrown
Copy link
Contributor

propertySources should always be prefixed with either classpath or file. If a path starts with /, it's considered to be from the root of the classpath or file system, otherwise relative to the test class.

If the value has to be prefixed with classpath or file I think that would be a breaking change and would remove the possibility for folks to use a relative path.

@jeffscottbrown
Copy link
Contributor

Sorry... I understand now. It would be a breaking change, but it wouldn't prevent folks from using a relative path.

@jameskleeh
Copy link
Contributor

jameskleeh commented Mar 26, 2021

I don't think this behavior should be removed or changed, however the documentation should instead show as an example the more common use case of classpath:x. I see the relative classpath feature as something pretty niche that most users would not be interested in.

Also we should throw an error, or at least a warning when the file is not found

@asarkar
Copy link
Author

asarkar commented Mar 26, 2021

@jameskleeh My suggestion is intended to make the behavior consistent and intuitive. May be some people don’t need relative classpath, but that’s what is happening today without the prefix. Wouldn’t it be nice if both prefixes work the same way?

@jameskleeh
Copy link
Contributor

Wouldn’t it be nice if both prefixes work the same way?

I'm not sure what you mean here. There are 2 prefixes, file and classpath and they are consistent in that there is no relative path. They both expect the full path either at the start of the file system or the start of the classpath.

If a path starts with /, it's considered to be from the root of the classpath or file system, otherwise relative to the test class.

Having classpath:foo.yml changed to be relative to the test class instead of absolute would be less intuitive compared to its current behavior imo

@asarkar
Copy link
Author

asarkar commented Mar 26, 2021

classpath:foo.yml changed to be relative to the test class instead of absolute would be less intuitive

This currently is absolute compared to foo.yml which is relative, hence the confusion. Making classpath:foo.yml relative would make it exactly the same behavior as you'd expect file:foo.yml to work.
Anyway, I'll leave it here.

@stale
Copy link

stale bot commented May 30, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants