Skip to content

Commit 99f1fae

Browse files
committed
Add tests for import block in ConfigFile and ConfigDirectory
1 parent 3134be2 commit 99f1fae

File tree

4 files changed

+119
-0
lines changed

4 files changed

+119
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package importstate_test
5+
6+
import (
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
10+
11+
"github.com/hashicorp/terraform-plugin-testing/config"
12+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
13+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
14+
"github.com/hashicorp/terraform-plugin-testing/tfversion"
15+
16+
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
17+
)
18+
19+
func Test_ImportBlock_InConfigDirectory(t *testing.T) {
20+
t.Parallel()
21+
22+
r.UnitTest(t, r.TestCase{
23+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
24+
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later
25+
},
26+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
27+
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
28+
Resources: map[string]testprovider.Resource{
29+
"examplecloud_container": examplecloudResource(),
30+
},
31+
}),
32+
},
33+
Steps: []r.TestStep{
34+
{
35+
ConfigDirectory: func(config.TestStepConfigRequest) string {
36+
return `testdata/1`
37+
},
38+
},
39+
{
40+
ResourceName: "examplecloud_container.test",
41+
ImportState: true,
42+
ImportStateKind: r.ImportBlockWithID,
43+
ImportStateVerify: true,
44+
ConfigDirectory: func(config.TestStepConfigRequest) string {
45+
return `testdata/2`
46+
},
47+
},
48+
},
49+
})
50+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
// Copyright (c) HashiCorp, Inc.
2+
// SPDX-License-Identifier: MPL-2.0
3+
4+
package importstate_test
5+
6+
import (
7+
"testing"
8+
9+
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
10+
11+
"github.com/hashicorp/terraform-plugin-testing/config"
12+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testprovider"
13+
"github.com/hashicorp/terraform-plugin-testing/internal/testing/testsdk/providerserver"
14+
"github.com/hashicorp/terraform-plugin-testing/tfversion"
15+
16+
r "github.com/hashicorp/terraform-plugin-testing/helper/resource"
17+
)
18+
19+
func Test_ImportBlock_InConfigFile(t *testing.T) {
20+
t.Parallel()
21+
22+
r.UnitTest(t, r.TestCase{
23+
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
24+
tfversion.SkipBelow(tfversion.Version1_5_0), // ImportBlockWithID requires Terraform 1.5.0 or later
25+
},
26+
ProtoV6ProviderFactories: map[string]func() (tfprotov6.ProviderServer, error){
27+
"examplecloud": providerserver.NewProviderServer(testprovider.Provider{
28+
Resources: map[string]testprovider.Resource{
29+
"examplecloud_container": examplecloudResource(),
30+
},
31+
}),
32+
},
33+
Steps: []r.TestStep{
34+
{
35+
ConfigFile: func(config.TestStepConfigRequest) string {
36+
return `testdata/1/examplecloud_container.tf`
37+
},
38+
},
39+
{
40+
ResourceName: "examplecloud_container.test",
41+
ImportState: true,
42+
ImportStateKind: r.ImportBlockWithID,
43+
ImportStateVerify: true,
44+
ConfigFile: func(config.TestStepConfigRequest) string {
45+
return `testdata/2/examplecloud_container_import.tf`
46+
},
47+
},
48+
},
49+
})
50+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
resource "examplecloud_container" "test" {
5+
name = "somevalue"
6+
location = "westeurope"
7+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
resource "examplecloud_container" "test" {
5+
name = "somevalue"
6+
location = "westeurope"
7+
}
8+
9+
import {
10+
to = examplecloud_container.test
11+
id = "examplecloud_container.test"
12+
}

0 commit comments

Comments
 (0)