Skip to content

Commit 8a9a5aa

Browse files
committed
Update tests
1 parent cc5d2f9 commit 8a9a5aa

File tree

3 files changed

+50
-1
lines changed

3 files changed

+50
-1
lines changed

.github/workflows/test-version.yaml

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -526,7 +526,7 @@ jobs:
526526

527527
- name: Check the version
528528
run: |
529-
if [[ "${{ steps.terraform-version.outputs.terraform }}" != *"1.8"* ]]; then
529+
if [[ "${{ steps.terraform-version.outputs.terraform }}" != *"1.9"* ]]; then
530530
echo "::error:: Latest version was not used"
531531
exit 1
532532
fi
@@ -740,6 +740,8 @@ jobs:
740740
opentofu_version_pre_release_nosig:
741741
runs-on: ubuntu-latest
742742
name: OPENTOFU_VERSION pre-release with tofu action
743+
env:
744+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
743745
steps:
744746
- name: Checkout
745747
uses: actions/checkout@v4
@@ -770,6 +772,8 @@ jobs:
770772
opentofu_old_version:
771773
runs-on: ubuntu-latest
772774
name: Prefer OpenTofu, but only Terraform matches constraints
775+
env:
776+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
773777
steps:
774778
- name: Checkout
775779
uses: actions/checkout@v4

tests/github_pr_comment/test_comment.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import random
22
import string
3+
from typing import cast
34

5+
from github_actions.api import NodeId
46
from github_pr_comment.comment import _format_comment_header, _parse_comment_header, TerraformComment, _to_api_payload, _from_api_payload
57

68

