def test_nondefault_workspace(): payload = '''Terraform plan in __/test/terraform__ in the __myworkspace__ workspace <details open> <summary>Plan: 1 to add, 0 to change, 0 to destroy.</summary> ```hcl An execution plan has been generated and is shown below. ... Plan: 1 to add, 0 to change, 0 to destroy. ``` </details> Testing''' expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status='Testing', headers={}, description= 'Terraform plan in __/test/terraform__ in the __myworkspace__ workspace', summary='Plan: 1 to add, 0 to change, 0 to destroy.', body=plan) assert _from_api_payload({ 'body': payload, 'url': comment_url, 'issue_url': issue_url }) == expected
def test_variables_single_line(): payload = '''Terraform plan in __/test/terraform__ With variables: `var1="value"` <details open> <summary>Plan: 1 to add, 0 to change, 0 to destroy.</summary> ```hcl An execution plan has been generated and is shown below. ... Plan: 1 to add, 0 to change, 0 to destroy. ``` </details> Testing''' expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status='Testing', headers={}, description= 'Terraform plan in __/test/terraform__\nWith variables: `var1="value"`', summary='Plan: 1 to add, 0 to change, 0 to destroy.', body=plan) assert _from_api_payload({ 'body': payload, 'url': comment_url, 'issue_url': issue_url }) == expected
def test_backend_config_file(): payload = '''Terraform plan in __/test/terraform__ With backend config files: `backend.tf` <details open> <summary>Plan: 1 to add, 0 to change, 0 to destroy.</summary> ```hcl An execution plan has been generated and is shown below. ... Plan: 1 to add, 0 to change, 0 to destroy. ``` </details> Testing''' expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status='Testing', headers={}, description='''Terraform plan in __/test/terraform__ With backend config files: `backend.tf`''', summary='Plan: 1 to add, 0 to change, 0 to destroy.', body=plan) assert _from_api_payload({ 'body': payload, 'url': comment_url, 'issue_url': issue_url }) == expected
def test_replace(): payload = '''Terraform plan in __/test/terraform__ Replacing resources: `kubernetes_secret.tls_cert_public[0]`, `kubernetes_secret.tls_cert_private` <details open> <summary>Plan: 1 to add, 0 to change, 0 to destroy.</summary> ```hcl An execution plan has been generated and is shown below. ... Plan: 1 to add, 0 to change, 0 to destroy. ``` </details> Testing''' expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status='Testing', headers={}, description='''Terraform plan in __/test/terraform__ Replacing resources: `kubernetes_secret.tls_cert_public[0]`, `kubernetes_secret.tls_cert_private`''', summary='Plan: 1 to add, 0 to change, 0 to destroy.', body=plan) assert _from_api_payload({ 'body': payload, 'url': comment_url, 'issue_url': issue_url }) == expected
def test_bad_description(): issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10)) comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10)) status = 'Testing' summary = 'Some changes' body = '''blah blah body''' description = 'crap -->\nqweqwe</details>something something <details>' headers = { 'hello': 'first_header_value', 'there': 'second_header_value' } expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status=status, headers=headers, description=description, summary=summary, body=body ) assert _from_api_payload({ 'body': _to_api_payload(expected), 'url': comment_url, 'issue_url': issue_url }) == expected
def test_headers(): issue_url = ''.join(random.choice(string.ascii_letters) for _ in range(10)) comment_url = ''.join(random.choice(string.ascii_letters) for _ in range(10)) status = 'Testing' description = 'Hello, this is a description' summary = 'Some changes' body = '''An execution plan has been generated and is shown below. ... Plan: 1 to add, 0 to change, 0 to destroy. ''' headers = { 'hello': 'first_header_value', 'there': 'second_header_value' } expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status=status, headers=headers, description=description, summary=summary, body=body ) assert _from_api_payload({ 'body': _to_api_payload(expected), 'url': comment_url, 'issue_url': issue_url }) == expected
def test_all(): payload = '''Terraform plan in __/test/terraform__ in the __test__ workspace Targeting resources: `kubernetes_secret.tls_cert_public[0]`, `kubernetes_secret.tls_cert_private` Replacing resources: `kubernetes_secret.tls_cert_public[0]`, `kubernetes_secret.tls_cert_private` With backend config: `bucket=mybucket` With backend config files: `backend.tf` With vars: `myvar=hello` With var files: `vars.tf` <details open> <summary>Plan: 1 to add, 0 to change, 0 to destroy.</summary> ```hcl An execution plan has been generated and is shown below. ... Plan: 1 to add, 0 to change, 0 to destroy. ``` </details> Testing''' expected = TerraformComment( issue_url=issue_url, comment_url=comment_url, status='Testing', headers={}, description= '''Terraform plan in __/test/terraform__ in the __test__ workspace Targeting resources: `kubernetes_secret.tls_cert_public[0]`, `kubernetes_secret.tls_cert_private` Replacing resources: `kubernetes_secret.tls_cert_public[0]`, `kubernetes_secret.tls_cert_private` With backend config: `bucket=mybucket` With backend config files: `backend.tf` With vars: `myvar=hello` With var files: `vars.tf`''', summary='Plan: 1 to add, 0 to change, 0 to destroy.', body=plan) assert _from_api_payload({ 'body': payload, 'url': comment_url, 'issue_url': issue_url }) == expected