Skip to content

Commit

Permalink
Add tests - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
oreenlivnicode committed Oct 31, 2023
1 parent e857a65 commit 7959f01
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 15 deletions.
2 changes: 1 addition & 1 deletion src/downloader/gh_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
10 changes: 10 additions & 0 deletions tests/unit/test_composite_action.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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

Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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
Expand All @@ -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)
Expand All @@ -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 }}",
Expand Down
22 changes: 8 additions & 14 deletions tests/unit/test_dependency.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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]
4 changes: 4 additions & 0 deletions tests/unit/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand All @@ -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 }}"]

Expand Down

0 comments on commit 7959f01

Please sign in to comment.