-
Notifications
You must be signed in to change notification settings - Fork 75
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
How to get a dependency service without starting a service? #194
Comments
@timur87 if I'm understanding you correctly, the best way to do this for testing is implement a mock version of the dependency service. Then you can use the testutils Would that suffice for your needs? |
@cprice404, thanks for the prompt answer again. What I'm asking might be a really basic question :) What I need is an actual instance of the dependency service. Something similar to (services/get-service this :MyProtocol) except without "this" parameter here so that I can call it outside of the start or init functions. |
@timur87 so this is in test code? With a TK app booted up? Or are you saying you're trying to write tests that test the service without booting a TK app? |
It's not a test code, I'm working in repl interactively and want to see if the service really does its job. It's a persistency service, and I want to see if the things are really added. For that I need to get an instance of a dependency service, i.e., persistency service. All of this is happening in CIDER nREPL :) |
Ah, OK, so you do have a full instance of the TK app running then. There's probably a hacky way to do it; you can use this variable: https://github.com/puppetlabs/trapperkeeper/blob/master/src/puppetlabs/trapperkeeper/core.clj#L122 to get a reference to the https://github.com/puppetlabs/trapperkeeper/blob/master/src/puppetlabs/trapperkeeper/app.clj#L5 I hate having that global variable in the code but this is what I put it in there for, as a last resort for this kind of situation. For a dev environment it'd probably be preferable to boot the tk-app explicitly in the repl and hold on to your own variable with a reference to the app, and access it through that, if possible. |
@timur87 did that work for your use case? |
Yes it did thanks for the prompt answers as always! |
Hi,
Is there a way to get the instance of a dependency service without starting the service? I want to test certain functions using a dependency service but without actually starting the dependent service.
Regards,
Timur
The text was updated successfully, but these errors were encountered: