You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi, I am starting with bats and I love it. Now I have encountered a problem to test part of the functionality of my script.
My script parses some data, calls an api and depending on the response it continues or not the execution.
Would it be possible to predefine the value of a variable used in the script and not modify it?
Something like declare -r response="My fake response", a constant that works throughout the execution of the script within the test.
And then in my script, where I read the variable response I will always read "My fake response" and it does not change even if another value is assigned in the script to test.
I do not know if I have explained well. I hope someone has some idea how to do this.
The text was updated successfully, but these errors were encountered:
If I understand you correctly, you want to simulate responses, which sounds a lot like mocking. maybe you want to look into mocking libraries for Bats.
Anyway, your intended solution might have several issues:
Bash readonly variables trigger errors on writing, which is not what you want
Subshells will only inherit exported variables
Mocking every variable named response might have unintended consequences due to name collisions
Hi, I am starting with bats and I love it. Now I have encountered a problem to test part of the functionality of my script.
My script parses some data, calls an api and depending on the response it continues or not the execution.
Would it be possible to predefine the value of a variable used in the script and not modify it?
Something like
declare -r response="My fake response"
, a constant that works throughout the execution of the script within the test.And then in my script, where I read the variable
response
I will always read "My fake response" and it does not change even if another value is assigned in the script to test.I do not know if I have explained well. I hope someone has some idea how to do this.
The text was updated successfully, but these errors were encountered: