Skip to content

Consider Friendlier Naming When Persisting Working Directories #114

Open
@bflad

Description

@bflad

terraform-plugin-testing version

v1.2.0

Use cases

When using the TF_ACC_PERSIST_WORKING_DIR=1 environment variable, the directory is filled with some handy contents showing file artifacts during the testing:

$ tree /Users/bflad/test/testing55    
/Users/bflad/test/testing55

0 directories, 0 files

$ TF_ACC_PERSIST_WORKING_DIR=1 go test -count=1 -v ./internal/provider
=== RUN   TestExampleDataSource_basic
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/step_1
--- PASS: TestExampleDataSource_basic (0.54s)
=== RUN   TestExampleResource_basic
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/step_1
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/step_2
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/step_3
--- PASS: TestExampleResource_basic (0.89s)
PASS
ok      github.com/bflad/terraform-provider-framework/internal/provider 1.717s

$ tree /Users/bflad/test/testing55                                    
/Users/bflad/test/testing55
├── step_1
│   ├── work1058235289
│   │   ├── terraform.tfstate
│   │   ├── terraform.tfstate.backup
│   │   ├── terraform_plugin_test.tf
│   │   └── tfplan
│   └── work763334115
│       ├── terraform.tfstate
│       ├── terraform_plugin_test.tf
│       └── tfplan
├── step_2
│   └── work1058235289
│       ├── terraform.tfstate
│       ├── terraform.tfstate.backup
│       ├── terraform_plugin_test.tf
│       └── tfplan
├── step_3
│   └── work1058235289
│       ├── terraform.tfstate
│       ├── terraform.tfstate.backup
│       ├── terraform_plugin_test.tf
│       └── tfplan
├── work1058235289
│   ├── terraform.tfstate
│   ├── terraform.tfstate.backup
│   ├── terraform_plugin_test.tf
│   └── tfplan
├── work4271933255
│   ├── terraform.tfstate
│   └── terraform_plugin_test.tf
└── work763334115
    ├── terraform.tfstate
    ├── terraform.tfstate.backup
    ├── terraform_plugin_test.tf
    └── tfplan

11 directories, 25 files

However, from the directory structure, its unclear what each of the step and work* directories relate to in terms of the actual test that used those files.

Attempted solutions

Manually look through the config/plan/state files of each directory.

Proposal

Use (testing.T).Name() for the persisted working directory, then flip the directories so its TestName/step_#, e.g.

(note the changes in logging output as well)

$ tree /Users/bflad/test/testing55    
/Users/bflad/test/testing55

0 directories, 0 files

$ TF_ACC_PERSIST_WORKING_DIR=1 go test -count=1 -v ./internal/provider
=== RUN   TestExampleDataSource_basic
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleDataSource_basic/step_1
--- PASS: TestExampleDataSource_basic (0.54s)
=== RUN   TestExampleResource_basic
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_1
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_2
    testing_new.go:478: Working directory and files have been copied to: /Users/bflad/test/testing55/TestExampleResource_basic/step_3
--- PASS: TestExampleResource_basic (0.89s)
PASS
ok      github.com/bflad/terraform-provider-framework/internal/provider 1.717s

$ tree /Users/bflad/test/testing55
/Users/bflad/test/testing55
├── TestExampleDataSource_basic
│   └── step_1
│       ├── terraform.tfstate
│       ├── terraform_plugin_test.tf
│       └── tfplan
├── TestExampleResource_basic
│   ├── step_1
│   │   ├── terraform.tfstate
│   │   ├── terraform.tfstate.backup
│   │   ├── terraform_plugin_test.tf
│   │   └── tfplan
│   ├── step_2
│   │   ├── terraform.tfstate
│   │   ├── terraform.tfstate.backup
│   │   ├── terraform_plugin_test.tf
│   │   └── tfplan
│   └── step_3
│       ├── terraform.tfstate
│       ├── terraform.tfstate.backup
│       ├── terraform_plugin_test.tf
│       └── tfplan
├── work1058235289
│   ├── terraform.tfstate
│   ├── terraform.tfstate.backup
│   ├── terraform_plugin_test.tf
│   └── tfplan
├── work4271933255
│   ├── terraform.tfstate
│   └── terraform_plugin_test.tf
└── work763334115
    ├── terraform.tfstate
    ├── terraform.tfstate.backup
    ├── terraform_plugin_test.tf
    └── tfplan

10 directories, 25 files

References

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions