pkl
pkl copied to clipboard
Allow to Mock Resource in testing
i would to mock read's like read("env:MY_CUSTOM_ENV") for a specific test case/(or test file at least)
Context: I have a Global Config object which reads env variables and i would like to define them in a test file.
Mocking Resources could be a way i think
You might wanna check this discussion that provides a solution: https://github.com/apple/pkl/discussions/1032
@StefMa i don't think that it actually solves my issue as this is local mocking and not global
i have a global config file, and i want to test a specific file which imports the config file i don't think i can currently mock the response of that "internal" import of that config file
I have the same advice that I did in the discussion that @StefMa linked to.
The best way to stub out that value is to expose it as an API, and replace it in your tests.
If you really want to, you can set env vars when running pkl test, e.g. run shell command FOO=1 pkl test