Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

helper/resource: Added error logging before failing tests #958

Merged
merged 2 commits into from May 5, 2022

Conversation

bflad
Copy link
Member

@bflad bflad commented May 4, 2022

Closes #956

If provider developers are using TF_ACC_LOG_PATH or TF_LOG_PATH_MASK, this will ensure that the separate log file will include the test failure reason, in addition to the test output.

Example from terraform-provider-corner, after purposefully breaking a check:

$ TF_ACC=1 TF_LOG=TRACE TF_ACC_LOG_PATH=test.txt go test -count=1 -run='TestAccFrameworkResourceUser$' -v ./internal/frameworkprovider
=== RUN   TestAccFrameworkResourceUser
    resource_user_test.go:12: Step 1/1 error: Check failed: Check 1/5 error: framework_user.foo: Attribute 'name' expected "Oops", got "Ford Prefect"
--- FAIL: TestAccFrameworkResourceUser (0.82s)
FAIL
FAIL    github.com/hashicorp/terraform-provider-corner/internal/frameworkprovider       1.162s

$ grep ERROR internal/frameworkprovider/test.txt
2022-05-04T14:42:58.636-0400 [ERROR] sdk.helper_resource: Unexpected error: test_name=TestAccFrameworkResourceUser test_step_number=1 test_terraform_path=/usr/local/bin/terraform test_working_directory=/var/folders/w8/05f3x02n27x72g0mc2jy6_180000gp/T/plugintest853754224 error="Check failed: Check 1/5 error: framework_user.foo: Attribute 'name' expected \"Oops\", got \"Ford Prefect\""

Reference: #956

If provider developers are using `TF_ACC_LOG_PATH` or `TF_LOG_PATH_MASK`, this will ensure that the separate log file will  include the test failure reason, in addition to the test output.
@bflad bflad added enhancement New feature or request subsystem/tests Issues and feature requests related to the testing framework. labels May 4, 2022
@bflad bflad added this to the v2.16.0 milestone May 4, 2022
@bflad bflad requested a review from a team as a code owner May 4, 2022 18:45
Copy link
Contributor

@bendbennett bendbennett left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

@detro detro left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This makes sense.

@bflad bflad merged commit 0f5a544 into main May 5, 2022
@bflad bflad deleted the bflad-helper-resource-error-logging branch May 5, 2022 14:43
@github-actions
Copy link

github-actions bot commented Jun 5, 2022

I'm going to lock this pull request because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active contributions.
If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 5, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement New feature or request subsystem/tests Issues and feature requests related to the testing framework.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Emit failure reasons in debug logs
3 participants