Skip to content

Conversation

@SBGoods
Copy link
Contributor

@SBGoods SBGoods commented Oct 20, 2025

Related Issue

Relates: #561

Description

Refactors query test step logic into testStepNewQuery() allowing query errors to be used with ExpectError.

Rollback Plan

  • If a change needs to be reverted, we will roll out an update to the code within 7 days.

Changes to Security Controls

Are there any changes to security controls (access controls, encryption, logging) in this pull request? If so, explain.
N/A

@SBGoods SBGoods changed the title [DRAFT] query: handle query errors in RunQueryChecks() query: handle query errors in RunQueryChecks() Oct 27, 2025
@SBGoods SBGoods marked this pull request as ready for review October 27, 2025 14:00
@SBGoods SBGoods requested a review from a team as a code owner October 27, 2025 14:00
@SBGoods SBGoods changed the title query: handle query errors in RunQueryChecks() query: refactor query test step logic into testStepNewQuery() Oct 28, 2025
Copy link
Member

@austinvalle austinvalle left a comment

Choose a reason for hiding this comment

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

Just one non-blocking note, code LGTM 👍🏻

}
}
`,
ExpectError: regexp.MustCompile(`Diagnostic summary`),
Copy link
Member

Choose a reason for hiding this comment

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

Something worth noting that might not be an immediate problem, but more of a potential future confusion for folks familiar with ExpectError

Since Query is using the machine readable output, the error message it is running the regex on with that mode is the formatted %+v of the diagnostics, which is different then other modes that use the formatted Terraform CLI output of the diagnostics. That can make the output hard to read / different to match than the other modes:

--- FAIL: TestQuery_ExpectError_ValidationError (0.49s)
    /Users/austin.valle/code/terraform-plugin-testing/helper/resource/query/query_test.go:111: Step 2/2 error running query, expected an error with pattern (Not the correct diagnostic summary), no match on: running terraform query command returned diagnostics: [{baseLogMessage:{Lvl:error Msg:Error: Diagnostic summary Time:2025-10-29 09:10:02.151561 -0400 EDT} Diagnostic:{Severity:error Summary:Diagnostic summary Detail:Diagnostic details Range:0x140004547c0 Snippet:0x14000030640}} {baseLogMessage:{Lvl:error Msg:Error: Diagnostic summary Time:2025-10-29 09:10:02.151735 -0400 EDT} Diagnostic:{Severity:error Summary:Diagnostic summary Detail:Diagnostic details Range:0x14000454900 Snippet:0x14000030690}}]

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeah, that's a good point. Maybe we should introduce a string formatter for machine readable error messaging in a follow-up PR.

@SBGoods SBGoods merged commit 203e6cc into main Oct 29, 2025
43 checks passed
@SBGoods SBGoods deleted the SBGoods/query-expect-error branch October 29, 2025 15:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants