Mocking Resources in Tests #1032
Unanswered
rohan-datar
asked this question in
Q&A
Replies: 1 comment 1 reply
-
I got around this by using an import expression rather than a clause in // foo.pkl
resources = import("resources.pkl")
... // foo_test.pkl
import "foo.pkl" as foo
import "resources.pkl" as r
local fooWithMockedResources = (foo) {
resources = new r {
envValValidated = 20
}
}
examples {
["foo"] {
fooWithMockedResources.output.text
}
} However this exposes |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I have a module that reads a bunch of resources from the environment and performs some validation on them. This module is imported by other modules that use the resources as needed. When writing tests for my modules, I'd like to mock the values provided by the resource module. As far as I can tell, Pkl does not have a simple way to do this. Any suggestions on how I can achieve this?
I'd like to be able to write an example test like this:
If I run this test in an environment where
ENV_VAL
is not set or has an invalid value, it will fail, it will also fail ifENV_VAL
changes even if my module code is unchanged. Ideally I'd be able to set the value infoo_test.pkl
so I don't have to worry about it, but it's unclear how I would do that in this case.Beta Was this translation helpful? Give feedback.
All reactions