mirror of
https://github.com/apple/pkl.git
synced 2026-01-11 22:30:54 +01:00
Allow to Mock Resource in testing #308
Reference in New Issue
Block a user
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Originally created by @lucsoft on GitHub (May 5, 2025).
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
@StefMa commented on GitHub (May 5, 2025):
You might wanna check this discussion that provides a solution: https://github.com/apple/pkl/discussions/1032
@lucsoft commented on GitHub (May 6, 2025):
@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
@bioball commented on GitHub (May 7, 2025):
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 commandFOO=1 pkl test