@@ -23,6 +25,7 @@ def test_comment_header():
2325
def test_no_headers():
2426
issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
2527
comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
28+
node_id = cast(NodeId, ''.join(random.choice(string.ascii_letters) for _ in range(10)))
2629
status = 'Testing'
2730
description = 'Hello, this is a description'
2831
summary = 'Some changes'
@@ -34,6 +37,7 @@ def test_no_headers():
3437
expected = TerraformComment(
3538
issue_url=issue_url,
3639
comment_url=comment_url,
40+
node_id=node_id,
3741
status=status,
3842
headers={},
3943
description=description,
@@ -44,13 +48,15 @@ def test_no_headers():
4448
assert _from_api_payload({
4549
'body': _to_api_payload(expected),
4650
'url': comment_url,
51+
'node_id': node_id,
4752
'issue_url': issue_url
4853
}) == expected
4954

5055

5156
def test_headers():
5257
issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
5358
comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
59+
node_id = cast(NodeId, ''.join(random.choice(string.ascii_letters) for _ in range(10)))
5460
status = 'Testing'
5561
description = 'Hello, this is a description'
5662
summary = 'Some changes'
@@ -66,6 +72,7 @@ def test_headers():
6672
expected = TerraformComment(
6773
issue_url=issue_url,
6874
comment_url=comment_url,
75+
node_id=node_id,
6976
status=status,
7077
headers=headers,
7178
description=description,
@@ -76,13 +83,15 @@ def test_headers():
7683
assert _from_api_payload({
7784
'body': _to_api_payload(expected),
7885
'url': comment_url,
86+
'node_id': node_id,
7987
'issue_url': issue_url
8088
}) == expected
8189

8290

8391
def test_bad_description():
8492
issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
8593
comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
94+
node_id = cast(NodeId, ''.join(random.choice(string.ascii_letters) for _ in range(10)))
8695
status = 'Testing'
8796
summary = 'Some changes'
8897
body = '''blah blah body'''
@@ -96,6 +105,7 @@ def test_bad_description():
96105
expected = TerraformComment(
97106
issue_url=issue_url,
98107
comment_url=comment_url,
108+
node_id=node_id,
99109
status=status,
100110
headers=headers,
101111
description=description,
@@ -106,13 +116,15 @@ def test_bad_description():
106116
assert _from_api_payload({
107117
'body': _to_api_payload(expected),
108118
'url': comment_url,
119+
'node_id': node_id,
109120
'issue_url': issue_url
110121
}) == expected
111122

112123

113124
def test_bad_body():
114125
issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
115126
comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
127+
node_id = cast(NodeId, ''.join(random.choice(string.ascii_letters) for _ in range(10)))
116128
status = 'Testing'
117129
summary = 'Some changes'
118130
description = '''blah blah description'''
@@ -126,6 +138,7 @@ def test_bad_body():
126138
expected = TerraformComment(
127139
issue_url=issue_url,
128140
comment_url=comment_url,
141+
node_id=node_id,
129142
status=status,
130143
headers=headers,
131144
description=description,
@@ -136,5 +149,6 @@ def test_bad_body():
136149
assert _from_api_payload({
137150
'body': _to_api_payload(expected),
138151
'url': comment_url,
152+
'node_id': node_id,
139153
'issue_url': issue_url
140154
}) == expected

tests/github_pr_comment/test_legacy_comment.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313

1414
issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
1515
comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10))
16+
node_id = ''.join(random.choice(string.ascii_letters) for _ in range(10))
1617

1718
def test_path_only():
1819
payload = '''Terraform plan in __/test/terraform__
@@ -31,6 +32,7 @@ def test_path_only():
3132
expected = TerraformComment(
3233
issue_url=issue_url,
3334
comment_url=comment_url,
35+
node_id=node_id,
3436
status='Testing',
3537
headers={},
3638
description='Terraform plan in __/test/terraform__',
@@ -42,6 +44,7 @@ def test_path_only():
4244
assert _from_api_payload({
4345
'body': payload,
4446
'url': comment_url,
47+
'node_id': node_id,
4548
'issue_url': issue_url
4649
}) == expected
4750

@@ -63,6 +66,7 @@ def test_nondefault_workspace():
6366
expected = TerraformComment(
6467
issue_url=issue_url,
6568
comment_url=comment_url,
69+
node_id=node_id,
6670
status='Testing',
6771
headers={},
6872
description='Terraform plan in __/test/terraform__ in the __myworkspace__ workspace',
@@ -74,6 +78,7 @@ def test_nondefault_workspace():
7478
assert _from_api_payload({
7579
'body': payload,
7680
'url': comment_url,
81+
'node_id': node_id,
7782
'issue_url': issue_url
7883
}) == expected
7984

@@ -97,6 +102,7 @@ def test_variables_single_line():
97102
expected = TerraformComment(
98103
issue_url=issue_url,
99104
comment_url=comment_url,
105+
node_id=node_id,
100106
status='Testing',
101107
headers={},
102108
description='Terraform plan in __/test/terraform__\nWith variables: `var1="value"`',
@@ -108,6 +114,7 @@ def test_variables_single_line():
108114
assert _from_api_payload({
109115
'body': payload,
110116
'url': comment_url,
117+
'node_id': node_id,
111118
'issue_url': issue_url
112119
}) == expected
113120

@@ -136,6 +143,7 @@ def test_variables_multi_line():
136143
expected = TerraformComment(
137144
issue_url=issue_url,
138145
comment_url=comment_url,
146+
node_id=node_id,
139147
status='Testing',
140148
headers={},
141149
description='''Terraform plan in __/test/terraform__<details><summary>With variables</summary>
@@ -153,6 +161,7 @@ def test_variables_multi_line():
153161
assert _from_api_payload({
154162
'body': payload,
155163
'url': comment_url,
164+
'node_id': node_id,
156165
'issue_url': issue_url
157166
}) == expected
158167

@@ -175,6 +184,7 @@ def test_var():
175184
expected = TerraformComment(
176185
issue_url=issue_url,
177186
comment_url=comment_url,
187+
node_id=node_id,
178188
status='Testing',
179189
headers={},
180190
description='''Terraform plan in __/test/terraform__
@@ -187,6 +197,7 @@ def test_var():
187197
assert _from_api_payload({
188198
'body': payload,
189199
'url': comment_url,
200+
'node_id': node_id,
190201
'issue_url': issue_url
191202
}) == expected
192203

@@ -209,6 +220,7 @@ def test_var_file():
209220
expected = TerraformComment(
210221
issue_url=issue_url,
211222
comment_url=comment_url,
223+
node_id=node_id,
212224
status='Testing',
213225
headers={},
214226
description='''Terraform plan in __/test/terraform__
@@ -221,6 +233,7 @@ def test_var_file():
221233
assert _from_api_payload({
222234
'body': payload,
223235
'url': comment_url,
236+
'node_id': node_id,
224237
'issue_url': issue_url
225238
}) == expected
226239

@@ -244,6 +257,7 @@ def test_backend_config():
244257
expected = TerraformComment(
245258
issue_url=issue_url,
246259
comment_url=comment_url,
260+
node_id=node_id,
247261
status='Testing',
248262
headers={},
249263
description='''Terraform plan in __/test/terraform__
@@ -256,6 +270,7 @@ def test_backend_config():
256270
assert _from_api_payload({
257271
'body': payload,
258272
'url': comment_url,
273+
'node_id': node_id,
259274
'issue_url': issue_url
260275
}) == expected
261276

@@ -278,6 +293,7 @@ def test_backend_config_bad_words():
278293
expected = TerraformComment(
279294
issue_url=issue_url,
280295
comment_url=comment_url,
296+
node_id=node_id,
281297
status='Testing',
282298
headers={},
283299
description='''Terraform plan in __/test/terraform__
@@ -290,6 +306,7 @@ def test_backend_config_bad_words():
290306
assert _from_api_payload({
291307
'body': payload,
292308
'url': comment_url,
309+
'node_id': node_id,
293310
'issue_url': issue_url
294311
}) == expected
295312

@@ -311,6 +328,7 @@ def test_target():
311328
expected = TerraformComment(
312329
issue_url=issue_url,
313330
comment_url=comment_url,
331+
node_id=node_id,
314332
status='Testing',
315333
headers={},
316334
description='''Terraform plan in __/test/terraform__
@@ -323,6 +341,7 @@ def test_target():
323341
assert _from_api_payload({
324342
'body': payload,
325343
'url': comment_url,
344+
'node_id': node_id,
326345
'issue_url': issue_url
327346
}) == expected
328347

@@ -344,6 +363,7 @@ def test_replace():
344363
expected = TerraformComment(
345364
issue_url=issue_url,
346365
comment_url=comment_url,
366+
node_id=node_id,
347367
status='Testing',
348368
headers={},
349369
description='''Terraform plan in __/test/terraform__
@@ -356,6 +376,7 @@ def test_replace():
356376
assert _from_api_payload({
357377
'body': payload,
358378
'url': comment_url,
379+
'node_id': node_id,
359380
'issue_url': issue_url
360381
}) == expected
361382

@@ -378,6 +399,7 @@ def test_backend_config_file():
378399
expected = TerraformComment(
379400
issue_url=issue_url,
380401
comment_url=comment_url,
402+
node_id=node_id,
381403
status='Testing',
382404
headers={},
383405
description='''Terraform plan in __/test/terraform__
@@ -390,6 +412,7 @@ def test_backend_config_file():
390412
assert _from_api_payload({
391413
'body': payload,
392414
'url': comment_url,
415+
'node_id': node_id,
393416
'issue_url': issue_url
394417
}) == expected
395418

@@ -417,6 +440,7 @@ def test_all():
417440
expected = TerraformComment(
418441
issue_url=issue_url,
419442
comment_url=comment_url,
443+
node_id=node_id,
420444
status='Testing',
421445
headers={},
422446
description='''Terraform plan in __/test/terraform__ in the __test__ workspace
@@ -434,6 +458,7 @@ def test_all():
434458
assert _from_api_payload({
435459
'body': payload,
436460
'url': comment_url,
461+
'node_id': node_id,
437462
'issue_url': issue_url
438463
}) == expected
439464

@@ -455,6 +480,7 @@ def test_label():
455480
expected = TerraformComment(
456481
issue_url=issue_url,
457482
comment_url=comment_url,
483+
node_id=node_id,
458484
status='Testing',
459485
headers={},
460486
description='''Terraform plan for __test_label__''',
@@ -466,6 +492,7 @@ def test_label():
466492
assert _from_api_payload({
467493
'body': payload,
468494
'url': comment_url,
495+
'node_id': node_id,
469496
'issue_url': issue_url
470497
}) == expected
471498

@@ -489,6 +516,7 @@ def test_error():
489516
expected = TerraformComment(
490517
issue_url=issue_url,
491518
comment_url=comment_url,
519+
node_id=node_id,
492520
status=':x: Failed to generate plan in [Test terraform-plan #603](https://github.com/dflook/terraform-github-actions/actions/runs/6684032578)',
493521
headers={},
494522
description='''Terraform plan in __tests/workflows/test-plan/error__''',
@@ -504,6 +532,7 @@ def test_error():
504532
assert _from_api_payload({
505533
'body': payload,
506534
'url': comment_url,
535+
'node_id': node_id,
507536
'issue_url': issue_url
508537
}) == expected
509538

@@ -524,6 +553,7 @@ def test_diff():
524553
expected = TerraformComment(
525554
issue_url=issue_url,
526555
comment_url=comment_url,
556+
node_id=node_id,
527557
status='Testing',
528558
headers={},
529559
description='Terraform plan in __/test/terraform__ in the __myworkspace__ workspace',
@@ -535,5 +565,6 @@ def test_diff():
535565
assert _from_api_payload({
536566
'body': payload,
537567
'url': comment_url,
568+
'node_id': node_id,
538569
'issue_url': issue_url
539570
}) == expected

0 commit comments

Comments
 (0)