From 76f5405bebe3da18d28fb282de203fb370195ac3 Mon Sep 17 00:00:00 2001 From: oreenlivnicode Date: Mon, 30 Oct 2023 19:06:27 +0200 Subject: [PATCH] Add tests - WIP --- src/downloader/gh_api.py | 2 +- tests/unit/test_composite_action.py | 10 ++++++++++ tests/unit/test_dependency.py | 22 ++++++++-------------- tests/unit/test_workflow.py | 4 ++++ 4 files changed, 23 insertions(+), 15 deletions(-) diff --git a/src/downloader/gh_api.py b/src/downloader/gh_api.py index 8d29a52..e8af8b1 100644 --- a/src/downloader/gh_api.py +++ b/src/downloader/gh_api.py @@ -202,7 +202,7 @@ def get_ref_of_tag(repo: str, tag: str) -> Optional[str]: r_tags = get(TAGS_URL.format(repo_path=repo), headers=headers) if r_tags.status_code != 200: log.error( - f"Coudln't found tags for repository {repo}. status code: {r_tags.status_code}. Response: {r_tags.text}" + f"Coudln't found tags for repository {repo} even though tag {tag} is required. status code: {r_tags.status_code}. Response: {r_tags.text}" ) return diff --git a/tests/unit/test_composite_action.py b/tests/unit/test_composite_action.py index b44bbe0..ee8aa43 100644 --- a/tests/unit/test_composite_action.py +++ b/tests/unit/test_composite_action.py @@ -32,6 +32,7 @@ def test_composite_action_from_dist_node(): "branding": {"icon": "alert-circle", "color": "orange"}, "path": "data/actions/peter-evans|create-issue-from-file|action.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v3", } ca = composite_action.CompositeAction.from_dict(ca_d) @@ -41,6 +42,7 @@ def test_composite_action_from_dist_node(): assert ca.inputs == list(ca_d["inputs"].keys()) assert ca.using == "node16" assert ca.url == ca_d["url"] + assert ca.tag == ca_d["tag"] assert ca.image is None assert len(ca.steps) == 0 @@ -137,6 +139,7 @@ def test_composite_action_from_dict_steps(): }, "path": "data/actions/taiki-e|install-action|action.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v1", } ca = composite_action.CompositeAction.from_dict(ca_d) @@ -146,6 +149,7 @@ def test_composite_action_from_dict_steps(): assert ca.inputs == list(ca_d["inputs"].keys()) assert ca.using == "composite" assert ca.url == ca_d["url"] + assert ca.tag == ca_d["tag"] assert ca.image is None assert len(ca.steps) == 1 @@ -158,6 +162,7 @@ def test_composite_action_step_from_dict_run(): "_id": "4eba12855ade10f6e8dda0456946ffa1", "path": "data/actions/dtolnay|rust-toolchain|action.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v1", } step = composite_action.CompositeActionStep.from_dict(step_d) @@ -171,6 +176,7 @@ def test_composite_action_step_from_dict_run(): assert step.shell == step_d["shell"] assert step.with_prop is None assert step.url == step_d["url"] + assert step.tag == step_d["tag"] assert len(step.action) == 0 assert len(step.reusable_workflow) == 0 assert len(step.using_param) == 0 @@ -187,6 +193,7 @@ def test_composite_action_step_from_dict_run_dependency(): "_id": "f85b9778e35a1273d88c7dabdb210eaf", "path": "data/actions/ytdl-org|setup-python|action.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v1", } step = composite_action.CompositeActionStep.from_dict(step_d) @@ -199,6 +206,7 @@ def test_composite_action_step_from_dict_run_dependency(): assert step.ref is None assert step.shell == step_d["shell"] assert step.url == step_d["url"] + assert step.tag == step_d["tag"] assert step.with_prop is None assert len(step.action) == 0 assert len(step.reusable_workflow) == 0 @@ -221,6 +229,7 @@ def test_composite_action_step_from_dict_using(): "_id": "11e15e6b7424478c2e32fd22ed477c21", "path": "data/actions/ytdl-org|setup-python|action.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v1", } step = composite_action.CompositeActionStep.from_dict(step_d) @@ -232,6 +241,7 @@ def test_composite_action_step_from_dict_using(): assert step.ref == "bd6b4b6205c4dbad673328db7b31b7fab9e241c0" assert step.shell is None assert step.url == step_d["url"] + assert step.tag == step_d["tag"] assert step.with_prop == [ "python-version:${{ steps.build.outputs.python-version }}", "cache:${{ inputs.cache }}", diff --git a/tests/unit/test_dependency.py b/tests/unit/test_dependency.py index 9b7eb67..471eba6 100644 --- a/tests/unit/test_dependency.py +++ b/tests/unit/test_dependency.py @@ -6,11 +6,7 @@ def test_uses_string_analyze(): test_cases = [ - ( - "actions/checkout@v2", - False, - "actions/checkout", - ), + ("actions/checkout@v2", False, "actions/checkout", "v2"), ( "github/codeql-action/analyze@v1", False, @@ -20,27 +16,25 @@ def test_uses_string_analyze(): "./.github/actions/action-setup", True, "./.github/actions/action-setup", + None, ), - ( - "./.github/actions/build.yml", - True, - "./.github/actions/build.yml", - ), + ("./.github/actions/build.yml", True, "./.github/actions/build.yml", None), ( "octo-org/this-repo/.github/workflows/workflow-1.yml@latest", False, "octo-org/this-repo/.github/workflows/workflow-1.yml", + "latest", ), ( "docker://docker.io/library/golang:1.17.1-alpine@sha256:abcd", False, "docker://docker.io/library/golang:1.17.1-alpine", + "sha256:abcd", ), ] for test_case in test_cases: uses_string_obj = dependency.UsesString.analyze(test_case[0]) - assert ( - uses_string_obj.is_relative == test_case[1] - and uses_string_obj.path == test_case[2] - ) + assert uses_string_obj.is_relative == test_case[1] + assert uses_string_obj.path == test_case[2] + assert uses_string_obj.ref == test_case[3] diff --git a/tests/unit/test_workflow.py b/tests/unit/test_workflow.py index 8dae7bc..8282aab 100644 --- a/tests/unit/test_workflow.py +++ b/tests/unit/test_workflow.py @@ -19,6 +19,7 @@ def test_job_from_dict_steps(): "_id": "6347a06af34cc01c884c110fd9db8964", "path": "electron/electron/.github/workflows/issue-commented.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v1", } job = workflow.Job.from_dict(job_d) @@ -31,6 +32,7 @@ def test_job_from_dict_steps(): assert job.ref is None assert job.with_prop is None assert job.url == job_d["url"] + assert job.tag == job_d["tag"] assert len(job.steps) == 1 assert len(job.reusable_workflow) == 0 @@ -101,6 +103,7 @@ def test_step_from_dict_uses(): "_id": "9a42f7bb6c8e5be00c1d36d54ac7bdb6", "path": "electron/electron/.github/workflows/issue-commented.yml", "url": "https://github.com/CycodeLabs/Raven/pull/1", + "tag": "v1", } step = workflow.Step.from_dict(step_d) @@ -111,6 +114,7 @@ def test_step_from_dict_uses(): assert step.run is None assert step.uses == step_d["uses"] assert step.url == step_d["url"] + assert step.tag == step_d["tag"] assert step.ref == "cc6751b3b5e4edc5b9a4ad0a021ac455653b6dc8" assert step.with_prop == ["creds:${{ secrets.ISSUE_TRIAGE_GH_APP_CREDS }}"]