Skip to content

Commit

Permalink
re-add the test
Browse files Browse the repository at this point in the history
  • Loading branch information
rebrowning committed Nov 1, 2023
1 parent 7b4d626 commit cd2d9f4
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions st2client/tests/unit/test_command_actionrun.py
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,65 @@ def test_correctly_process_inherit_env_when_no_parameters_set(self):
self.assertEqual(v1, env_params[k1])
self.assertEqual(v2, env_params[k2])

def test_correctly_process_inherit_env_when_parameters_set(self):
"""test_correctly_process_inherit_env_when_parameters_set
This tests that we still correctly pass through the environment variables
when --inherit-env is set and we run a job that has action parameters set
"""

runner = RunnerType()
runner.runner_parameters = {}

action = Action()
action.ref = "test.action"
action.parameters = {
"param_string": {"type": "string"},
"param_array": {"type": "array"},
"param_array_of_dicts": {"type": "array"},
}

subparser = mock.Mock()
command = ActionRunCommand(action, self, subparser, name="test")

p_string = "param_string"
p_array = "param_array"
p_ra_dicts = "param_array_of_dicts"
mockarg = mock.Mock()
mockarg.inherit_env = True
mockarg.auto_dict = True
mockarg.parameters = [
f"{p_string}=hoge",
f"{p_array}=foo,bar",
f"{p_ra_dicts}=foo:1,bar:2",
]

k1 = "key1"
v1 = "value1"
k2 = "key2"
v2 = "value2"

with mock.patch("os.environ.copy") as mockCopy:
mockCopy.return_value = {k1: v1, k2: v2}
param = command._get_action_parameters_from_args(
action=action, runner=runner, args=mockarg
)

self.assertIn("env", param)

env_params = param["env"]
self.assertIn(k1, env_params)
self.assertIn(k2, env_params)
self.assertEqual(v1, env_params[k1])
self.assertEqual(v2, env_params[k2])
self.assertIn(p_string, param)
self.assertEqual("hoge", param[p_string])
self.assertIn(p_array, param)
self.assertIn("foo", param[p_array])
self.assertIn("bar", param[p_array])
self.assertIn(p_ra_dicts, param)
self.assertDictEqual({"foo": "1", "bar": "2"}, param[p_ra_dicts][0])

def test_correctly_generate_empty_params_no_inherit_empty_parameters(self):
"""test_correctly_generate_empty_params_no_inherit_empty_parameters
Expand Down

0 comments on commit cd2d9f4

Please sign in to comment.