From 36d34135ad298324ec609c75e90d60a6e65d0392 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Thu, 6 Jul 2023 10:22:57 -0400 Subject: [PATCH] replace remaining types in tests --- internal/backend/local/backend_apply_test.go | 31 +++++----- internal/backend/local/backend_plan_test.go | 39 +++++++------ .../backend/local/backend_refresh_test.go | 56 +++++++++++-------- internal/backend/remote/testing.go | 10 ++-- internal/cloud/testing.go | 10 ++-- internal/command/jsonformat/plan_test.go | 14 +++-- internal/command/jsonformat/state_test.go | 4 +- internal/command/jsonplan/values_test.go | 19 ++++--- internal/command/jsonstate/state_test.go | 29 ++++++---- internal/command/views/plan_test.go | 4 +- internal/command/views/show_test.go | 13 +++-- 11 files changed, 133 insertions(+), 96 deletions(-) diff --git a/internal/backend/local/backend_apply_test.go b/internal/backend/local/backend_apply_test.go index 5ae4fd4d4f..1997a7dd32 100644 --- a/internal/backend/local/backend_apply_test.go +++ b/internal/backend/local/backend_apply_test.go @@ -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}, + }, }, }, }, diff --git a/internal/backend/local/backend_plan_test.go b/internal/backend/local/backend_plan_test.go index ee213df6d4..c6f906cf88 100644 --- a/internal/backend/local/backend_plan_test.go +++ b/internal/backend/local/backend_plan_test.go @@ -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}, + }, }, }, }, diff --git a/internal/backend/local/backend_refresh_test.go b/internal/backend/local/backend_refresh_test.go index eaf7e7d760..1d9c197a87 100644 --- a/internal/backend/local/backend_refresh_test.go +++ b/internal/backend/local/backend_refresh_test.go @@ -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}, + }, }, }, }, diff --git a/internal/backend/remote/testing.go b/internal/backend/remote/testing.go index 0721087099..282afc0dba 100644 --- a/internal/backend/remote/testing.go +++ b/internal/backend/remote/testing.go @@ -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}, + }, }, }, }, diff --git a/internal/cloud/testing.go b/internal/cloud/testing.go index 119f57d509..672840092f 100644 --- a/internal/cloud/testing.go +++ b/internal/cloud/testing.go @@ -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}, + }, }, }, }, diff --git a/internal/command/jsonformat/plan_test.go b/internal/command/jsonformat/plan_test.go index 061fad67ab..d9b2fa7f09 100644 --- a/internal/command/jsonformat/plan_test.go +++ b/internal/command/jsonformat/plan_test.go @@ -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, + }, }, }, }, diff --git a/internal/command/jsonformat/state_test.go b/internal/command/jsonformat/state_test.go index 716650141d..e455ec8d12 100644 --- a/internal/command/jsonformat/state_test.go +++ b/internal/command/jsonformat/state_test.go @@ -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(), }, } } diff --git a/internal/command/jsonplan/values_test.go b/internal/command/jsonplan/values_test.go index 2ac7ec5a5f..099d865ab1 100644 --- a/internal/command/jsonplan/values_test.go +++ b/internal/command/jsonplan/values_test.go @@ -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, - }, }, }, } diff --git a/internal/command/jsonstate/state_test.go b/internal/command/jsonstate/state_test.go index 27544de678..33ad46f092 100644 --- a/internal/command/jsonstate/state_test.go +++ b/internal/command/jsonstate/state_test.go @@ -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}, + }, }, }, }, diff --git a/internal/command/views/plan_test.go b/internal/command/views/plan_test.go index 0011f6b54f..df9fe3a27b 100644 --- a/internal/command/views/plan_test.go +++ b/internal/command/views/plan_test.go @@ -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(), }, } } diff --git a/internal/command/views/show_test.go b/internal/command/views/show_test.go index 2101b8252c..7524cfa88c 100644 --- a/internal/command/views/show_test.go +++ b/internal/command/views/show_test.go @@ -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}, + }, }, }, },