|
5 | 5 | from tools.ci import check_for_updated_refs
|
6 | 6 |
|
7 | 7 |
|
8 |
| -def test_parse_push(): |
9 |
| - s = io.StringIO( |
10 |
| - """ |
11 |
| -To github.com:gsnedders/web-platform-tests.git |
12 |
| -= refs/heads/a:refs/heads/a [up to date] |
13 |
| -- :refs/heads/b [deleted] |
14 |
| -+ refs/heads/c:refs/heads/c a6eb923e19...9b6507e295 (forced update) |
15 |
| -* refs/heads/d:refs/heads/d [new branch] |
16 |
| -\x20 refs/heads/e:refs/heads/e 0acd8f62f1..6188942729 |
17 |
| -! refs/heads/f:refs/heads/f [rejected] (atomic push failed) |
| 8 | +PUSH_OUTPUT = """To github.com:web-platform-tests/wpt.git |
| 9 | += refs/heads/stable:refs/heads/stable [up to date] |
| 10 | +- :refs/heads/deleted [deleted] |
| 11 | ++ refs/heads/force:refs/heads/force 7151480...62ee8b6 (forced update) |
| 12 | +* refs/heads/new:refs/heads/new [new branch] |
| 13 | +* refs/tags/v1.0:refs/tags/v1.0 [new tag] |
| 14 | +* refs/review/pr/123:refs/review/pr/123 [new reference] |
| 15 | +\x20 refs/heads/main:refs/heads/main 2e0d156..fd86363 |
| 16 | +\x20 HEAD:refs/heads/feature 49d4a17..5105902 |
| 17 | +\x20 refs/heads/short-sha:refs/heads/short-sha 9731..e320 |
| 18 | +\x20 refs/heads/long-sha:refs/heads/long-sha 01e1bec7812eb37679c0b1cb436290a83cbc4694..8ec0c04d22002009e9db16f5e3c5518574907c93 |
| 19 | +! refs/heads/reject1:refs/heads/reject1 [rejected] (non-fast-forward) |
| 20 | +! refs/heads/reject2:refs/heads/reject2 [rejected] (already exists) |
| 21 | +! refs/heads/reject3:refs/heads/reject3 [rejected] (fetch first) |
| 22 | +! refs/heads/reject4:refs/heads/reject4 [rejected] (needs force) |
| 23 | +! refs/heads/reject5:refs/heads/reject5 [rejected] (stale info) |
| 24 | +! refs/heads/reject6:refs/heads/reject6 [rejected] (remote ref updated since checkout) |
| 25 | +! refs/heads/reject7:refs/heads/reject7 [rejected] (new shallow roots not allowed) |
| 26 | +! refs/heads/reject8:refs/heads/reject8 [rejected] (atomic push failed) |
| 27 | +! refs/heads/reject9:refs/heads/reject9 [remote rejected] (hook declined) |
| 28 | +! refs/heads/reject10:refs/heads/reject10 [remote failure] (timeout) |
| 29 | +! refs/heads/reject11:refs/heads/reject11 [no match] |
18 | 30 | Done
|
19 |
| - """ |
20 |
| - ) |
| 31 | +""" |
| 32 | + |
| 33 | + |
| 34 | +def test_parse_push(): |
| 35 | + s = io.StringIO(PUSH_OUTPUT) |
21 | 36 |
|
22 | 37 | actual = list(check_for_updated_refs.parse_push(s))
|
23 |
| - print(repr(actual)) |
24 | 38 | expected = [
|
25 | 39 | {
|
26 | 40 | "flag": "=",
|
27 |
| - "from": "refs/heads/a", |
28 |
| - "to": "refs/heads/a", |
| 41 | + "from_ref": "refs/heads/stable", |
| 42 | + "to_ref": "refs/heads/stable", |
29 | 43 | "summary": "[up to date]",
|
30 | 44 | "reason": None,
|
31 | 45 | },
|
32 | 46 | {
|
33 | 47 | "flag": "-",
|
34 |
| - "from": "", |
35 |
| - "to": "refs/heads/b", |
| 48 | + "from_ref": "", |
| 49 | + "to_ref": "refs/heads/deleted", |
36 | 50 | "summary": "[deleted]",
|
37 | 51 | "reason": None,
|
38 | 52 | },
|
39 | 53 | {
|
40 | 54 | "flag": "+",
|
41 |
| - "from": "refs/heads/c", |
42 |
| - "to": "refs/heads/c", |
43 |
| - "summary": "a6eb923e19...9b6507e295", |
| 55 | + "from_ref": "refs/heads/force", |
| 56 | + "to_ref": "refs/heads/force", |
| 57 | + "summary": "7151480...62ee8b6", |
44 | 58 | "reason": "forced update",
|
45 | 59 | },
|
46 | 60 | {
|
47 | 61 | "flag": "*",
|
48 |
| - "from": "refs/heads/d", |
49 |
| - "to": "refs/heads/d", |
| 62 | + "from_ref": "refs/heads/new", |
| 63 | + "to_ref": "refs/heads/new", |
50 | 64 | "summary": "[new branch]",
|
51 | 65 | "reason": None,
|
52 | 66 | },
|
| 67 | + { |
| 68 | + "flag": "*", |
| 69 | + "from_ref": "refs/tags/v1.0", |
| 70 | + "to_ref": "refs/tags/v1.0", |
| 71 | + "summary": "[new tag]", |
| 72 | + "reason": None, |
| 73 | + }, |
| 74 | + { |
| 75 | + "flag": "*", |
| 76 | + "from_ref": "refs/review/pr/123", |
| 77 | + "to_ref": "refs/review/pr/123", |
| 78 | + "summary": "[new reference]", |
| 79 | + "reason": None, |
| 80 | + }, |
| 81 | + { |
| 82 | + "flag": " ", |
| 83 | + "from_ref": "refs/heads/main", |
| 84 | + "to_ref": "refs/heads/main", |
| 85 | + "summary": "2e0d156..fd86363", |
| 86 | + "reason": None, |
| 87 | + }, |
53 | 88 | {
|
54 | 89 | "flag": " ",
|
55 |
| - "from": "refs/heads/e", |
56 |
| - "to": "refs/heads/e", |
57 |
| - "summary": "0acd8f62f1..6188942729", |
| 90 | + "from_ref": "HEAD", |
| 91 | + "to_ref": "refs/heads/feature", |
| 92 | + "summary": "49d4a17..5105902", |
58 | 93 | "reason": None,
|
59 | 94 | },
|
| 95 | + { |
| 96 | + "flag": " ", |
| 97 | + "from_ref": "refs/heads/short-sha", |
| 98 | + "to_ref": "refs/heads/short-sha", |
| 99 | + "summary": "9731..e320", |
| 100 | + "reason": None, |
| 101 | + }, |
| 102 | + { |
| 103 | + "flag": " ", |
| 104 | + "from_ref": "refs/heads/long-sha", |
| 105 | + "to_ref": "refs/heads/long-sha", |
| 106 | + "summary": "01e1bec7812eb37679c0b1cb436290a83cbc4694..8ec0c04d22002009e9db16f5e3c5518574907c93", |
| 107 | + "reason": None, |
| 108 | + }, |
| 109 | + { |
| 110 | + "flag": "!", |
| 111 | + "from_ref": "refs/heads/reject1", |
| 112 | + "to_ref": "refs/heads/reject1", |
| 113 | + "summary": "[rejected]", |
| 114 | + "reason": "non-fast-forward", |
| 115 | + }, |
| 116 | + { |
| 117 | + "flag": "!", |
| 118 | + "from_ref": "refs/heads/reject2", |
| 119 | + "to_ref": "refs/heads/reject2", |
| 120 | + "summary": "[rejected]", |
| 121 | + "reason": "already exists", |
| 122 | + }, |
| 123 | + { |
| 124 | + "flag": "!", |
| 125 | + "from_ref": "refs/heads/reject3", |
| 126 | + "to_ref": "refs/heads/reject3", |
| 127 | + "summary": "[rejected]", |
| 128 | + "reason": "fetch first", |
| 129 | + }, |
| 130 | + { |
| 131 | + "flag": "!", |
| 132 | + "from_ref": "refs/heads/reject4", |
| 133 | + "to_ref": "refs/heads/reject4", |
| 134 | + "summary": "[rejected]", |
| 135 | + "reason": "needs force", |
| 136 | + }, |
| 137 | + { |
| 138 | + "flag": "!", |
| 139 | + "from_ref": "refs/heads/reject5", |
| 140 | + "to_ref": "refs/heads/reject5", |
| 141 | + "summary": "[rejected]", |
| 142 | + "reason": "stale info", |
| 143 | + }, |
60 | 144 | {
|
61 | 145 | "flag": "!",
|
62 |
| - "from": "refs/heads/f", |
63 |
| - "to": "refs/heads/f", |
| 146 | + "from_ref": "refs/heads/reject6", |
| 147 | + "to_ref": "refs/heads/reject6", |
| 148 | + "summary": "[rejected]", |
| 149 | + "reason": "remote ref updated since checkout", |
| 150 | + }, |
| 151 | + { |
| 152 | + "flag": "!", |
| 153 | + "from_ref": "refs/heads/reject7", |
| 154 | + "to_ref": "refs/heads/reject7", |
| 155 | + "summary": "[rejected]", |
| 156 | + "reason": "new shallow roots not allowed", |
| 157 | + }, |
| 158 | + { |
| 159 | + "flag": "!", |
| 160 | + "from_ref": "refs/heads/reject8", |
| 161 | + "to_ref": "refs/heads/reject8", |
64 | 162 | "summary": "[rejected]",
|
65 | 163 | "reason": "atomic push failed",
|
66 | 164 | },
|
| 165 | + { |
| 166 | + "flag": "!", |
| 167 | + "from_ref": "refs/heads/reject9", |
| 168 | + "to_ref": "refs/heads/reject9", |
| 169 | + "summary": "[remote rejected]", |
| 170 | + "reason": "hook declined", |
| 171 | + }, |
| 172 | + { |
| 173 | + "flag": "!", |
| 174 | + "from_ref": "refs/heads/reject10", |
| 175 | + "to_ref": "refs/heads/reject10", |
| 176 | + "summary": "[remote failure]", |
| 177 | + "reason": "timeout", |
| 178 | + }, |
| 179 | + { |
| 180 | + "flag": "!", |
| 181 | + "from_ref": "refs/heads/reject11", |
| 182 | + "to_ref": "refs/heads/reject11", |
| 183 | + "summary": "[no match]", |
| 184 | + "reason": None, |
| 185 | + }, |
67 | 186 | ]
|
68 | 187 |
|
69 | 188 | assert expected == actual
|
70 | 189 |
|
71 | 190 |
|
72 |
| -def test_process_push(): |
| 191 | +def test_parse_push_malformed_lines(): |
73 | 192 | s = io.StringIO(
|
74 |
| - """ |
75 |
| -To github.com:gsnedders/web-platform-tests.git |
76 |
| -= refs/heads/a:refs/heads/a [up to date] |
77 |
| -- :refs/heads/b [deleted] |
78 |
| -+ refs/heads/c:refs/heads/c a6eb923e19...9b6507e295 (forced update) |
79 |
| -* refs/heads/d:refs/heads/d [new branch] |
80 |
| -\x20 refs/heads/e:refs/heads/e 0acd8f62f1..6188942729 |
81 |
| -! refs/heads/f:refs/heads/f [rejected] (atomic push failed) |
| 193 | + """To github.com:test/repo.git |
| 194 | +\x20 refs/heads/good:refs/heads/good be30154..bd80959 |
| 195 | +malformed line without tabs |
| 196 | +another bad line |
| 197 | +\x20 refs/heads/good2:refs/heads/good2 ae0f96f..207e07b |
82 | 198 | Done
|
83 |
| - """ |
| 199 | +""" |
84 | 200 | )
|
85 | 201 |
|
86 |
| - actual = list( |
87 |
| - check_for_updated_refs.process_push( |
88 |
| - s, |
89 |
| - [ |
90 |
| - "refs/heads/e", |
91 |
| - "refs/heads/b", |
92 |
| - "refs/heads/c", |
93 |
| - "refs/heads/d", |
94 |
| - "refs/heads/e", |
95 |
| - "refs/heads/x", |
96 |
| - ], |
97 |
| - ) |
98 |
| - ) |
| 202 | + actual = list(check_for_updated_refs.parse_push(s)) |
99 | 203 | expected = [
|
100 |
| - "refs/heads/b", |
101 |
| - "refs/heads/c", |
102 |
| - "refs/heads/d", |
103 |
| - "refs/heads/e", |
| 204 | + { |
| 205 | + "flag": " ", |
| 206 | + "from_ref": "refs/heads/good", |
| 207 | + "to_ref": "refs/heads/good", |
| 208 | + "summary": "be30154..bd80959", |
| 209 | + "reason": None, |
| 210 | + }, |
| 211 | + { |
| 212 | + "flag": " ", |
| 213 | + "from_ref": "refs/heads/good2", |
| 214 | + "to_ref": "refs/heads/good2", |
| 215 | + "summary": "ae0f96f..207e07b", |
| 216 | + "reason": None, |
| 217 | + }, |
104 | 218 | ]
|
105 | 219 |
|
106 | 220 | assert expected == actual
|
| 221 | + |
| 222 | + |
| 223 | +def test_process_push(): |
| 224 | + s = io.StringIO(PUSH_OUTPUT) |
| 225 | + |
| 226 | + actual = check_for_updated_refs.process_push( |
| 227 | + s, |
| 228 | + [ |
| 229 | + "refs/heads/stable", # Omitted as it wasn't actually updated. |
| 230 | + "refs/heads/deleted", |
| 231 | + "refs/heads/force", |
| 232 | + "refs/heads/new", |
| 233 | + "refs/tags/v1.0", |
| 234 | + "refs/review/pr/123", |
| 235 | + "refs/heads/main", |
| 236 | + "refs/heads/feature", |
| 237 | + "refs/heads/reject1", # Omitted as it wasn't actually updated. |
| 238 | + "refs/heads/nonexistent", # Omitted as it wasn't actually updated. |
| 239 | + ], |
| 240 | + ) |
| 241 | + expected = { |
| 242 | + "refs/heads/deleted": None, |
| 243 | + "refs/heads/force": "62ee8b6", |
| 244 | + "refs/heads/new": None, |
| 245 | + "refs/tags/v1.0": None, |
| 246 | + "refs/review/pr/123": None, |
| 247 | + "refs/heads/main": "fd86363", |
| 248 | + "refs/heads/feature": "5105902", |
| 249 | + } |
| 250 | + |
| 251 | + assert expected == actual |
0 commit comments