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/statemgr"
"github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/internal/terraform"
"github.com/hashicorp/terraform/internal/tfdiags"
)
@ -123,7 +122,7 @@ func TestLocal_applyCheck(t *testing.T) {
func TestLocal_applyEmptyDir(t *testing.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")})}
op, configCleanup, done := testOperationApply(t, "./testdata/empty")
@ -157,7 +156,7 @@ func TestLocal_applyEmptyDir(t *testing.T) {
func TestLocal_applyEmptyDirDestroy(t *testing.T) {
b := TestLocal(t)
p := TestLocalProvider(t, b, "test", &terraform.ProviderSchema{})
p := TestLocalProvider(t, b, "test", providers.Schemas{})
p.ApplyResourceChangeResponse = &providers.ApplyResourceChangeResponse{}
op, configCleanup, done := testOperationApply(t, "./testdata/empty")
@ -187,12 +186,14 @@ func TestLocal_applyEmptyDirDestroy(t *testing.T) {
func TestLocal_applyError(t *testing.T) {
b := TestLocal(t)
schema := &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
schema := providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true},
"id": {Type: cty.String, Computed: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"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
// configuration in testdata/apply . This schema should be
// assigned to a mock provider named "test".
func applyFixtureSchema() *terraform.ProviderSchema {
return &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
func applyFixtureSchema() providers.Schemas {
return providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true},
"id": {Type: cty.String, Computed: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"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/plans"
"github.com/hashicorp/terraform/internal/plans/planfile"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/terminal"
"github.com/hashicorp/terraform/internal/terraform"
@ -88,7 +89,7 @@ func TestLocal_planInAutomation(t *testing.T) {
func TestLocal_planNoConfig(t *testing.T) {
b := TestLocal(t)
TestLocalProvider(t, b, "test", &terraform.ProviderSchema{})
TestLocalProvider(t, b, "test", providers.Schemas{})
op, configCleanup, done := testOperationPlan(t, "./testdata/empty")
defer configCleanup()
@ -854,30 +855,34 @@ func testReadPlan(t *testing.T, path string) *plans.Plan {
// planFixtureSchema returns a schema suitable for processing the
// configuration in testdata/plan . This schema should be
// assigned to a mock provider named "test".
func planFixtureSchema() *terraform.ProviderSchema {
return &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
func planFixtureSchema() providers.Schemas {
return providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true},
},
BlockTypes: map[string]*configschema.NestedBlock{
"network_interface": {
Nesting: configschema.NestingList,
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"device_index": {Type: cty.Number, Optional: true},
"description": {Type: cty.String, Optional: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true},
},
BlockTypes: map[string]*configschema.NestedBlock{
"network_interface": {
Nesting: configschema.NestingList,
Block: configschema.Block{
Attributes: map[string]*configschema.Attribute{
"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": {
Attributes: map[string]*configschema.Attribute{
"filter": {Type: cty.String, Required: true},
Block: &configschema.Block{
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) {
b := TestLocal(t)
schema := &terraform.ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
schema := providers.Schemas{
Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
},
},
ResourceTypes: map[string]*configschema.Block{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
"foo": {Type: cty.String, Optional: true},
"ami": {Type: cty.String, Optional: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: 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) {
b := TestLocal(t)
schema := &terraform.ProviderSchema{
Provider: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
schema := providers.Schemas{
Provider: providers.Schema{
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"value": {Type: cty.String, Optional: true},
},
},
},
ResourceTypes: map[string]*configschema.Block{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
"ami": {Type: cty.String, Optional: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"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
// configuration in testdata/refresh . This schema should be
// assigned to a mock provider named "test".
func refreshFixtureSchema() *terraform.ProviderSchema {
return &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
func refreshFixtureSchema() providers.Schemas {
return providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"ami": {Type: cty.String, Optional: true},
"id": {Type: cty.String, Computed: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"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)
// Add a test provider to the local backend.
p := backendLocal.TestLocalProvider(t, b, "null", &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
p := backendLocal.TestLocalProvider(t, b, "null", providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"null_resource": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
Block: &configschema.Block{
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)
// Add a test provider to the local backend.
p := backendLocal.TestLocalProvider(t, b, "null", &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
p := backendLocal.TestLocalProvider(t, b, "null", providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"null_resource": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Computed: true},
Block: &configschema.Block{
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{
Providers: map[addrs.Provider]*providers.Schemas{
Providers: map[addrs.Provider]providers.Schemas{
src.ProviderAddr.Provider: {
ResourceTypes: map[string]*configschema.Block{
src.Addr.Resource.Resource.Type: tc.Schema,
ResourceTypes: map[string]providers.Schema{
src.Addr.Resource.Resource.Type: {
Block: tc.Schema,
},
},
DataSources: map[string]*configschema.Block{
src.Addr.Resource.Resource.Type: tc.Schema,
DataSources: map[string]providers.Schema{
src.Addr.Resource.Resource.Type: {
Block: tc.Schema,
},
},
},
},

View File

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

View File

@ -11,6 +11,7 @@ import (
"github.com/hashicorp/terraform/internal/addrs"
"github.com/hashicorp/terraform/internal/configs/configschema"
"github.com/hashicorp/terraform/internal/plans"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/terraform"
"github.com/zclconf/go-cty/cty"
)
@ -344,19 +345,19 @@ func TestMarshalPlanValuesNoopDeposed(t *testing.T) {
func testSchemas() *terraform.Schemas {
return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{
addrs.NewDefaultProvider("test"): &terraform.ProviderSchema{
ResourceTypes: map[string]*configschema.Block{
Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): providers.Schemas{
ResourceTypes: map[string]providers.Schema{
"test_thing": {
Attributes: map[string]*configschema.Attribute{
"woozles": {Type: cty.String, Optional: true, Computed: true},
"foozles": {Type: cty.String, Optional: true},
Version: 1,
Block: &configschema.Block{
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/configs/configschema"
"github.com/hashicorp/terraform/internal/lang/marks"
"github.com/hashicorp/terraform/internal/providers"
"github.com/hashicorp/terraform/internal/states"
"github.com/hashicorp/terraform/internal/terraform"
)
@ -807,25 +808,31 @@ func TestMarshalModules_parent_no_resources(t *testing.T) {
func testSchemas() *terraform.Schemas {
return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{
Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): {
ResourceTypes: map[string]*configschema.Block{
ResourceTypes: map[string]providers.Schema{
"test_thing": {
Attributes: map[string]*configschema.Attribute{
"woozles": {Type: cty.String, Optional: true, Computed: true},
"foozles": {Type: cty.String, Optional: true, Sensitive: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"woozles": {Type: cty.String, Optional: true, Computed: true},
"foozles": {Type: cty.String, Optional: true, Sensitive: true},
},
},
},
"test_instance": {
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Optional: true, Computed: true},
"foo": {Type: cty.String, Optional: true},
"bar": {Type: cty.String, Optional: true},
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Optional: true, Computed: true},
"foo": {Type: cty.String, Optional: true},
"bar": {Type: cty.String, Optional: true},
},
},
},
"test_map_attr": {
Attributes: map[string]*configschema.Attribute{
"data": {Type: cty.Map(cty.String), Optional: true, Computed: true, Sensitive: true},
Block: &configschema.Block{
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 {
provider := testProvider()
return &terraform.Schemas{
Providers: map[addrs.Provider]*terraform.ProviderSchema{
addrs.NewDefaultProvider("test"): provider.ProviderSchema(),
Providers: map[addrs.Provider]providers.Schemas{
addrs.NewDefaultProvider("test"): provider.GetProviderSchema(),
},
}
}

View File

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