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

Inject not working correctly with lambda and @Requries(env = ...) #1589

Open
andriy-dmytruk opened this issue Jan 31, 2023 · 2 comments
Open
Labels
info: workaround available A workaround is available for the issue

Comments

@andriy-dmytruk
Copy link
Contributor

Issue description

Inspect the following test:

@MicronautTest(environments = "my-env")
public class InjectRequiresEnvTest {
    @Inject
    MyClass myClass;

    @Requires(env = "my-env")
    @Singleton
    static class MyClass {}

    @Test
    void testWorks() {

    }
}

The test should pass since bean injection should be performed successfully. If the runtime is set to lambda:

micronaut {
    runtime("lambda_provided")
    ...
}

the test fails.

Reproduced in this branch: https://github.com/andriy-dmytruk/micronaut-function/tree/lambda

@sdelamo
Copy link
Contributor

sdelamo commented Feb 2, 2023

@sdelamo sdelamo added the info: workaround available A workaround is available for the issue label Feb 2, 2023
@andriy-dmytruk
Copy link
Contributor Author

I am not entirely sure I understand what the solution is. A workaround would be to use @Requires(property="my-test-prop") and then define it for the test class @Property(name = "my-test-prop"). This works and MyClass would only be available inside this particular test.

However, I still think that environments not working correctly for tests with lambda is an issue, although it is probably not very important.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info: workaround available A workaround is available for the issue
Projects
None yet
Development

No branches or pull requests

2 participants