Skip to content

Commit

Permalink
get latest result artifact value not first
Browse files Browse the repository at this point in the history
  • Loading branch information
itewk committed Aug 2, 2021
1 parent c213ebc commit 9143e21
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 8 deletions.
2 changes: 1 addition & 1 deletion src/ploigos_step_runner/results/workflow_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def get_artifact_value(
"""

value = None
for step_result in self.workflow_list:
for step_result in reversed(self.workflow_list):
if ( \
(not step_name or step_result.step_name == step_name) and \
(not sub_step_name or step_result.sub_step_name == sub_step_name) and \
Expand Down
8 changes: 4 additions & 4 deletions tests/results/test_workflow_result.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def setup_test():
step_result1.add_evidence('evidence3', 'value3')
step_result1.add_evidence('evidence4', False)
step_result1.add_evidence('same-evidence-all-env-and-no-env', 'result1')


step_result2 = StepResult('step2', 'sub2', 'implementer2')
step_result2.add_artifact('artifact1', True)
Expand Down Expand Up @@ -103,7 +103,7 @@ class TestStepWorkflowResultTest(BaseTestCase):
def test_get_artifact_value_without_step(self):
wfr = setup_test()

expected_artifact = 'value1'
expected_artifact = True
self.assertEqual(
expected_artifact,
wfr.get_artifact_value(artifact='artifact1')
Expand Down Expand Up @@ -237,7 +237,7 @@ def test_get_artifact_value_in_step_executed_in_different_environments_and_no_en
wfr.get_artifact_value(
artifact='same-artifact-all-env-and-no-env'
),
'result1'
'result4-test-env'
)

self.assertEqual(
Expand Down Expand Up @@ -289,7 +289,7 @@ def test_get_artifact_value_in_step_executed_in_different_environments(self):
wfr.get_artifact_value(
artifact='same-artifact-diff-env'
),
'value-dev-env'
'value-test-env'
)

self.assertEqual(
Expand Down
34 changes: 31 additions & 3 deletions tests/test_step_implementer.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,17 @@ def _setup_get_value_with_env_test(self, test_dir, environment):

workflow_result = WorkflowResult()

step_result_no_evn = StepResult(
step_name='foo',
sub_step_name='Mock',
sub_step_implementer_name='Mock'
)
step_result_no_evn.add_artifact(
name='container-image-tag',
value='localhost/mock:0.42.0-weird'
)
workflow_result.add_step_result(step_result=step_result_no_evn)

step_result_deploy_test = StepResult(
step_name='deploy',
sub_step_name='ArgoCD',
Expand All @@ -67,6 +78,10 @@ def _setup_get_value_with_env_test(self, test_dir, environment):
name='deployed-host-urls',
value='https://awesome-app.test.ploigos.xyz'
)
step_result_deploy_test.add_artifact(
name='container-image-tag',
value='localhost/test/mock:0.42.0-weird'
)
workflow_result.add_step_result(step_result=step_result_deploy_test)

step_result_deploy_prod = StepResult(
Expand All @@ -79,6 +94,10 @@ def _setup_get_value_with_env_test(self, test_dir, environment):
name='deployed-host-urls',
value='https://awesome-app.prod.ploigos.xyz'
)
step_result_deploy_test.add_artifact(
name='container-image-tag',
value='localhost/prod/mock:0.42.0-weird'
)
workflow_result.add_step_result(step_result=step_result_deploy_prod)
pickle_filename = os.path.join(parent_work_dir_path, 'step-runner-results.pkl')
workflow_result.write_to_pickle_file(pickle_filename=pickle_filename)
Expand Down Expand Up @@ -910,12 +929,21 @@ def test_get_value_no_env(self):
self.assertEqual(step.get_value('fake-previous-step-artifact'), 'world hello')
self.assertIsNone(step.get_value('does-not-exist'))

def test_get_value_from_step_not_run_against_specific_environment(self):
def test_get_value_from_artifact_without_specifing_environment_where_last_artifact_was_from_environment_and_artifact_never_set_without_environment(self):
with TempDirectory() as test_dir:
step = self._setup_get_value_with_env_test(test_dir=test_dir, environment=None)
self.assertEqual(
step.get_value('deployed-host-urls'),
'https://awesome-app.test.ploigos.xyz'
'https://awesome-app.prod.ploigos.xyz'
)

# NOTE: maybe this should actually return the first instance where the environment was not set?
def test_get_value_from_artifact_without_specifing_environment_where_last_artifact_was_from_environment_and_artifact_was_set_without_environment(self):
with TempDirectory() as test_dir:
step = self._setup_get_value_with_env_test(test_dir=test_dir, environment=None)
self.assertEqual(
step.get_value('container-image-tag'),
'localhost/prod/mock:0.42.0-weird'
)

def test_get_value_from_step_run_in_environment_that_has_result_value_for_that_environment_1(self):
Expand All @@ -939,7 +967,7 @@ def test_get_value_from_step_run_in_environment_that_nodes_not_have_result_value
step = self._setup_get_value_with_env_test(test_dir=test_dir, environment='RANDOM')
self.assertEqual(
step.get_value('deployed-host-urls'),
'https://awesome-app.test.ploigos.xyz'
'https://awesome-app.prod.ploigos.xyz'
)

def test_get_value_multiple_keys_1(self):
Expand Down

0 comments on commit 9143e21

Please sign in to comment.