Skip to content

Commit

Permalink
Fix traceback when task or matrix has no env.
Browse files Browse the repository at this point in the history
Signed-off-by: Chris Evich <cevich@redhat.com>
  • Loading branch information
cevich committed Mar 26, 2021
1 parent 1a55eaa commit 8da1985
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 1 deletion.
2 changes: 1 addition & 1 deletion cirrus-ci_env/cirrus-ci_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ def unroll_matrix(self, name_default: str, alias_default: str,
f" or matrix definition: {item}"
f" for task definition: {task}")
# default values for the rendered task - not mutable, needs a copy.
matrix_task = dict(alias=alias_default, env=task.get("env").copy())
matrix_task = dict(alias=alias_default, env=task.get("env", dict()).copy())
matrix_name = item.get("name", name_default)
CirrusCfg._working = matrix_name

Expand Down
29 changes: 29 additions & 0 deletions cirrus-ci_env/test/test_cirrus-ci_env.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,19 @@ def test_simple_render(self):
result = self.CCfg(config).tasks
self.assertDictEqual(result, expected)

def test_noenv_render(self):
"""Verify rendering of task w/o local env. vars."""
task = dict(something="ignored")
config = dict(env=self.global_env, test_task=task)
expected = {
"test": {
"alias": "test",
"env": {}
}
}
result = self.CCfg(config).tasks
self.assertDictEqual(result, expected)

def test_simple_matrix(self):
"""Verify unrolling of a simple matrix containing two tasks."""
matrix1 = dict(name="test_matrix1", env=dict(item="${foo}bar"))
Expand Down Expand Up @@ -194,6 +207,22 @@ def test_simple_matrix(self):
self.assertDictEqual(expected[task_name], result[task_name])
self.assertDictEqual(result, expected)

def test_noenv_matrix(self):
"""Verify unrolling of single matrix w/o env. vars."""
matrix = dict(name="test_matrix")
task = dict(env=dict(something="untouched"), matrix=[matrix])
config = dict(env=self.global_env, test_task=task)
expected = {
"test_matrix": {
"alias": "test",
"env": {
"something": "untouched"
}
}
}
result = self.CCfg(config).tasks
self.assertDictEqual(result, expected)

def test_rendered_name_matrix(self):
"""Verify env. values may be used in matrix names with spaces."""
test_foobar = dict(env=dict(item="$foo$bar", unique="item"))
Expand Down

0 comments on commit 8da1985

Please sign in to comment.