replace remaining types in tests

This commit is contained in:
James Bardin 2023-07-06 10:22:57 -04:00
parent 4e8dd5866c
commit 36d34135ad
11 changed files with 133 additions and 96 deletions

View File

@ -27,7 +27,6 @@ import (
"github.com/hashicorp/terraform/internal/states" "github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/states/statemgr" "github.com/hashicorp/terraform/internal/states/statemgr"
"github.com/hashicorp/terraform/internal/terminal" "github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/internal/terraform"
"github.com/hashicorp/terraform/internal/tfdiags" "github.com/hashicorp/terraform/internal/tfdiags"
) )
@ -123,7 +122,7 @@ func TestLocal_applyCheck(t *testing.T) {
func TestLocal_applyEmptyDir(t *testing.T) { func TestLocal_applyEmptyDir(t *testing.T) {
b := TestLocal(t) b := TestLocal(t)
p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{}) p := TestLocalProvider(t, b, "test", providers.Schemas{})
p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{"id": cty.StringVal("yes")})} p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{NewState: cty.ObjectVal(map[string]cty.Value{"id": cty.StringVal("yes")})}
op, configCleanup, done := testOperationApply(t, "./testdata/empty") op, configCleanup, done := testOperationApply(t, "./testdata/empty")
@ -157,7 +156,7 @@ func TestLocal_applyEmptyDir(t *testing.T) {
func TestLocal_applyEmptyDirDestroy(t *testing.T) { func TestLocal_applyEmptyDirDestroy(t *testing.T) {
b := TestLocal(t) b := TestLocal(t)
p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{}) p := TestLocalProvider(t, b, "test", providers.Schemas{})
p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{} p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{}
op, configCleanup, done := testOperationApply(t, "./testdata/empty") op, configCleanup, done := testOperationApply(t, "./testdata/empty")
@ -187,12 +186,14 @@ func TestLocal_applyEmptyDirDestroy(t *testing.T) {
func TestLocal_applyError(t *testing.T) { func TestLocal_applyError(t *testing.T) {
b := TestLocal(t) b := TestLocal(t)
schema := &terraform.ProviderSchema{ schema := providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"ami": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "ami": {Type: cty.String, Optional: true},
"id": {Type: cty.String, Computed: true},
},
}, },
}, },
}, },
@ -386,13 +387,15 @@ func testOperationApply(t *testing.T, configDir string) (*backend.Operation, fun
// applyFixtureSchema returns a schema suitable for processing the // applyFixtureSchema returns a schema suitable for processing the
// configuration in testdata/apply . This schema should be // configuration in testdata/apply . This schema should be
// assigned to a mock provider named "test". // assigned to a mock provider named "test".
func applyFixtureSchema() *terraform.ProviderSchema { func applyFixtureSchema() providers.Schemas {
return &terraform.ProviderSchema{ return providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"ami": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "ami": {Type: cty.String, Optional: true},
"id": {Type: cty.String, Computed: true},
},
}, },
}, },
}, },

View File

@ -20,6 +20,7 @@ import (
"github.com/hashicorp/terraform/internal/initwd" "github.com/hashicorp/terraform/internal/initwd"
"github.com/hashicorp/terraform/internal/plans" "github.com/hashicorp/terraform/internal/plans"
"github.com/hashicorp/terraform/internal/plans/planfile" "github.com/hashicorp/terraform/internal/plans/planfile"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/states" "github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/terminal" "github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/internal/terraform" "github.com/hashicorp/terraform/internal/terraform"
@ -88,7 +89,7 @@ func TestLocal_planInAutomation(t *testing.T) {
func TestLocal_planNoConfig(t *testing.T) { func TestLocal_planNoConfig(t *testing.T) {
b := TestLocal(t) b := TestLocal(t)
TestLocalProvider(t, b, "test", &terraform.ProviderSchema{}) TestLocalProvider(t, b, "test", providers.Schemas{})
op, configCleanup, done := testOperationPlan(t, "./testdata/empty") op, configCleanup, done := testOperationPlan(t, "./testdata/empty")
defer configCleanup() defer configCleanup()
@ -854,30 +855,34 @@ func testReadPlan(t *testing.T, path string) *plans.Plan {
// planFixtureSchema returns a schema suitable for processing the // planFixtureSchema returns a schema suitable for processing the
// configuration in testdata/plan . This schema should be // configuration in testdata/plan . This schema should be
// assigned to a mock provider named "test". // assigned to a mock provider named "test".
func planFixtureSchema() *terraform.ProviderSchema { func planFixtureSchema() providers.Schemas {
return &terraform.ProviderSchema{ return providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"ami": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
}, "ami": {Type: cty.String, Optional: true},
BlockTypes: map[string]*configschema.NestedBlock{ },
"network_interface": { BlockTypes: map[string]*configschema.NestedBlock{
Nesting: configschema.NestingList, "network_interface": {
Block: configschema.Block{ Nesting: configschema.NestingList,
Attributes: map[string]*configschema.Attribute{ Block: configschema.Block{
"device_index": {Type: cty.Number, Optional: true}, Attributes: map[string]*configschema.Attribute{
"description": {Type: cty.String, Optional: true}, "device_index": {Type: cty.Number, Optional: true},
"description": {Type: cty.String, Optional: true},
},
}, },
}, },
}, },
}, },
}, },
}, },
DataSources: map[string]*configschema.Block{ DataSources: map[string]providers.Schema{
"test_ds": { "test_ds": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"filter": {Type: cty.String, Required: true}, Attributes: map[string]*configschema.Attribute{
"filter": {Type: cty.String, Required: true},
},
}, },
}, },
}, },

View File

@ -63,18 +63,22 @@ test_instance.foo:
func TestLocal_refreshInput(t *testing.T) { func TestLocal_refreshInput(t *testing.T) {
b := TestLocal(t) b := TestLocal(t)
schema := &terraform.ProviderSchema{ schema := providers.Schemas{
Provider: &configschema.Block{ Provider: providers.Schema{
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"value": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"id": {Type: cty.String, Computed: true}, Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "id": {Type: cty.String, Computed: true},
"ami": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
"ami": {Type: cty.String, Optional: true},
},
}, },
}, },
}, },
@ -154,17 +158,21 @@ test_instance.foo:
func TestLocal_refreshValidateProviderConfigured(t *testing.T) { func TestLocal_refreshValidateProviderConfigured(t *testing.T) {
b := TestLocal(t) b := TestLocal(t)
schema := &terraform.ProviderSchema{ schema := providers.Schemas{
Provider: &configschema.Block{ Provider: providers.Schema{
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"value": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
}, },
}, },
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"id": {Type: cty.String, Computed: true}, Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true}, "id": {Type: cty.String, Computed: true},
"ami": {Type: cty.String, Optional: true},
},
}, },
}, },
}, },
@ -297,13 +305,15 @@ func testRefreshState() *states.State {
// refreshFixtureSchema returns a schema suitable for processing the // refreshFixtureSchema returns a schema suitable for processing the
// configuration in testdata/refresh . This schema should be // configuration in testdata/refresh . This schema should be
// assigned to a mock provider named "test". // assigned to a mock provider named "test".
func refreshFixtureSchema() *terraform.ProviderSchema { func refreshFixtureSchema() providers.Schemas {
return &terraform.ProviderSchema{ return providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"ami": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true}, "ami": {Type: cty.String, Optional: true},
"id": {Type: cty.String, Computed: true},
},
}, },
}, },
}, },

View File

@ -182,11 +182,13 @@ func testLocalBackend(t *testing.T, remote *Remote) backend.Enhanced {
b := backendLocal.NewWithBackend(remote) b := backendLocal.NewWithBackend(remote)
// Add a test provider to the local backend. // Add a test provider to the local backend.
p := backendLocal.TestLocalProvider(t, b, "null", &terraform.ProviderSchema{ p := backendLocal.TestLocalProvider(t, b, "null", providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"null_resource": { "null_resource": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"id": {Type: cty.String, Computed: true}, Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
},
}, },
}, },
}, },

View File

@ -345,11 +345,13 @@ func testLocalBackend(t *testing.T, cloud *Cloud) backend.Enhanced {
b := backendLocal.NewWithBackend(cloud) b := backendLocal.NewWithBackend(cloud)
// Add a test provider to the local backend. // Add a test provider to the local backend.
p := backendLocal.TestLocalProvider(t, b, "null", &terraform.ProviderSchema{ p := backendLocal.TestLocalProvider(t, b, "null", providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"null_resource": { "null_resource": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"id": {Type: cty.String, Computed: true}, Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
},
}, },
}, },
}, },

View File

@ -6987,13 +6987,17 @@ func runTestCases(t *testing.T, testCases map[string]testCase) {
} }
tfschemas := &terraform.Schemas{ tfschemas := &terraform.Schemas{
Providers: map[addrs.Provider]*providers.Schemas{ Providers: map[addrs.Provider]providers.Schemas{
src.ProviderAddr.Provider: { src.ProviderAddr.Provider: {
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
src.Addr.Resource.Resource.Type: tc.Schema, src.Addr.Resource.Resource.Type: {
Block: tc.Schema,
},
}, },
DataSources: map[string]*configschema.Block{ DataSources: map[string]providers.Schema{
src.Addr.Resource.Resource.Type: tc.Schema, src.Addr.Resource.Resource.Type: {
Block: tc.Schema,
},
}, },
}, },
}, },

View File

@ -156,8 +156,8 @@ func testProviderSchema() *providers.GetProviderSchemaResponse {
func testSchemas() *terraform.Schemas { func testSchemas() *terraform.Schemas {
provider := testProvider() provider := testProvider()
return &terraform.Schemas{ return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{ Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): provider.ProviderSchema(), addrs.NewDefaultProvider("test"): provider.GetProviderSchema(),
}, },
} }
} }

View File

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/internal/addrs" "github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs/configschema" "github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/plans" "github.com/hashicorp/terraform/internal/plans"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/terraform" "github.com/hashicorp/terraform/internal/terraform"
"github.com/zclconf/go-cty/cty" "github.com/zclconf/go-cty/cty"
) )
@ -344,19 +345,19 @@ func TestMarshalPlanValuesNoopDeposed(t *testing.T) {
func testSchemas() *terraform.Schemas { func testSchemas() *terraform.Schemas {
return &terraform.Schemas{ return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{ Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): &terraform.ProviderSchema{ addrs.NewDefaultProvider("test"): providers.Schemas{
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Version: 1,
"woozles": {Type: cty.String, Optional: true, Computed: true}, Block: &configschema.Block{
"foozles": {Type: cty.String, Optional: true}, Attributes: map[string]*configschema.Attribute{
"woozles": {Type: cty.String, Optional: true, Computed: true},
"foozles": {Type: cty.String, Optional: true},
},
}, },
}, },
}, },
ResourceTypeSchemaVersions: map[string]uint64{
"test_thing": 1,
},
}, },
}, },
} }

View File

@ -14,6 +14,7 @@ import (
"github.com/hashicorp/terraform/internal/addrs" "github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs/configschema" "github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/lang/marks" "github.com/hashicorp/terraform/internal/lang/marks"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/states" "github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/terraform" "github.com/hashicorp/terraform/internal/terraform"
) )
@ -807,25 +808,31 @@ func TestMarshalModules_parent_no_resources(t *testing.T) {
func testSchemas() *terraform.Schemas { func testSchemas() *terraform.Schemas {
return &terraform.Schemas{ return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{ Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): { addrs.NewDefaultProvider("test"): {
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_thing": { "test_thing": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"woozles": {Type: cty.String, Optional: true, Computed: true}, Attributes: map[string]*configschema.Attribute{
"foozles": {Type: cty.String, Optional: true, Sensitive: true}, "woozles": {Type: cty.String, Optional: true, Computed: true},
"foozles": {Type: cty.String, Optional: true, Sensitive: true},
},
}, },
}, },
"test_instance": { "test_instance": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"id": {Type: cty.String, Optional: true, Computed: true}, Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "id": {Type: cty.String, Optional: true, Computed: true},
"bar": {Type: cty.String, Optional: true}, "foo": {Type: cty.String, Optional: true},
"bar": {Type: cty.String, Optional: true},
},
}, },
}, },
"test_map_attr": { "test_map_attr": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"data": {Type: cty.Map(cty.String), Optional: true, Computed: true, Sensitive: true}, Attributes: map[string]*configschema.Attribute{
"data": {Type: cty.Map(cty.String), Optional: true, Computed: true, Sensitive: true},
},
}, },
}, },
}, },

View File

@ -133,8 +133,8 @@ func testPlanWithDatasource(t *testing.T) *plans.Plan {
func testSchemas() *terraform.Schemas { func testSchemas() *terraform.Schemas {
provider := testProvider() provider := testProvider()
return &terraform.Schemas{ return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{ Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): provider.ProviderSchema(), addrs.NewDefaultProvider("test"): provider.GetProviderSchema(),
}, },
} }
} }

View File

@ -13,6 +13,7 @@ import (
"github.com/hashicorp/terraform/internal/configs/configschema" "github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/initwd" "github.com/hashicorp/terraform/internal/initwd"
"github.com/hashicorp/terraform/internal/plans" "github.com/hashicorp/terraform/internal/plans"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/states" "github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/states/statefile" "github.com/hashicorp/terraform/internal/states/statefile"
"github.com/hashicorp/terraform/internal/terminal" "github.com/hashicorp/terraform/internal/terminal"
@ -130,13 +131,15 @@ func TestShowJSON(t *testing.T) {
v := NewShow(arguments.ViewJSON, view) v := NewShow(arguments.ViewJSON, view)
schemas := &terraform.Schemas{ schemas := &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{ Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): { addrs.NewDefaultProvider("test"): {
ResourceTypes: map[string]*configschema.Block{ ResourceTypes: map[string]providers.Schema{
"test_resource": { "test_resource": {
Attributes: map[string]*configschema.Attribute{ Block: &configschema.Block{
"id": {Type: cty.String, Optional: true, Computed: true}, Attributes: map[string]*configschema.Attribute{
"foo": {Type: cty.String, Optional: true}, "id": {Type: cty.String, Optional: true, Computed: true},
"foo": {Type: cty.String, Optional: true},
},
}, },
}, },
}, },