Skip to content

tfexec: Initial test command support#400

Merged
kmoe merged 1 commit intomainfrom
bflad/test-command
Aug 31, 2023
Merged

tfexec: Initial test command support#400
kmoe merged 1 commit intomainfrom
bflad/test-command

Conversation

@bflad
Copy link
Copy Markdown
Contributor

@bflad bflad commented Jul 25, 2023

Closes #398
Reference: hashicorp/terraform#33454

Adds support for the terraform test command, which currently supports JSON machine-readable output and one flag for configuring the tests directory away from the command default of tests. The command will return a non-zero status if any of the tests fail, which returns an error back to callers of the Test function. If consumers need access to the pass/fail test results, the terraform-json Go module will need to be enhanced to support the test summary JSON, e.g.

{"@level":"info","@message":"Failure! 0 passed, 1 failed.","@module":"terraform.ui","@timestamp":"2023-07-25T10:03:42.980799-04:00","test_summary":{"status":"fail","passed":0,"failed":1,"errored":0,"skipped":0},"type":"test_summary"}

Output of new end-to-end testing:

$ TFEXEC_E2ETEST_VERSIONS=1.5.3,1.6.0-alpha20230719 go test -count=1 -run='TestTest' -v ./tfexec/internal/e2etest
...
--- PASS: TestTest (9.50s)
    --- SKIP: TestTest/test_command_passing-1.5.3 (4.06s)
    --- PASS: TestTest/test_command_passing-1.6.0-alpha20230719 (5.44s)
...
--- PASS: TestTestError (0.48s)
    --- SKIP: TestTestError/test_command_failing-1.5.3 (0.27s)
    --- PASS: TestTestError/test_command_failing-1.6.0-alpha20230719 (0.21s)

Reference: #398
Reference: hashicorp/terraform#33454

Adds support for the `terraform test` command, which currently supports JSON machine-readable output and one flag for configuring the tests directory away from the command default of `tests`. The command will return a non-zero status if any of the tests fail, which returns an error back to callers of the `Test` function. If consumers need access to the pass/fail test results, the terraform-json Go module will need to be enhanced to support the test summary JSON, e.g.

```
{"@Level":"info","@message":"Failure! 0 passed, 1 failed.","@module":"terraform.ui","@timestamp":"2023-07-25T10:03:42.980799-04:00","test_summary":{"status":"fail","passed":0,"failed":1,"errored":0,"skipped":0},"type":"test_summary"}
```

Output of new end-to-end testing:

```
$ TFEXEC_E2ETEST_VERSIONS=1.5.3,1.6.0-alpha20230719 go test -count=1 -run='TestTest' -v ./tfexec/internal/e2etest
...
--- PASS: TestTest (9.50s)
    --- SKIP: TestTest/test_command_passing-1.5.3 (4.06s)
    --- PASS: TestTest/test_command_passing-1.6.0-alpha20230719 (5.44s)
...
--- PASS: TestTestError (0.48s)
    --- SKIP: TestTestError/test_command_failing-1.5.3 (0.27s)
    --- PASS: TestTestError/test_command_failing-1.6.0-alpha20230719 (0.21s)
```
@bflad bflad added the enhancement New feature or request label Jul 25, 2023
@kmoe
Copy link
Copy Markdown
Member

kmoe commented Jul 25, 2023

Lovely! @liamcervante will be adding terraform-json support for the return types, so those will definitely be usable here.

@liamcervante
Copy link
Copy Markdown

liamcervante commented Aug 29, 2023

@liamcervante will be adding terraform-json support for the return types, so those will definitely be usable here.

So, terraform-json doesn't actually support the streamed JSON logs for any of the other commands. I'm not sure if I should just go and add them for the testing command only. I'm gathering other opinions on this, is this something that would be required for this PR? If yes, that'll help me make my decision!

I'm only hesitant as I'm worried about why the streamed logs for the other commands aren't available.

@liamcervante
Copy link
Copy Markdown

We've agreed to be reactive here, so happy to merge this as-is. We can come and add more fine-grained info to the outputs as and when we have a concrete use-case.

@kmoe
Copy link
Copy Markdown
Member

kmoe commented Aug 31, 2023

Lovely, thank you bflad

@kmoe kmoe merged commit cff1cb8 into main Aug 31, 2023
@kmoe kmoe deleted the bflad/test-command branch August 31, 2023 09:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider supporting terraform test

3 participants