Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix remaining references to taskcluster/ci + add a test for action-callback #399

Merged
merged 2 commits into from
Dec 19, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/taskgraph/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -723,7 +723,7 @@ def action_callback(options):
@argument(
"--root",
"-r",
default="taskcluster/ci",
default="taskcluster",
help="root of the taskgraph definition relative to topsrcdir",
)
@argument(
Expand Down
4 changes: 2 additions & 2 deletions src/taskgraph/transforms/task.py
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,7 @@ def _run_task_suffix():


UNKNOWN_GROUP_NAME = (
"Treeherder group {} (from {}) has no name; " "add it to taskcluster/ci/config.yml"
"Treeherder group {} (from {}) has no name; " "add it to taskcluster/config.yml"
)

V2_ROUTE_TEMPLATES = [
Expand Down Expand Up @@ -266,7 +266,7 @@ def wrap(func):

UNSUPPORTED_INDEX_PRODUCT_ERROR = """\
The index product {product} is not in the list of configured products in
`taskcluster/ci/config.yml'.
`taskcluster/config.yml'.
"""


Expand Down
56 changes: 45 additions & 11 deletions test/test_main.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@


@pytest.fixture
def run_show_taskgraph(maketgg, monkeypatch):
def run_taskgraph(maketgg, monkeypatch):
def inner(args, **kwargs):
kwargs.setdefault("target_tasks", ["_fake-t-0", "_fake-t-1"])
tgg = maketgg(**kwargs)
Expand Down Expand Up @@ -48,41 +48,41 @@ def fake_get_taskgraph_generator(*args):
("morphed", ["_fake-t-0", "_fake-t-1"]),
),
)
def test_show_taskgraph(run_show_taskgraph, capsys, attr, expected):
res = run_show_taskgraph([attr])
def test_show_taskgraph(run_taskgraph, capsys, attr, expected):
res = run_taskgraph([attr])
assert res == 0

out, err = capsys.readouterr()
assert out.strip() == "\n".join(expected)
assert "Dumping result" in err

# Craft params to cause an exception
res = run_show_taskgraph(["full"], params={"_kinds": None})
res = run_taskgraph(["full"], params={"_kinds": None})
assert res == 1


def test_show_taskgraph_parallel(run_show_taskgraph):
res = run_show_taskgraph(["full", "-p", "taskcluster/test/params"])
def test_show_taskgraph_parallel(run_taskgraph):
res = run_taskgraph(["full", "-p", "taskcluster/test/params"])
assert res == 0

# Craft params to cause an exception
res = run_show_taskgraph(
res = run_taskgraph(
["full", "-p", "taskcluster/test/params"], params={"_kinds": None}
)
assert res == 1


def test_tasks_regex(run_show_taskgraph, capsys):
run_show_taskgraph(["full", "--tasks=_.*-t-1"])
def test_tasks_regex(run_taskgraph, capsys):
run_taskgraph(["full", "--tasks=_.*-t-1"])
out, _ = capsys.readouterr()
assert out.strip() == "_fake-t-1"


def test_output_file(run_show_taskgraph, tmpdir):
def test_output_file(run_taskgraph, tmpdir):
output_file = tmpdir.join("out.txt")
assert not output_file.check()

run_show_taskgraph(["full", f"--output-file={output_file.strpath}"])
run_taskgraph(["full", f"--output-file={output_file.strpath}"])
assert output_file.check()
assert output_file.read_text("utf-8").strip() == "\n".join(
["_fake-t-0", "_fake-t-1", "_fake-t-2"]
Expand Down Expand Up @@ -282,3 +282,37 @@ def test_init_taskgraph_unsupported(mocker, tmp_path, repo_with_upstream):
assert taskgraph_main(["init"]) == 1
finally:
os.chdir(oldcwd)


def test_action_callback(mocker, run_taskgraph):
mocker.patch.dict(
"os.environ",
{
"ACTION_TASK_ID": "null",
"ACTION_TASK_GROUP_ID": "def",
"ACTION_INPUT": '{"ship": true}',
"ACTION_CALLBACK": "action",
},
)

params_mock = mocker.patch("taskgraph.actions.util.get_parameters")
params_mock.return_value = {"foo": "bar"}

trigger_mock = mocker.patch("taskgraph.actions.trigger_action_callback")
trigger_mock.return_value = "result"

result = run_taskgraph(["action-callback"])
assert result == "result"

params_mock.assert_called_once_with("def")
trigger_mock.assert_called_once_with(
task_group_id="def",
task_id=None,
callback="action",
input={"ship": True},
parameters={"foo": "bar"},
root="taskcluster",
test=False,
)
root = Path(trigger_mock.call_args.kwargs["root"])
assert root.joinpath("config.yml").is_file()