Skip to content

Commit

Permalink
internal: Replace tfsdk.Schema, tfsdk.Attribute, and tfsdk.Block usag…
Browse files Browse the repository at this point in the history
…e in unit testing (#575)

Reference: #132

Precursor for fully removing `tfsdk` package `Schema`, `Attribute`, and `Block` types. Replaced with `internal/testing/testschema`, `datasource/schema`, `provider/metaschema`, `provider/schema`, and `resource/schema` equivalents. Removed extraneous unit testing such as datasource versioning, provider Computed, etc. since it will be no longer possible to declare invalid schemas based on the concept.
  • Loading branch information
bflad committed Dec 13, 2022
1 parent 7afa862 commit 085f2f9
Show file tree
Hide file tree
Showing 79 changed files with 7,761 additions and 9,675 deletions.
9 changes: 4 additions & 5 deletions internal/fromproto5/applyresourcechange_test.go
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func TestApplyResourceChangeRequest(t *testing.T) {
Expand All @@ -37,11 +37,10 @@ func TestApplyResourceChangeRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
13 changes: 7 additions & 6 deletions internal/fromproto5/config_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
Expand All @@ -33,18 +34,18 @@ func TestConfig(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.StringType,
},
},
}

testFwSchemaInvalid := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchemaInvalid := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.BoolType,
},
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto5/configureprovider_test.go
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/provider"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
Expand All @@ -34,11 +34,10 @@ func TestConfigureProviderRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto5/importresourcestate_test.go
Expand Up @@ -10,20 +10,19 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)

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

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
13 changes: 7 additions & 6 deletions internal/fromproto5/plan_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
Expand All @@ -33,18 +34,18 @@ func TestPlan(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.StringType,
},
},
}

testFwSchemaInvalid := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchemaInvalid := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.BoolType,
},
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto5/planresourcechange_test.go
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func TestPlanResourceChangeRequest(t *testing.T) {
Expand All @@ -37,11 +37,10 @@ func TestPlanResourceChangeRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto5/prepareproviderconfig_test.go
Expand Up @@ -9,8 +9,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/provider/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
Expand All @@ -34,11 +34,10 @@ func TestValidateProviderConfigRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
16 changes: 7 additions & 9 deletions internal/fromproto5/providermeta_test.go
Expand Up @@ -8,8 +8,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/provider/metaschema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
Expand All @@ -33,20 +33,18 @@ func TestProviderMeta(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := metaschema.Schema{
Attributes: map[string]metaschema.Attribute{
"test_attribute": metaschema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}

testFwSchemaInvalid := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchemaInvalid := metaschema.Schema{
Attributes: map[string]metaschema.Attribute{
"test_attribute": metaschema.BoolAttribute{
Required: true,
Type: types.BoolType,
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto5/readresource_test.go
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func TestReadResourceRequest(t *testing.T) {
Expand All @@ -37,11 +37,10 @@ func TestReadResourceRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
13 changes: 7 additions & 6 deletions internal/fromproto5/state_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto5"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
Expand All @@ -33,18 +34,18 @@ func TestState(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.StringType,
},
},
}

testFwSchemaInvalid := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchemaInvalid := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.BoolType,
},
Expand Down
10 changes: 4 additions & 6 deletions internal/fromproto5/upgraderesourcestate_test.go
Expand Up @@ -10,19 +10,17 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
)

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

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto5/validateresourcetypeconfig_test.go
Expand Up @@ -10,8 +10,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov5"
"github.com/hashicorp/terraform-plugin-go/tftypes"
)
Expand All @@ -35,11 +35,10 @@ func TestValidateResourceTypeConfigRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov5.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
9 changes: 4 additions & 5 deletions internal/fromproto6/applyresourcechange_test.go
Expand Up @@ -14,8 +14,8 @@ import (
"github.com/hashicorp/terraform-plugin-framework/internal/fwserver"
"github.com/hashicorp/terraform-plugin-framework/internal/privatestate"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
)

func TestApplyResourceChangeRequest(t *testing.T) {
Expand All @@ -37,11 +37,10 @@ func TestApplyResourceChangeRequest(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := schema.Schema{
Attributes: map[string]schema.Attribute{
"test_attribute": schema.StringAttribute{
Required: true,
Type: types.StringType,
},
},
}
Expand Down
13 changes: 7 additions & 6 deletions internal/fromproto6/config_test.go
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/diag"
"github.com/hashicorp/terraform-plugin-framework/internal/fromproto6"
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-go/tfprotov6"
Expand All @@ -33,18 +34,18 @@ func TestConfig(t *testing.T) {
t.Fatalf("unexpected error calling tfprotov6.NewDynamicValue(): %s", err)
}

testFwSchema := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchema := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.StringType,
},
},
}

testFwSchemaInvalid := &tfsdk.Schema{
Attributes: map[string]tfsdk.Attribute{
"test_attribute": {
testFwSchemaInvalid := testschema.Schema{
Attributes: map[string]fwschema.Attribute{
"test_attribute": testschema.Attribute{
Required: true,
Type: types.BoolType,
},
Expand Down

0 comments on commit 085f2f9

Please sign in to comment.