-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_github_script.py
More file actions
145 lines (117 loc) · 3.91 KB
/
Copy pathtest_github_script.py
File metadata and controls
145 lines (117 loc) · 3.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
import sys
import pytest
import gardenlinux.github.release.__main__ as gh
from gardenlinux.constants import GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME
from ..constants import TEST_GARDENLINUX_COMMIT, TEST_GARDENLINUX_RELEASE
def test_script_parse_args_wrong_command(monkeypatch, capfd):
monkeypatch.setattr(sys, "argv", ["gh", "rejoice"])
with pytest.raises(SystemExit):
gh.main()
captured = capfd.readouterr()
assert (
"argument command: invalid choice: 'rejoice'" in captured.err
), "Expected help message printed"
def test_script_parse_args_create_command_required_args(monkeypatch, capfd):
monkeypatch.setattr(
sys, "argv", ["gh", "create", "--owner", "gardenlinux", "--repo", "gardenlinux"]
)
with pytest.raises(SystemExit):
gh.main()
captured = capfd.readouterr()
assert (
"the following arguments are required: --tag, --commit" in captured.err
), "Expected help message on missing arguments for 'create' command"
def test_script_parse_args_upload_command_required_args(monkeypatch, capfd):
monkeypatch.setattr(
sys, "argv", ["gh", "upload", "--owner", "gardenlinux", "--repo", "gardenlinux"]
)
with pytest.raises(SystemExit):
gh.main()
captured = capfd.readouterr()
assert (
"the following arguments are required: --release_id, --file_path"
in captured.err
), "Expected help message on missing arguments for 'upload' command"
def test_script_create_dry_run(monkeypatch, capfd):
monkeypatch.setattr(
sys,
"argv",
[
"gh",
"create",
"--owner",
"gardenlinux",
"--repo",
"gardenlinux",
"--tag",
TEST_GARDENLINUX_RELEASE,
"--commit",
TEST_GARDENLINUX_COMMIT,
"--dry-run",
],
)
monkeypatch.setattr(
"gardenlinux.github.release.__main__.create_github_release_notes",
lambda tag, commit, bucket: f"{tag} {commit} {bucket}",
)
gh.main()
captured = capfd.readouterr()
assert (
captured.out
== f"Dry Run ...\nThis release would be created:\n{TEST_GARDENLINUX_RELEASE} {TEST_GARDENLINUX_COMMIT} {GARDENLINUX_GITHUB_RELEASE_BUCKET_NAME}\n"
), "Expected dry-run create to return generated release notes text"
def test_script_create(monkeypatch, caplog):
monkeypatch.setattr(
sys,
"argv",
[
"gh",
"create",
"--owner",
"gardenlinux",
"--repo",
"gardenlinux",
"--tag",
TEST_GARDENLINUX_RELEASE,
"--commit",
TEST_GARDENLINUX_COMMIT,
],
)
monkeypatch.setattr(
"gardenlinux.github.release.__main__.create_github_release_notes",
lambda tag, commit, bucket: f"{tag} {commit} {bucket}",
)
monkeypatch.setattr(
"gardenlinux.github.release.__main__.create_github_release",
lambda a1, a2, a3, a4, a5, a6: TEST_GARDENLINUX_RELEASE,
)
gh.main()
assert any(
f"Release created with ID: {TEST_GARDENLINUX_RELEASE}" in record.message
for record in caplog.records
), "Expected a release creation confirmation log entry"
def test_script_upload_dry_run(monkeypatch, capfd):
monkeypatch.setattr(
sys,
"argv",
[
"gh",
"upload",
"--owner",
"gardenlinux",
"--repo",
"gardenlinux",
"--release_id",
TEST_GARDENLINUX_RELEASE,
"--file_path",
"foo",
"--dry-run",
],
)
monkeypatch.setattr(
"gardenlinux.github.release.__main__.upload_to_github_release_page",
lambda a1, a2, a3, a4, dry_run: print(f"dry-run: {dry_run}"),
)
gh.main()
captured = capfd.readouterr()
assert captured.out == "dry-run: True\n"