|
1 | 1 | import json |
2 | | -from convert_output import convert_to_github, Mask, Output |
| 2 | +from convert_output import convert_to_github, Mask, Output, read_input |
3 | 3 |
|
4 | 4 |
|
5 | 5 | def test_string(): |
@@ -40,9 +40,11 @@ def test_number(): |
40 | 40 | } |
41 | 41 | } |
42 | 42 |
|
43 | | - expected_output = [Output(name='int', value='123'), |
44 | | - Mask(value='123'), |
45 | | - Output(name='sensitive_int', value='123')] |
| 43 | + expected_output = [ |
| 44 | + Output(name='int', value='123'), |
| 45 | + Mask(value='123'), |
| 46 | + Output(name='sensitive_int', value='123') |
| 47 | + ] |
46 | 48 |
|
47 | 49 | output = list(convert_to_github(input)) |
48 | 50 | assert output == expected_output |
@@ -305,3 +307,44 @@ def test_compound(): |
305 | 307 |
|
306 | 308 | output = list(convert_to_github(input)) |
307 | 309 | assert output == expected_output |
| 310 | + |
| 311 | + |
| 312 | +def test_read_input_with_junk_lines(): |
| 313 | + input_string = ''' There was an error connecting to Terraform Cloud. Please do not exit |
| 314 | +Terraform to prevent data loss! Trying to restore the connection... |
| 315 | +
|
| 316 | +Still trying to restore the connection... (3s elapsed) |
| 317 | +Still trying to restore the connection... (5s elapsed) |
| 318 | +{ |
| 319 | + "output1": {"type": "string", "value": "value1", "sensitive": false} |
| 320 | +}''' |
| 321 | + result = read_input(input_string) |
| 322 | + assert result == { |
| 323 | + "output1": {"type": "string", "value": "value1", "sensitive": False} |
| 324 | + } |
| 325 | + |
| 326 | +def test_read_input_without_junk_lines(): |
| 327 | + input_string = '''{ |
| 328 | + "output1": {"type": "string", "value": "value1", "sensitive": false} |
| 329 | +}''' |
| 330 | + result = read_input(input_string) |
| 331 | + assert result == { |
| 332 | + "output1": {"type": "string", "value": "value1", "sensitive": False} |
| 333 | + } |
| 334 | + |
| 335 | +def test_read_input_empty_string(): |
| 336 | + input_string = '' |
| 337 | + try: |
| 338 | + read_input(input_string) |
| 339 | + assert False, "Expected an exception" |
| 340 | + except json.JSONDecodeError: |
| 341 | + pass |
| 342 | + |
| 343 | +def test_read_input_invalid_json(): |
| 344 | + input_string = '''{ |
| 345 | + "output1": {"type": "string", "value": "value1", "sensitive": false''' |
| 346 | + try: |
| 347 | + read_input(input_string) |
| 348 | + assert False, "Expected an exception" |
| 349 | + except json.JSONDecodeError: |
| 350 | + pass |
0 commit comments