-
Notifications
You must be signed in to change notification settings - Fork 16
Add tests using ConfigFile
and ConfigDirectory
with plannable import
#465
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
Merged
Merged
Changes from all commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
2e6c321
Prepare to move test to a directory
bbasata 288ec26
Move test to import_test package
bbasata e924715
Extract testprovider resource from test
bbasata 4b76aba
More test provider extraction
bbasata f7076a9
Add a test expecting fail when plannable import is not supported
bbasata 6865074
importstate: a working example of ImportState as the first TestStep
bbasata 70f740d
importstate: a working example of ImportBlockWithId as the first Test…
bbasata d8f5ccb
make generate
bbasata 5e5f6d6
Merge remote-tracking branch 'origin/main' into import-as-first-test-…
bbasata 0872e07
Use PlanChecks
bbasata 5d6bf83
Simpler test names
bbasata f45d8fe
Tidy comment
bbasata a36cde2
wip
bbasata 3b822d6
fixup! wip
bbasata 3134be2
Extract functions
bbasata 99f1fae
Add tests for import block in ConfigFile and ConfigDirectory
bbasata 42f36b7
Mark test helper function
bbasata 024ac49
minimize diff
bbasata 794a566
Update helper/resource/testing.go
bbasata a6d4bf2
Use Static{File,Directory} helper functions
bbasata 9d3ad72
Merge branch 'main' into import-config-file-and-directory
bbasata File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
46 changes: 46 additions & 0 deletions
46
helper/resource/importstate/import_block_in_config_directory_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package importstate_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/config" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
|
||
r "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func Test_ImportBlock_InConfigDirectory(t *testing.T) { | ||
t.Parallel() | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later | ||
}, | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{ | ||
Resources: map[string]testprovider.Resource{ | ||
"examplecloud_container": examplecloudResource(), | ||
}, | ||
}), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
ConfigDirectory: config.StaticDirectory(`testdata/1`), | ||
}, | ||
{ | ||
ResourceName: "examplecloud_container.test", | ||
ImportState: true, | ||
ImportStateKind: r.ImportBlockWithID, | ||
ImportStateVerify: true, | ||
ConfigDirectory: config.StaticDirectory(`testdata/2`), | ||
}, | ||
}, | ||
}) | ||
} |
46 changes: 46 additions & 0 deletions
46
helper/resource/importstate/import_block_in_config_file_test.go
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
// Copyright (c) HashiCorp, Inc. | ||
// SPDX-License-Identifier: MPL-2.0 | ||
|
||
package importstate_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/hashicorp/terraform-plugin-go/tfprotov6" | ||
|
||
"github.com/hashicorp/terraform-plugin-testing/config" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider" | ||
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver" | ||
"github.com/hashicorp/terraform-plugin-testing/tfversion" | ||
|
||
r "github.com/hashicorp/terraform-plugin-testing/helper/resource" | ||
) | ||
|
||
func Test_ImportBlock_InConfigFile(t *testing.T) { | ||
t.Parallel() | ||
|
||
r.UnitTest(t, r.TestCase{ | ||
TerraformVersionChecks: []tfversion.TerraformVersionCheck{ | ||
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later | ||
}, | ||
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){ | ||
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{ | ||
Resources: map[string]testprovider.Resource{ | ||
"examplecloud_container": examplecloudResource(), | ||
}, | ||
}), | ||
}, | ||
Steps: []r.TestStep{ | ||
{ | ||
ConfigFile: config.StaticFile(`testdata/1/examplecloud_container.tf`), | ||
}, | ||
{ | ||
ResourceName: "examplecloud_container.test", | ||
ImportState: true, | ||
ImportStateKind: r.ImportBlockWithID, | ||
ImportStateVerify: true, | ||
ConfigFile: config.StaticFile(`testdata/2/examplecloud_container_import.tf`), | ||
}, | ||
}, | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
helper/resource/importstate/testdata/1/examplecloud_container.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
resource "examplecloud_container" "test" { | ||
name = "somevalue" | ||
location = "westeurope" | ||
} |
12 changes: 12 additions & 0 deletions
12
helper/resource/importstate/testdata/2/examplecloud_container_import.tf
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
# Copyright (c) HashiCorp, Inc. | ||
# SPDX-License-Identifier: MPL-2.0 | ||
|
||
resource "examplecloud_container" "test" { | ||
name = "somevalue" | ||
location = "westeurope" | ||
} | ||
|
||
import { | ||
to = examplecloud_container.test | ||
id = "examplecloud_container.test" | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.