Skip to content

Commit

Permalink
Port over more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
iwahbe committed Oct 24, 2024
1 parent 6c289a3 commit b7a98e3
Show file tree
Hide file tree
Showing 3 changed files with 85 additions and 100 deletions.
5 changes: 4 additions & 1 deletion pkg/internal/tests/cross-tests/configure.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,10 @@ func MakeConfigure(
provider map[string]*schema.Schema, tfConfig cty.Value, puConfig resource.PropertyMap,
options ...ConfigureOption,
) func(*testing.T) {
return func(t *testing.T) { Configure(t, provider, tfConfig, puConfig, options...) }
return func(t *testing.T) {
t.Parallel()
Configure(t, provider, tfConfig, puConfig, options...)
}
}

// Configure validates that a Terraform provider witnesses the same input when:
Expand Down
99 changes: 0 additions & 99 deletions pkg/internal/tests/cross-tests/input_cross_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,30 +101,6 @@ func TestInputsEqualObjectBasic(t *testing.T) {
}
}

// Isolated from rapid-generated tests
func TestInputsEmptyString(t *testing.T) {
runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"f0": {
Type: schema.TypeString,
Required: true,
},
},
},
Config: tftypes.NewValue(
tftypes.Object{
AttributeTypes: map[string]tftypes.Type{
"f0": tftypes.String,
},
},
map[string]tftypes.Value{
"f0": tftypes.NewValue(tftypes.String, ""),
},
),
})
}

func TestExplicitNilList(t *testing.T) {
t0 := tftypes.Map{ElementType: tftypes.Number}
t1 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
Expand Down Expand Up @@ -307,78 +283,3 @@ func TestInputsNestedBlocksEmpty(t *testing.T) {
})
}
}

func TestEmptySetOfEmptyObjects(t *testing.T) {
t1 := tftypes.Object{}
t0 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"d3f0": tftypes.Set{ElementType: t1},
}}
config := tftypes.NewValue(t0, map[string]tftypes.Value{
"d3f0": tftypes.NewValue(tftypes.Set{ElementType: t1}, []tftypes.Value{}),
})

runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{}},
},
},
},
Config: config,
})
}

func TestMap(t *testing.T) {
t0 := tftypes.Map{ElementType: tftypes.String}
t1 := tftypes.Object{AttributeTypes: map[string]tftypes.Type{
"tags": t0,
}}
mapVal := tftypes.NewValue(t0, map[string]tftypes.Value{
"key": tftypes.NewValue(tftypes.String, "val"),
"key2": tftypes.NewValue(tftypes.String, "val2"),
})
config := tftypes.NewValue(t1, map[string]tftypes.Value{
"tags": mapVal,
})

runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Optional: true,
Type: schema.TypeString,
},
},
},
},
Config: config,
})
}

func TestTimeouts(t *testing.T) {
emptyConfig := tftypes.NewValue(tftypes.Object{}, map[string]tftypes.Value{})
runCreateInputCheck(t, inputTestCase{
Resource: &schema.Resource{
Schema: map[string]*schema.Schema{
"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Optional: true,
Type: schema.TypeString,
},
},
},
Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(time.Duration(120)),
},
},
Config: emptyConfig,
})
}
81 changes: 81 additions & 0 deletions pkg/tfbridge/tests/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import (
"math"
"strconv"
"testing"
"time"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
"github.com/pulumi/providertest/replay"
Expand Down Expand Up @@ -271,6 +272,86 @@ func TestCreateDoesNotPanicWithStateUpgraders(t *testing.T) {
)
}

func TestTimeouts(t *testing.T) {
t.Parallel()
crosstests.Create(t,
map[string]*schema.Schema{
"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Optional: true,
Type: schema.TypeString,
},
},
},
cty.EmptyObjectVal,
crosstests.InferPulumiValue(),
crosstests.CreateTimeout(&schema.ResourceTimeout{
Create: schema.DefaultTimeout(time.Duration(120)),
}),
)
}

func TestMap(t *testing.T) {
t.Parallel()

crosstests.Create(t,
map[string]*schema.Schema{
"tags": {
Type: schema.TypeMap,
Optional: true,
Elem: &schema.Schema{
Optional: true,
Type: schema.TypeString,
},
},
},
cty.ObjectVal(map[string]cty.Value{
"tags": cty.MapVal(map[string]cty.Value{
"key": cty.StringVal("val"),
"key2": cty.StringVal("val2"),
}),
}),
crosstests.InferPulumiValue(),
)
}

func TestEmptySetOfEmptyObjects(t *testing.T) {
t.Parallel()

crosstests.Create(t,
map[string]*schema.Schema{
"d3f0": {
Type: schema.TypeSet,
Optional: true,
Elem: &schema.Resource{Schema: map[string]*schema.Schema{}},
},
},
cty.ObjectVal(map[string]cty.Value{
"d3f0": cty.SetValEmpty(cty.EmptyObject),
}),
crosstests.InferPulumiValue(),
)
}

func TestInputsEmptyString(t *testing.T) {
t.Parallel()

crosstests.Create(t,
map[string]*schema.Schema{
"f0": {
Type: schema.TypeString,
Required: true,
},
},
cty.ObjectVal(map[string]cty.Value{
"f0": cty.StringVal(""),
}),
crosstests.InferPulumiValue(),
)
}

// Demonstrating the use of the newTestProvider helper.
func TestWithNewTestProvider(t *testing.T) {
ctx := context.Background()
Expand Down

0 comments on commit b7a98e3

Please sign in to comment.