Skip to content

Conversation

@bbasata
Copy link
Collaborator

@bbasata bbasata commented Apr 1, 2025

In the plugin test framework, the core test step logic can indicate error in two different ways:

  • Return an error to the plugin test framework. This is the plugin test framework's facility for test authors to make positive or negative assertions for their provider's behavior. The test author supplies a TestStep.ExpectError to match on the error.

  • Call the Go testing library's t.Fatal. This is a lower-level error that a test author cannot make assertions on.

Core test step logic -- such as ImportState -- does both of these. The reason for using one or the other can be subtle and implicit. This poses a cognitive hurdle for contributing code changes. It also poses a hurdle to refactoring and breaking down large functions into smaller ones: does every smaller function need a testing.T parameter so that it can call t.Fatal?

This change separates concerns by introducing a type to embed the first type of error in a result object: framework: testOutcome.

Smaller functions can return two values: testOutcome and error, with the latter indicating a fatal error.

A test step's entry point -- such as testStepNewImportState -- is the one place that knows that an error translates to t.Fatalf and a failed testOutcome is simply returned to the plugin test framework.

bbasata added 2 commits April 1, 2025 10:32
In the plugin test framework, the core test step logic can indicate
error in two different ways:

- Return an `error` to the plugin test framework. This is the plugin
  test framework's facility for test authors to make positive or
  negative assertions for their provider's behavior. The test author
  supplies a `TestStep.ExpectError` to match on the error.

- Call the Go testing library's `t.Fatal`. This is a lower-level error
  that a test author cannot make assertions on.

Core test step logic -- such as `ImportState` -- does both of these. The
reason for using one or the other can be subtle and implicit. This
poses a cognitive hurdle for contributing code changes. It also poses a
hurdle to refactoring and breaking down large functions into smaller
ones: does every smaller function need a `testing.T` parameter so that
it can call `t.Fatal`?

This change separates concerns by introducing a type to embed the first
type of error in a result object: framework: `testOutcome`.

Smaller functions can return two values: `testOutcome` and `error`, with
the latter indicating a fatal error.

A test step's entry point -- such as `testStepNewImportState` -- is the
one place that knows that an `error` translates to `t.Fatalf` and a
failed `testOutcome` is simply returned to the plugin test framework.
@bbasata bbasata closed this Apr 2, 2025
@bbasata bbasata deleted the extract-verify-import-state branch April 2, 2025 13:10
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 2, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant