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

Consider Displaying Test Step Number in CLI for Import Errors #287

Open
bendbennett opened this issue Feb 2, 2024 · 0 comments
Open

Consider Displaying Test Step Number in CLI for Import Errors #287

bendbennett opened this issue Feb 2, 2024 · 0 comments
Labels
enhancement New feature or request

Comments

@bendbennett
Copy link
Contributor

terraform-plugin-testing version

v1.6.0

Use cases

During execution of tests in which an error occurs during an import, the failing test step number is not displayed in the CLI output.

For example, using the following test:

func TestTest_TestStep_ProviderFactories_Import_External(t *testing.T) {
	id := "none"

	t.Parallel()

	Test(t, TestCase{
		ExternalProviders: map[string]ExternalProvider{
			"random": {
				Source: "registry.terraform.io/hashicorp/random",
			},
		},
		Steps: []TestStep{
			{
				Config:       `resource "random_password" "test" { length = 12 }`,
				ResourceName: "random_password.test",
				ImportState:  true,
				ImportStatePersist: true,
				ImportStateCheck: composeImportStateCheck(
					testCheckResourceAttrInstanceState(&id, "result", "Z=:cbrJE?Ltg"),
					testCheckResourceAttrInstanceState(&id, "length", "12"),
				),
			},
		},
	})
}

Generates the following error, which does not indicate the failing test step number:

    teststep_providers_test.go:2786: Resource specified by ResourceName couldn't be found: random_password.test

Attempted solutions

The test step number is present in the logs, re-running the same failing test with TF_LOG=TRACE generates the following output:

2024-02-02T11:04:20.405Z [TRACE] sdk.helper_resource: Using resource identifier for import identifier: test_name=TestTest_TestStep_ProviderFactories_Import_External test_terraform_path=/usr/local/bin/terraform test_working_directory=/var/folders/23/p8tx31c53rd16t1pjt03zndc0000gq/T/plugintest972934573 test_step_number=1
    teststep_providers_test.go:2786: Resource specified by ResourceName couldn't be found: random_password.test

The log contains test_step_number=1.

Proposal

Include the test step number in the error displayed by the CLI output.

@bendbennett bendbennett added the enhancement New feature or request label Feb 2, 2024
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

No branches or pull requests

1 participant