Skip to content

Commit 7d17d64

Browse files
authored
Migrate cross-tests from input_cross_test.go to tests/provider_test.go (#2510)
This PR migrates our tests away from input_cross_tests.go to the public `crosstests.Create`, removing `runCreateInputCheck` in the process. The only tests removed were tests of `runCreateInputCheck` itself.
1 parent 93323f8 commit 7d17d64

File tree

7 files changed

+377
-604
lines changed

7 files changed

+377
-604
lines changed

pkg/internal/tests/cross-tests/assert.go

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package crosstests
33
import (
44
"github.com/hashicorp/go-cty/cty"
55
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
6+
"github.com/stretchr/testify/assert"
67
"github.com/stretchr/testify/require"
78
)
89

@@ -30,7 +31,7 @@ func assertValEqual(t T, name string, tfVal, pulVal any) {
3031
}
3132
}
3233

33-
func assertResourceDataEqual(t T, schema map[string]*schema.Schema, tfResult, puResult *schema.ResourceData) {
34+
func assertResourceDataEqual(t T, resourceSchema map[string]*schema.Schema, tfResult, puResult *schema.ResourceData) {
3435
// We are unable to assert that both providers were configured with the exact same
3536
// data. Type information doesn't line up in the simple case. This just doesn't work:
3637
//
@@ -41,7 +42,17 @@ func assertResourceDataEqual(t T, schema map[string]*schema.Schema, tfResult, pu
4142
assertCtyValEqual(t, "RawPlan", tfResult.GetRawPlan(), puResult.GetRawPlan())
4243
assertCtyValEqual(t, "RawState", tfResult.GetRawState(), puResult.GetRawState())
4344

44-
for k := range schema {
45+
for _, timeout := range []string{
46+
schema.TimeoutCreate,
47+
schema.TimeoutRead,
48+
schema.TimeoutUpdate,
49+
schema.TimeoutDelete,
50+
schema.TimeoutDefault,
51+
} {
52+
assert.Equal(t, tfResult.Timeout(timeout), puResult.Timeout(timeout), "timeout %s", timeout)
53+
}
54+
55+
for k := range resourceSchema {
4556
// TODO: make this recursive
4657
tfVal := tfResult.Get(k)
4758
pulVal := puResult.Get(k)

pkg/internal/tests/cross-tests/configure.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ func MakeConfigure(
3535
provider map[string]*schema.Schema, tfConfig cty.Value, puConfig resource.PropertyMap,
3636
options ...ConfigureOption,
3737
) func(*testing.T) {
38-
return func(t *testing.T) { Configure(t, provider, tfConfig, puConfig, options...) }
38+
return func(t *testing.T) {
39+
t.Parallel()
40+
Configure(t, provider, tfConfig, puConfig, options...)
41+
}
3942
}
4043

4144
// Configure validates that a Terraform provider witnesses the same input when:

pkg/internal/tests/cross-tests/create.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ package crosstests
1515

1616
import (
1717
"context"
18+
"testing"
1819

1920
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
2021
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -29,6 +30,17 @@ import (
2930
shimv2 "github.com/pulumi/pulumi-terraform-bridge/v3/pkg/tfshim/sdk-v2"
3031
)
3132

33+
// MakeCreate is a helper function for calling [Create] in [testing.T.Run] subcases.
34+
func MakeCreate(
35+
resource map[string]*schema.Schema, tfConfig cty.Value, puConfig resource.PropertyMap,
36+
options ...CreateOption,
37+
) func(t *testing.T) {
38+
return func(t *testing.T) {
39+
t.Parallel()
40+
Create(t, resource, tfConfig, puConfig, options...)
41+
}
42+
}
43+
3244
// Create validates that a Terraform provider witnesses the same input when:
3345
// - invoked directly with HCL on tfConfig
3446
// - bridged and invoked via Pulumi YAML on puConfig

pkg/internal/tests/cross-tests/input_check.go

Lines changed: 0 additions & 46 deletions
This file was deleted.

0 commit comments

Comments
 (0)