From a6d722590a06d193bba1f0966b96a4933c88edfd Mon Sep 17 00:00:00 2001 From: Benjamin Bennett Date: Fri, 14 Jul 2023 09:51:41 +0100 Subject: [PATCH] Refactoring to use TestServer.GetProviderSchemaResponse field (#176) --- .../unreleased/BUG FIXES-20230713-155423.yaml | 6 - .../unreleased/BUG FIXES-20230713-155511.yaml | 6 - .../unreleased/BUG FIXES-20230714-094529.yaml | 6 + .../unreleased/BUG FIXES-20230714-094547.yaml | 6 + internal/tf5testserver/tf5testserver.go | 43 +- internal/tf6testserver/tf6testserver.go | 43 +- .../mux_server_ApplyResourceChange_test.go | 13 +- .../mux_server_ConfigureProvider_test.go | 19 +- .../mux_server_GetProviderSchema_test.go | 650 ++++++++----- .../mux_server_ImportResourceState_test.go | 13 +- .../mux_server_PlanResourceChange_test.go | 73 +- .../mux_server_PrepareProviderConfig_test.go | 106 ++- .../mux_server_ReadDataSource_test.go | 13 +- tf5muxserver/mux_server_ReadResource_test.go | 13 +- tf5muxserver/mux_server_StopProvider_test.go | 21 +- .../mux_server_UpgradeResourceState_test.go | 13 +- ...ux_server_ValidateDataSourceConfig_test.go | 13 +- ..._server_ValidateResourceTypeConfig_test.go | 13 +- tf5muxserver/mux_server_test.go | 879 +++++++++--------- tf5to6server/tf5to6server_test.go | 185 ++-- .../mux_server_ApplyResourceChange_test.go | 13 +- .../mux_server_ConfigureProvider_test.go | 19 +- .../mux_server_GetProviderSchema_test.go | 650 ++++++++----- .../mux_server_ImportResourceState_test.go | 13 +- .../mux_server_PlanResourceChange_test.go | 73 +- .../mux_server_ReadDataSource_test.go | 13 +- tf6muxserver/mux_server_ReadResource_test.go | 13 +- tf6muxserver/mux_server_StopProvider_test.go | 20 +- .../mux_server_UpgradeResourceState_test.go | 13 +- ..._server_ValidateDataResourceConfig_test.go | 13 +- .../mux_server_ValidateProviderConfig_test.go | 109 ++- .../mux_server_ValidateResourceConfig_test.go | 13 +- tf6muxserver/mux_server_test.go | 879 +++++++++--------- tf6to5server/tf6to5server_test.go | 283 +++--- 34 files changed, 2484 insertions(+), 1774 deletions(-) delete mode 100644 .changes/unreleased/BUG FIXES-20230713-155423.yaml delete mode 100644 .changes/unreleased/BUG FIXES-20230713-155511.yaml create mode 100644 .changes/unreleased/BUG FIXES-20230714-094529.yaml create mode 100644 .changes/unreleased/BUG FIXES-20230714-094547.yaml diff --git a/.changes/unreleased/BUG FIXES-20230713-155423.yaml b/.changes/unreleased/BUG FIXES-20230713-155423.yaml deleted file mode 100644 index d47a5f2..0000000 --- a/.changes/unreleased/BUG FIXES-20230713-155423.yaml +++ /dev/null @@ -1,6 +0,0 @@ -kind: BUG FIXES -body: 'tf5muxserver: Include diagnostics returned from `server.GetProviderSchema()` - in `muxServer.GetProviderSchemaResponse`' -time: 2023-07-13T15:54:23.555736+01:00 -custom: - Issue: "176" diff --git a/.changes/unreleased/BUG FIXES-20230713-155511.yaml b/.changes/unreleased/BUG FIXES-20230713-155511.yaml deleted file mode 100644 index 8df4714..0000000 --- a/.changes/unreleased/BUG FIXES-20230713-155511.yaml +++ /dev/null @@ -1,6 +0,0 @@ -kind: BUG FIXES -body: 'tf6muxserver: Include diagnostics returned from `server.GetProviderSchema()` - in `muxServer.GetProviderSchemaResponse`' -time: 2023-07-13T15:55:11.144049+01:00 -custom: - Issue: "176" diff --git a/.changes/unreleased/BUG FIXES-20230714-094529.yaml b/.changes/unreleased/BUG FIXES-20230714-094529.yaml new file mode 100644 index 0000000..2744b2a --- /dev/null +++ b/.changes/unreleased/BUG FIXES-20230714-094529.yaml @@ -0,0 +1,6 @@ +kind: BUG FIXES +body: 'tf5muxserver: Ensure `GetProviderSchema` RPC diagnostics are properly returned + to Terraform' +time: 2023-07-14T09:45:29.631825+01:00 +custom: + Issue: "176" diff --git a/.changes/unreleased/BUG FIXES-20230714-094547.yaml b/.changes/unreleased/BUG FIXES-20230714-094547.yaml new file mode 100644 index 0000000..0ae41ee --- /dev/null +++ b/.changes/unreleased/BUG FIXES-20230714-094547.yaml @@ -0,0 +1,6 @@ +kind: BUG FIXES +body: 'tf6muxserver: Ensure `GetProviderSchema` RPC diagnostics are properly returned + to Terraform' +time: 2023-07-14T09:45:47.81872+01:00 +custom: + Issue: "176" diff --git a/internal/tf5testserver/tf5testserver.go b/internal/tf5testserver/tf5testserver.go index e5c5cdb..e1133dc 100644 --- a/internal/tf5testserver/tf5testserver.go +++ b/internal/tf5testserver/tf5testserver.go @@ -12,17 +12,12 @@ import ( var _ tfprotov5.ProviderServer = &TestServer{} type TestServer struct { - DataSourceSchemas map[string]*tfprotov5.Schema - ProviderMetaSchema *tfprotov5.Schema - ProviderSchema *tfprotov5.Schema - ResourceSchemas map[string]*tfprotov5.Schema - ServerCapabilities *tfprotov5.ServerCapabilities - ApplyResourceChangeCalled map[string]bool ConfigureProviderCalled bool - GetProviderSchemaCalled bool + GetProviderSchemaCalled bool + GetProviderSchemaResponse *tfprotov5.GetProviderSchemaResponse ImportResourceStateCalled map[string]bool @@ -65,22 +60,7 @@ func (s *TestServer) ConfigureProvider(_ context.Context, _ *tfprotov5.Configure func (s *TestServer) GetProviderSchema(_ context.Context, _ *tfprotov5.GetProviderSchemaRequest) (*tfprotov5.GetProviderSchemaResponse, error) { s.GetProviderSchemaCalled = true - - if s.DataSourceSchemas == nil { - s.DataSourceSchemas = make(map[string]*tfprotov5.Schema) - } - - if s.ResourceSchemas == nil { - s.ResourceSchemas = make(map[string]*tfprotov5.Schema) - } - - return &tfprotov5.GetProviderSchemaResponse{ - Provider: s.ProviderSchema, - ProviderMeta: s.ProviderMetaSchema, - ResourceSchemas: s.ResourceSchemas, - DataSourceSchemas: s.DataSourceSchemas, - ServerCapabilities: s.ServerCapabilities, - }, nil + return s.GetProviderSchemaResponse, nil } func (s *TestServer) ImportResourceState(_ context.Context, req *tfprotov5.ImportResourceStateRequest) (*tfprotov5.ImportResourceStateResponse, error) { @@ -162,20 +142,3 @@ func (s *TestServer) PrepareProviderConfig(_ context.Context, req *tfprotov5.Pre s.PrepareProviderConfigCalled = true return s.PrepareProviderConfigResponse, nil } - -type TestServerDiags struct { - *TestServer - Diagnostics []*tfprotov5.Diagnostic -} - -func (s *TestServerDiags) GetProviderSchema(ctx context.Context, req *tfprotov5.GetProviderSchemaRequest) (*tfprotov5.GetProviderSchemaResponse, error) { - resp, err := s.TestServer.GetProviderSchema(ctx, req) - - resp.Diagnostics = append(resp.Diagnostics, s.Diagnostics...) - - return resp, err -} - -func (s *TestServerDiags) ProviderServer() tfprotov5.ProviderServer { - return s -} diff --git a/internal/tf6testserver/tf6testserver.go b/internal/tf6testserver/tf6testserver.go index fe5c4e0..2854714 100644 --- a/internal/tf6testserver/tf6testserver.go +++ b/internal/tf6testserver/tf6testserver.go @@ -12,17 +12,12 @@ import ( var _ tfprotov6.ProviderServer = &TestServer{} type TestServer struct { - DataSourceSchemas map[string]*tfprotov6.Schema - ProviderMetaSchema *tfprotov6.Schema - ProviderSchema *tfprotov6.Schema - ResourceSchemas map[string]*tfprotov6.Schema - ServerCapabilities *tfprotov6.ServerCapabilities - ApplyResourceChangeCalled map[string]bool ConfigureProviderCalled bool - GetProviderSchemaCalled bool + GetProviderSchemaCalled bool + GetProviderSchemaResponse *tfprotov6.GetProviderSchemaResponse ImportResourceStateCalled map[string]bool @@ -65,22 +60,7 @@ func (s *TestServer) ConfigureProvider(_ context.Context, _ *tfprotov6.Configure func (s *TestServer) GetProviderSchema(_ context.Context, _ *tfprotov6.GetProviderSchemaRequest) (*tfprotov6.GetProviderSchemaResponse, error) { s.GetProviderSchemaCalled = true - - if s.DataSourceSchemas == nil { - s.DataSourceSchemas = make(map[string]*tfprotov6.Schema) - } - - if s.ResourceSchemas == nil { - s.ResourceSchemas = make(map[string]*tfprotov6.Schema) - } - - return &tfprotov6.GetProviderSchemaResponse{ - Provider: s.ProviderSchema, - ProviderMeta: s.ProviderMetaSchema, - ResourceSchemas: s.ResourceSchemas, - DataSourceSchemas: s.DataSourceSchemas, - ServerCapabilities: s.ServerCapabilities, - }, nil + return s.GetProviderSchemaResponse, nil } func (s *TestServer) ImportResourceState(_ context.Context, req *tfprotov6.ImportResourceStateRequest) (*tfprotov6.ImportResourceStateResponse, error) { @@ -162,20 +142,3 @@ func (s *TestServer) ValidateProviderConfig(_ context.Context, req *tfprotov6.Va s.ValidateProviderConfigCalled = true return s.ValidateProviderConfigResponse, nil } - -type TestServerDiags struct { - *TestServer - Diagnostics []*tfprotov6.Diagnostic -} - -func (s *TestServerDiags) GetProviderSchema(ctx context.Context, req *tfprotov6.GetProviderSchemaRequest) (*tfprotov6.GetProviderSchemaResponse, error) { - resp, err := s.TestServer.GetProviderSchema(ctx, req) - - resp.Diagnostics = append(resp.Diagnostics, s.Diagnostics...) - - return resp, err -} - -func (s *TestServerDiags) ProviderServer() tfprotov6.ProviderServer { - return s -} diff --git a/tf5muxserver/mux_server_ApplyResourceChange_test.go b/tf5muxserver/mux_server_ApplyResourceChange_test.go index ef7d75c..6da21b1 100644 --- a/tf5muxserver/mux_server_ApplyResourceChange_test.go +++ b/tf5muxserver/mux_server_ApplyResourceChange_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerApplyResourceChange(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf5muxserver/mux_server_ConfigureProvider_test.go b/tf5muxserver/mux_server_ConfigureProvider_test.go index 7504895..6398ba2 100644 --- a/tf5muxserver/mux_server_ConfigureProvider_test.go +++ b/tf5muxserver/mux_server_ConfigureProvider_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -16,7 +17,23 @@ func TestMuxServerConfigureProvider(t *testing.T) { t.Parallel() ctx := context.Background() - testServers := [5]*tf5testserver.TestServer{{}, {}, {}, {}, {}} + testServers := [5]*tf5testserver.TestServer{ + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + } servers := []func() tfprotov5.ProviderServer{ testServers[0].ProviderServer, diff --git a/tf5muxserver/mux_server_GetProviderSchema_test.go b/tf5muxserver/mux_server_GetProviderSchema_test.go index 9acbf3a..146437c 100644 --- a/tf5muxserver/mux_server_GetProviderSchema_test.go +++ b/tf5muxserver/mux_server_GetProviderSchema_test.go @@ -30,227 +30,231 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "combined": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - }, - }, - }, - }, - }, - ProviderMetaSchema: &tfprotov5.Schema{ - Version: 4, - Block: &tfprotov5.SchemaBlock{ - Version: 4, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "module_id", - Type: tftypes.String, - Optional: true, - Description: "a unique identifier for the module", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - }, - }, - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, Block: &tfprotov5.SchemaBlock{ Version: 1, Attributes: []*tfprotov5.SchemaAttribute{ { - Name: "airspeed_velocity", - Type: tftypes.Number, + Name: "account_id", + Type: tftypes.String, Required: true, - Description: "the airspeed velocity of a swallow", + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, }, }, - }, - }, - "test_bar": { - Version: 1, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "name", - Type: tftypes.String, - Optional: true, - Description: "your name", - DescriptionKind: tfprotov5.StringKindPlain, - }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ { - Name: "color", - Type: tftypes.String, - Optional: true, - Description: "your favorite color", - DescriptionKind: tfprotov5.StringKindPlain, + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + }, }, }, }, }, - }, - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": { - Version: 1, + ProviderMeta: &tfprotov5.Schema{ + Version: 4, Block: &tfprotov5.SchemaBlock{ - Version: 1, + Version: 4, Attributes: []*tfprotov5.SchemaAttribute{ { - Name: "current_time", + Name: "module_id", Type: tftypes.String, - Computed: true, - Description: "the current time in RFC 3339 format", + Optional: true, + Description: "a unique identifier for the module", DescriptionKind: tfprotov5.StringKindPlain, }, }, }, }, - }, - }).ProviderServer, - (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": { + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "airspeed_velocity", + Type: tftypes.Number, + Required: true, + Description: "the airspeed velocity of a swallow", + DescriptionKind: tfprotov5.StringKindPlain, + }, + }, }, }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, - }, + "test_bar": { + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "name", + Type: tftypes.String, + Optional: true, + Description: "your name", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "color", + Type: tftypes.String, + Optional: true, + Description: "your favorite color", + DescriptionKind: tfprotov5.StringKindPlain, }, }, }, }, }, - }, - ProviderMetaSchema: &tfprotov5.Schema{ - Version: 4, - Block: &tfprotov5.SchemaBlock{ - Version: 4, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "module_id", - Type: tftypes.String, - Optional: true, - Description: "a unique identifier for the module", - DescriptionKind: tfprotov5.StringKindPlain, + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": { + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "current_time", + Type: tftypes.String, + Computed: true, + Description: "the current time in RFC 3339 format", + DescriptionKind: tfprotov5.StringKindPlain, + }, + }, }, }, }, }, - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_quux": { + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, Block: &tfprotov5.SchemaBlock{ Version: 1, Attributes: []*tfprotov5.SchemaAttribute{ { - Name: "a", + Name: "account_id", Type: tftypes.String, Required: true, Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ { - Name: "b", - Type: tftypes.String, - Required: true, + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + }, }, }, }, }, - }, - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_bar": { - Version: 1, + ProviderMeta: &tfprotov5.Schema{ + Version: 4, Block: &tfprotov5.SchemaBlock{ - Version: 1, + Version: 4, Attributes: []*tfprotov5.SchemaAttribute{ { - Name: "a", - Type: tftypes.Number, - Computed: true, - Description: "some field that's set by the provider", - DescriptionKind: tfprotov5.StringKindMarkdown, + Name: "module_id", + Type: tftypes.String, + Optional: true, + Description: "a unique identifier for the module", + DescriptionKind: tfprotov5.StringKindPlain, }, }, }, }, - "test_quux": { - Version: 1, - Block: &tfprotov5.SchemaBlock{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_quux": { Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "abc", - Type: tftypes.Number, - Computed: true, - Description: "some other field that's set by the provider", - DescriptionKind: tfprotov5.StringKindMarkdown, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "a", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "b", + Type: tftypes.String, + Required: true, + }, + }, + }, + }, + }, + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_bar": { + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "a", + Type: tftypes.Number, + Computed: true, + Description: "some field that's set by the provider", + DescriptionKind: tfprotov5.StringKindMarkdown, + }, + }, + }, + }, + "test_quux": { + Version: 1, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "abc", + Type: tftypes.Number, + Computed: true, + Description: "some other field that's set by the provider", + DescriptionKind: tfprotov5.StringKindMarkdown, + }, }, }, }, @@ -428,13 +432,17 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "duplicate-data-source-type": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -459,13 +467,17 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "duplicate-resource-type": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -487,52 +499,33 @@ func TestMuxServerGetProviderSchema(t *testing.T) { PlanDestroy: true, }, }, - "get-provider-schema-diagnostics": { - servers: []func() tfprotov5.ProviderServer{ - (&tf5testserver.TestServerDiags{ - TestServer: &tf5testserver.TestServer{}, - Diagnostics: []*tfprotov5.Diagnostic{ - { - Severity: tfprotov5.DiagnosticSeverityError, - Summary: "Summary", - Detail: "Detail", - }, - }, - }).ProviderServer, - }, - expectedDiagnostics: []*tfprotov5.Diagnostic{ - { - Severity: tfprotov5.DiagnosticSeverityError, - Summary: "Summary", - Detail: "Detail", - }, - }, - expectedDataSourceSchemas: map[string]*tfprotov5.Schema{}, - expectedResourceSchemas: map[string]*tfprotov5.Schema{}, - }, "provider-mismatch": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "testattribute1", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "testattribute1", + Type: tftypes.String, + Required: true, + }, }, }, }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "testattribute2", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "testattribute2", + Type: tftypes.String, + Required: true, + }, }, }, }, @@ -592,26 +585,30 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "provider-meta-mismatch": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderMetaSchema: &tfprotov5.Schema{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "testattribute1", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov5.Schema{ + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "testattribute1", + Type: tftypes.String, + Required: true, + }, }, }, }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderMetaSchema: &tfprotov5.Schema{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "testattribute2", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov5.Schema{ + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "testattribute2", + Type: tftypes.String, + Required: true, + }, }, }, }, @@ -671,16 +668,20 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "server-capabilities": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_with_server_capabilities": {}, - }, - ServerCapabilities: &tfprotov5.ServerCapabilities{ - PlanDestroy: true, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_with_server_capabilities": {}, + }, + ServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_without_server_capabilities": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_without_server_capabilities": {}, + }, }, }).ProviderServer, }, @@ -693,6 +694,195 @@ func TestMuxServerGetProviderSchema(t *testing.T) { PlanDestroy: true, }, }, + "error-once": { + servers: []func() tfprotov5.ProviderServer{ + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov5.Schema{}, + expectedDiagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + }, + "error-multiple": { + servers: []func() tfprotov5.ProviderServer{ + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov5.Schema{}, + expectedDiagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + }, + "warning-once": { + servers: []func() tfprotov5.ProviderServer{ + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov5.Schema{}, + expectedDiagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + }, + "warning-multiple": { + servers: []func() tfprotov5.ProviderServer{ + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov5.Schema{}, + expectedDiagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + }, + "warning-then-error": { + servers: []func() tfprotov5.ProviderServer{ + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf5testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov5.Schema{}, + expectedDiagnostics: []*tfprotov5.Diagnostic{ + { + Severity: tfprotov5.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + { + Severity: tfprotov5.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov5.Schema{}, + }, } for name, testCase := range testCases { diff --git a/tf5muxserver/mux_server_ImportResourceState_test.go b/tf5muxserver/mux_server_ImportResourceState_test.go index 89e578f..a540912 100644 --- a/tf5muxserver/mux_server_ImportResourceState_test.go +++ b/tf5muxserver/mux_server_ImportResourceState_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerImportResourceState(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf5muxserver/mux_server_PlanResourceChange_test.go b/tf5muxserver/mux_server_PlanResourceChange_test.go index 71e72fd..b6990f6 100644 --- a/tf5muxserver/mux_server_PlanResourceChange_test.go +++ b/tf5muxserver/mux_server_PlanResourceChange_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5dynamicvalue" "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" @@ -20,13 +21,15 @@ func TestMuxServerPlanResourceChange_Routing(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": { - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": { + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, @@ -34,13 +37,15 @@ func TestMuxServerPlanResourceChange_Routing(t *testing.T) { }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": { - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": { + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, @@ -122,36 +127,40 @@ func TestMuxServerPlanResourceChange_ServerCapabilities_PlanDestroy(t *testing.T ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": { - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": { + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, }, - }, - ServerCapabilities: &tfprotov5.ServerCapabilities{ - PlanDestroy: true, + ServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": { - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": { + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, }, + // Intentionally no ServerCapabilities on this server }, - // Intentionally no ServerCapabilities on this server } testProposedNewState := tf5dynamicvalue.Must( diff --git a/tf5muxserver/mux_server_PrepareProviderConfig_test.go b/tf5muxserver/mux_server_PrepareProviderConfig_test.go index f20b518..972134a 100644 --- a/tf5muxserver/mux_server_PrepareProviderConfig_test.go +++ b/tf5muxserver/mux_server_PrepareProviderConfig_test.go @@ -12,6 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -70,6 +71,7 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "error-once": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -80,8 +82,12 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, }, }, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, }, expectedResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ @@ -96,6 +102,7 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "error-multiple": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -106,8 +113,11 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, }, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -137,6 +147,7 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "warning-once": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -147,8 +158,12 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, }, }, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, }, expectedResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ @@ -163,6 +178,7 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "warning-multiple": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -173,8 +189,11 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, }, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -204,6 +223,7 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "warning-then-error": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -214,8 +234,11 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, }, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -244,21 +267,33 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, "no-response": { testServers: [3]*tf5testserver.TestServer{ - {}, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, }, }, "PreparedConfig-once": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, }, expectedResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, @@ -267,13 +302,20 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "PreparedConfig-once-and-error": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -284,7 +326,6 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { }, PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, }, expectedResponse: &tfprotov5.PrepareProviderConfigResponse{ @@ -301,13 +342,18 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "PreparedConfig-once-and-warning": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ Diagnostics: []*tfprotov5.Diagnostic{ { @@ -333,17 +379,23 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "PreparedConfig-multiple-different": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config2, }, - ProviderSchema: &configSchema, }, }, expectedError: fmt.Errorf("got different PrepareProviderConfig PreparedConfig response from multiple servers, not sure which to use"), @@ -351,17 +403,23 @@ func TestMuxServerPrepareProviderConfig(t *testing.T) { "PreparedConfig-multiple-equal": { testServers: [3]*tf5testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, - {}, { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &configSchema, + }, PrepareProviderConfigResponse: &tfprotov5.PrepareProviderConfigResponse{ PreparedConfig: &config, }, - ProviderSchema: &configSchema, }, }, expectedResponse: &tfprotov5.PrepareProviderConfigResponse{ diff --git a/tf5muxserver/mux_server_ReadDataSource_test.go b/tf5muxserver/mux_server_ReadDataSource_test.go index 75486f0..7ee529e 100644 --- a/tf5muxserver/mux_server_ReadDataSource_test.go +++ b/tf5muxserver/mux_server_ReadDataSource_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerReadDataSource(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source_server2": {}, + }, }, } diff --git a/tf5muxserver/mux_server_ReadResource_test.go b/tf5muxserver/mux_server_ReadResource_test.go index 7308bc9..1818992 100644 --- a/tf5muxserver/mux_server_ReadResource_test.go +++ b/tf5muxserver/mux_server_ReadResource_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerReadResource(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf5muxserver/mux_server_StopProvider_test.go b/tf5muxserver/mux_server_StopProvider_test.go index bdec483..e8a3b12 100644 --- a/tf5muxserver/mux_server_StopProvider_test.go +++ b/tf5muxserver/mux_server_StopProvider_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -16,7 +17,25 @@ func TestMuxServerStopProvider(t *testing.T) { t.Parallel() ctx := context.Background() - testServers := [5]*tf5testserver.TestServer{{}, {StopProviderError: "error in server2"}, {}, {StopProviderError: "error in server4"}, {}} + testServers := [5]*tf5testserver.TestServer{ + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + StopProviderError: "error in server2", + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + StopProviderError: "error in server4", + }, + { + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{}, + }, + } servers := []func() tfprotov5.ProviderServer{ testServers[0].ProviderServer, diff --git a/tf5muxserver/mux_server_UpgradeResourceState_test.go b/tf5muxserver/mux_server_UpgradeResourceState_test.go index d05a5eb..b8c9318 100644 --- a/tf5muxserver/mux_server_UpgradeResourceState_test.go +++ b/tf5muxserver/mux_server_UpgradeResourceState_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerUpgradeResourceState(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf5muxserver/mux_server_ValidateDataSourceConfig_test.go b/tf5muxserver/mux_server_ValidateDataSourceConfig_test.go index 4b493f3..8de0551 100644 --- a/tf5muxserver/mux_server_ValidateDataSourceConfig_test.go +++ b/tf5muxserver/mux_server_ValidateDataSourceConfig_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerValidateDataSourceConfig(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source_server2": {}, + }, }, } diff --git a/tf5muxserver/mux_server_ValidateResourceTypeConfig_test.go b/tf5muxserver/mux_server_ValidateResourceTypeConfig_test.go index e6f40cd..6ca53e0 100644 --- a/tf5muxserver/mux_server_ValidateResourceTypeConfig_test.go +++ b/tf5muxserver/mux_server_ValidateResourceTypeConfig_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov5" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerValidateResourceTypeConfig(t *testing.T) { ctx := context.Background() testServer1 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource_server2": {}, + }, }, } servers := []func() tfprotov5.ProviderServer{testServer1.ProviderServer, testServer2.ProviderServer} diff --git a/tf5muxserver/mux_server_test.go b/tf5muxserver/mux_server_test.go index 3544570..61a1c4b 100644 --- a/tf5muxserver/mux_server_test.go +++ b/tf5muxserver/mux_server_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5muxserver" ) @@ -24,13 +25,17 @@ func TestNewMuxServer(t *testing.T) { "duplicate-data-source": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -39,13 +44,17 @@ func TestNewMuxServer(t *testing.T) { "duplicate-resource": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -54,41 +63,43 @@ func TestNewMuxServer(t *testing.T) { "provider-mismatch": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -98,41 +109,43 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -147,73 +160,75 @@ func TestNewMuxServer(t *testing.T) { "provider-ordering": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "other_feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, }, - }, - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "other_feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -223,73 +238,75 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, }, - }, - { - TypeName: "other_feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + { + TypeName: "other_feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -303,41 +320,43 @@ func TestNewMuxServer(t *testing.T) { "provider-meta-mismatch": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderMetaSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -347,41 +366,43 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderMetaSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -396,73 +417,75 @@ func TestNewMuxServer(t *testing.T) { "provider-meta-ordering": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderMetaSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, }, - }, - { - TypeName: "other_feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + { + TypeName: "other_feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -472,73 +495,75 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderMetaSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov5.Schema{ Version: 1, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "other_feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, }, - }, - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "other_feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov5.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, @@ -552,44 +577,48 @@ func TestNewMuxServer(t *testing.T) { "nested block MinItems and MaxItems diff are ignored": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{}, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{}, + }, + MinItems: 1, + MaxItems: 2, }, - MinItems: 1, - MaxItems: 2, }, }, }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ProviderSchema: &tfprotov5.Schema{ - Version: 1, - Block: &tfprotov5.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + Provider: &tfprotov5.Schema{ Version: 1, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{}, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{}, + }, + MinItems: 0, + MaxItems: 0, }, - MinItems: 0, - MaxItems: 0, }, }, }, @@ -600,16 +629,20 @@ func TestNewMuxServer(t *testing.T) { "server-capabilities": { servers: []func() tfprotov5.ProviderServer{ (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_with_server_capabilities": {}, - }, - ServerCapabilities: &tfprotov5.ServerCapabilities{ - PlanDestroy: true, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_with_server_capabilities": {}, + }, + ServerCapabilities: &tfprotov5.ServerCapabilities{ + PlanDestroy: true, + }, }, }).ProviderServer, (&tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_without_server_capabilities": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_without_server_capabilities": {}, + }, }, }).ProviderServer, }, diff --git a/tf5to6server/tf5to6server_test.go b/tf5to6server/tf5to6server_test.go index f077f56..0e1f370 100644 --- a/tf5to6server/tf5to6server_test.go +++ b/tf5to6server/tf5to6server_test.go @@ -11,6 +11,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf5testserver" "github.com/hashicorp/terraform-plugin-mux/tf5to6server" ) @@ -24,75 +25,77 @@ func TestUpgradeServer(t *testing.T) { }{ "compatible": { v5Server: (&tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source": {}, - }, - ProviderSchema: &tfprotov5.Schema{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_attribute", - Type: tftypes.String, - Required: true, - Description: "test_attribute description", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "test_block", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Description: "test_block description", + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source": {}, + }, + Provider: &tfprotov5.Schema{ + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_attribute", + Type: tftypes.String, + Required: true, + Description: "test_attribute description", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_block_attribute", - Type: tftypes.Number, - Required: true, - Description: "test_block_attribute description", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "test_block", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Description: "test_block description", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_block_attribute", + Type: tftypes.Number, + Required: true, + Description: "test_block_attribute description", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, }, }, }, - }, - ProviderMetaSchema: &tfprotov5.Schema{ - Block: &tfprotov5.SchemaBlock{ - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_attribute", - Type: tftypes.String, - Required: true, - Description: "test_attribute description", - DescriptionKind: tfprotov5.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov5.SchemaNestedBlock{ - { - TypeName: "test_block", - Nesting: tfprotov5.SchemaNestedBlockNestingModeList, - Block: &tfprotov5.SchemaBlock{ - Description: "test_block description", + ProviderMeta: &tfprotov5.Schema{ + Block: &tfprotov5.SchemaBlock{ + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_attribute", + Type: tftypes.String, + Required: true, + Description: "test_attribute description", DescriptionKind: tfprotov5.StringKindPlain, - Attributes: []*tfprotov5.SchemaAttribute{ - { - Name: "test_block_attribute", - Type: tftypes.Number, - Required: true, - Description: "test_block_attribute description", - DescriptionKind: tfprotov5.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov5.SchemaNestedBlock{ + { + TypeName: "test_block", + Nesting: tfprotov5.SchemaNestedBlockNestingModeList, + Block: &tfprotov5.SchemaBlock{ + Description: "test_block description", + DescriptionKind: tfprotov5.StringKindPlain, + Attributes: []*tfprotov5.SchemaAttribute{ + { + Name: "test_block_attribute", + Type: tftypes.Number, + Required: true, + Description: "test_block_attribute description", + DescriptionKind: tfprotov5.StringKindPlain, + }, }, }, }, }, }, }, - }, - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, }).ProviderServer, }, @@ -128,8 +131,10 @@ func TestV6ToV5ServerApplyResourceChange(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -157,8 +162,10 @@ func TestV6ToV5ServerConfigureProvider(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -184,8 +191,10 @@ func TestV6ToV5ServerGetProviderSchema(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -211,8 +220,10 @@ func TestV6ToV5ServerImportResourceState(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -240,8 +251,10 @@ func TestV6ToV5ServerPlanResourceChange(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -269,8 +282,10 @@ func TestV6ToV5ServerReadDataSource(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source": {}, + }, }, } @@ -298,8 +313,10 @@ func TestV6ToV5ServerReadResource(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -327,8 +344,10 @@ func TestV6ToV5ServerStopProvider(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -354,8 +373,10 @@ func TestV6ToV5ServerUpgradeResourceState(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -383,8 +404,10 @@ func TestV6ToV5ServerValidateDataResourceConfig(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov5.Schema{ - "test_data_source": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov5.Schema{ + "test_data_source": {}, + }, }, } @@ -412,8 +435,10 @@ func TestV6ToV5ServerValidateProviderConfig(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } @@ -439,8 +464,10 @@ func TestV6ToV5ServerValidateResourceConfig(t *testing.T) { ctx := context.Background() v5server := &tf5testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov5.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov5.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov5.Schema{ + "test_resource": {}, + }, }, } diff --git a/tf6muxserver/mux_server_ApplyResourceChange_test.go b/tf6muxserver/mux_server_ApplyResourceChange_test.go index 06d6cd9..eb37462 100644 --- a/tf6muxserver/mux_server_ApplyResourceChange_test.go +++ b/tf6muxserver/mux_server_ApplyResourceChange_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerApplyResourceChange(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_ConfigureProvider_test.go b/tf6muxserver/mux_server_ConfigureProvider_test.go index 002b33e..a8ef910 100644 --- a/tf6muxserver/mux_server_ConfigureProvider_test.go +++ b/tf6muxserver/mux_server_ConfigureProvider_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -16,7 +17,23 @@ func TestMuxServerConfigureProvider(t *testing.T) { t.Parallel() ctx := context.Background() - testServers := [5]*tf6testserver.TestServer{{}, {}, {}, {}, {}} + testServers := [5]*tf6testserver.TestServer{ + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + } servers := []func() tfprotov6.ProviderServer{ testServers[0].ProviderServer, diff --git a/tf6muxserver/mux_server_GetProviderSchema_test.go b/tf6muxserver/mux_server_GetProviderSchema_test.go index 5c5a965..b1c23c8 100644 --- a/tf6muxserver/mux_server_GetProviderSchema_test.go +++ b/tf6muxserver/mux_server_GetProviderSchema_test.go @@ -30,227 +30,231 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "combined": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - }, - }, - }, - }, - }, - ProviderMetaSchema: &tfprotov6.Schema{ - Version: 4, - Block: &tfprotov6.SchemaBlock{ - Version: 4, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "module_id", - Type: tftypes.String, - Optional: true, - Description: "a unique identifier for the module", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - }, - }, - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, Block: &tfprotov6.SchemaBlock{ Version: 1, Attributes: []*tfprotov6.SchemaAttribute{ { - Name: "airspeed_velocity", - Type: tftypes.Number, + Name: "account_id", + Type: tftypes.String, Required: true, - Description: "the airspeed velocity of a swallow", + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, }, }, - }, - }, - "test_bar": { - Version: 1, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "name", - Type: tftypes.String, - Optional: true, - Description: "your name", - DescriptionKind: tfprotov6.StringKindPlain, - }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ { - Name: "color", - Type: tftypes.String, - Optional: true, - Description: "your favorite color", - DescriptionKind: tfprotov6.StringKindPlain, + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + }, }, }, }, }, - }, - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": { - Version: 1, + ProviderMeta: &tfprotov6.Schema{ + Version: 4, Block: &tfprotov6.SchemaBlock{ - Version: 1, + Version: 4, Attributes: []*tfprotov6.SchemaAttribute{ { - Name: "current_time", + Name: "module_id", Type: tftypes.String, - Computed: true, - Description: "the current time in RFC 3339 format", + Optional: true, + Description: "a unique identifier for the module", DescriptionKind: tfprotov6.StringKindPlain, }, }, }, }, - }, - }).ProviderServer, - (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": { + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "airspeed_velocity", + Type: tftypes.Number, + Required: true, + Description: "the airspeed velocity of a swallow", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, }, }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, - }, + "test_bar": { + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "name", + Type: tftypes.String, + Optional: true, + Description: "your name", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "color", + Type: tftypes.String, + Optional: true, + Description: "your favorite color", + DescriptionKind: tfprotov6.StringKindPlain, }, }, }, }, }, - }, - ProviderMetaSchema: &tfprotov6.Schema{ - Version: 4, - Block: &tfprotov6.SchemaBlock{ - Version: 4, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "module_id", - Type: tftypes.String, - Optional: true, - Description: "a unique identifier for the module", - DescriptionKind: tfprotov6.StringKindPlain, + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": { + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "current_time", + Type: tftypes.String, + Computed: true, + Description: "the current time in RFC 3339 format", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, }, }, }, }, - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_quux": { + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, Block: &tfprotov6.SchemaBlock{ Version: 1, Attributes: []*tfprotov6.SchemaAttribute{ { - Name: "a", + Name: "account_id", Type: tftypes.String, Required: true, Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ { - Name: "b", - Type: tftypes.String, - Required: true, + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + }, }, }, }, }, - }, - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_bar": { - Version: 1, + ProviderMeta: &tfprotov6.Schema{ + Version: 4, Block: &tfprotov6.SchemaBlock{ - Version: 1, + Version: 4, Attributes: []*tfprotov6.SchemaAttribute{ { - Name: "a", - Type: tftypes.Number, - Computed: true, - Description: "some field that's set by the provider", - DescriptionKind: tfprotov6.StringKindMarkdown, + Name: "module_id", + Type: tftypes.String, + Optional: true, + Description: "a unique identifier for the module", + DescriptionKind: tfprotov6.StringKindPlain, }, }, }, }, - "test_quux": { - Version: 1, - Block: &tfprotov6.SchemaBlock{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_quux": { Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "abc", - Type: tftypes.Number, - Computed: true, - Description: "some other field that's set by the provider", - DescriptionKind: tfprotov6.StringKindMarkdown, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "a", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "b", + Type: tftypes.String, + Required: true, + }, + }, + }, + }, + }, + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_bar": { + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "a", + Type: tftypes.Number, + Computed: true, + Description: "some field that's set by the provider", + DescriptionKind: tfprotov6.StringKindMarkdown, + }, + }, + }, + }, + "test_quux": { + Version: 1, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "abc", + Type: tftypes.Number, + Computed: true, + Description: "some other field that's set by the provider", + DescriptionKind: tfprotov6.StringKindMarkdown, + }, }, }, }, @@ -428,13 +432,17 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "duplicate-data-source-type": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -459,13 +467,17 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "duplicate-resource-type": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -487,52 +499,33 @@ func TestMuxServerGetProviderSchema(t *testing.T) { PlanDestroy: true, }, }, - "get-provider-schema-diagnostics": { - servers: []func() tfprotov6.ProviderServer{ - (&tf6testserver.TestServerDiags{ - TestServer: &tf6testserver.TestServer{}, - Diagnostics: []*tfprotov6.Diagnostic{ - { - Severity: tfprotov6.DiagnosticSeverityError, - Summary: "Summary", - Detail: "Detail", - }, - }, - }).ProviderServer, - }, - expectedDiagnostics: []*tfprotov6.Diagnostic{ - { - Severity: tfprotov6.DiagnosticSeverityError, - Summary: "Summary", - Detail: "Detail", - }, - }, - expectedDataSourceSchemas: map[string]*tfprotov6.Schema{}, - expectedResourceSchemas: map[string]*tfprotov6.Schema{}, - }, "provider-mismatch": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "testattribute1", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "testattribute1", + Type: tftypes.String, + Required: true, + }, }, }, }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "testattribute2", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "testattribute2", + Type: tftypes.String, + Required: true, + }, }, }, }, @@ -592,26 +585,30 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "provider-meta-mismatch": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "testattribute1", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "testattribute1", + Type: tftypes.String, + Required: true, + }, }, }, }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "testattribute2", - Type: tftypes.String, - Required: true, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "testattribute2", + Type: tftypes.String, + Required: true, + }, }, }, }, @@ -671,16 +668,20 @@ func TestMuxServerGetProviderSchema(t *testing.T) { "server-capabilities": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_with_server_capabilities": {}, - }, - ServerCapabilities: &tfprotov6.ServerCapabilities{ - PlanDestroy: true, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_with_server_capabilities": {}, + }, + ServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_without_server_capabilities": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_without_server_capabilities": {}, + }, }, }).ProviderServer, }, @@ -693,6 +694,195 @@ func TestMuxServerGetProviderSchema(t *testing.T) { PlanDestroy: true, }, }, + "error-once": { + servers: []func() tfprotov6.ProviderServer{ + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov6.Schema{}, + expectedDiagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + }, + "error-multiple": { + servers: []func() tfprotov6.ProviderServer{ + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov6.Schema{}, + expectedDiagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + }, + "warning-once": { + servers: []func() tfprotov6.ProviderServer{ + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov6.Schema{}, + expectedDiagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + }, + "warning-multiple": { + servers: []func() tfprotov6.ProviderServer{ + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov6.Schema{}, + expectedDiagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + }, + "warning-then-error": { + servers: []func() tfprotov6.ProviderServer{ + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + }, + }, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }).ProviderServer, + (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Diagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + }, + }).ProviderServer, + }, + expectedDataSourceSchemas: map[string]*tfprotov6.Schema{}, + expectedDiagnostics: []*tfprotov6.Diagnostic{ + { + Severity: tfprotov6.DiagnosticSeverityWarning, + Summary: "test warning summary", + Detail: "test warning details", + }, + { + Severity: tfprotov6.DiagnosticSeverityError, + Summary: "test error summary", + Detail: "test error details", + }, + }, + expectedResourceSchemas: map[string]*tfprotov6.Schema{}, + }, } for name, testCase := range testCases { diff --git a/tf6muxserver/mux_server_ImportResourceState_test.go b/tf6muxserver/mux_server_ImportResourceState_test.go index 3d2d22e..dfdfeef 100644 --- a/tf6muxserver/mux_server_ImportResourceState_test.go +++ b/tf6muxserver/mux_server_ImportResourceState_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerImportResourceState(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_PlanResourceChange_test.go b/tf6muxserver/mux_server_PlanResourceChange_test.go index b4b4205..e99cc35 100644 --- a/tf6muxserver/mux_server_PlanResourceChange_test.go +++ b/tf6muxserver/mux_server_PlanResourceChange_test.go @@ -9,6 +9,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6dynamicvalue" "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" @@ -19,13 +20,15 @@ func TestMuxServerPlanResourceChange_Routing(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": { - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": { + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, @@ -33,13 +36,15 @@ func TestMuxServerPlanResourceChange_Routing(t *testing.T) { }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": { - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": { + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, @@ -121,36 +126,40 @@ func TestMuxServerPlanResourceChange_ServerCapabilities_PlanDestroy(t *testing.T ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": { - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": { + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, }, - }, - ServerCapabilities: &tfprotov6.ServerCapabilities{ - PlanDestroy: true, + ServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": { - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_string_attribute", - Type: tftypes.String, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": { + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_string_attribute", + Type: tftypes.String, + }, }, }, }, }, + // Intentionally no ServerCapabilities on this server }, - // Intentionally no ServerCapabilities on this server } testProposedNewState := tf6dynamicvalue.Must( diff --git a/tf6muxserver/mux_server_ReadDataSource_test.go b/tf6muxserver/mux_server_ReadDataSource_test.go index a332ac8..ee7b19c 100644 --- a/tf6muxserver/mux_server_ReadDataSource_test.go +++ b/tf6muxserver/mux_server_ReadDataSource_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerReadDataSource(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_ReadResource_test.go b/tf6muxserver/mux_server_ReadResource_test.go index 72146b2..31ac8f7 100644 --- a/tf6muxserver/mux_server_ReadResource_test.go +++ b/tf6muxserver/mux_server_ReadResource_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerReadResource(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_StopProvider_test.go b/tf6muxserver/mux_server_StopProvider_test.go index e162e36..48946a6 100644 --- a/tf6muxserver/mux_server_StopProvider_test.go +++ b/tf6muxserver/mux_server_StopProvider_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -16,7 +17,24 @@ func TestMuxServerStopProvider(t *testing.T) { t.Parallel() ctx := context.Background() - testServers := [5]*tf6testserver.TestServer{{}, {StopProviderError: "error in server2"}, {}, {StopProviderError: "error in server4"}, {}} + testServers := [5]*tf6testserver.TestServer{ + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + StopProviderError: "error in server2", + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + StopProviderError: "error in server4", + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + } servers := []func() tfprotov6.ProviderServer{ testServers[0].ProviderServer, diff --git a/tf6muxserver/mux_server_UpgradeResourceState_test.go b/tf6muxserver/mux_server_UpgradeResourceState_test.go index 5f48045..ff49fb7 100644 --- a/tf6muxserver/mux_server_UpgradeResourceState_test.go +++ b/tf6muxserver/mux_server_UpgradeResourceState_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerUpgradeResourceState(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_ValidateDataResourceConfig_test.go b/tf6muxserver/mux_server_ValidateDataResourceConfig_test.go index 1a0b738..3808bd2 100644 --- a/tf6muxserver/mux_server_ValidateDataResourceConfig_test.go +++ b/tf6muxserver/mux_server_ValidateDataResourceConfig_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerValidateDataResourceConfig(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_ValidateProviderConfig_test.go b/tf6muxserver/mux_server_ValidateProviderConfig_test.go index 0952ebb..d63c793 100644 --- a/tf6muxserver/mux_server_ValidateProviderConfig_test.go +++ b/tf6muxserver/mux_server_ValidateProviderConfig_test.go @@ -12,6 +12,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -70,6 +71,7 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "error-once": { testServers: [3]*tf6testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -80,8 +82,12 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { }, }, }, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, }, expectedResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ @@ -96,6 +102,7 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "error-multiple": { testServers: [3]*tf6testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -106,8 +113,11 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { }, }, }, - {}, { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -137,6 +147,7 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "warning-once": { testServers: [3]*tf6testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -147,8 +158,12 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { }, }, }, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, }, expectedResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ @@ -163,6 +178,7 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "warning-multiple": { testServers: [3]*tf6testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -173,8 +189,11 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { }, }, }, - {}, { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -204,6 +223,7 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "warning-then-error": { testServers: [3]*tf6testserver.TestServer{ { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -214,8 +234,11 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { }, }, }, - {}, { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -244,21 +267,33 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { }, "no-response": { testServers: [3]*tf6testserver.TestServer{ - {}, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, }, }, "PreparedConfig-once": { testServers: [3]*tf6testserver.TestServer{ { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, }, }, - {}, - {}, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, + { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{}, + }, }, expectedResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, @@ -267,16 +302,22 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "PreparedConfig-once-and-error": { testServers: [3]*tf6testserver.TestServer{ { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -302,16 +343,22 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "PreparedConfig-once-and-warning": { testServers: [3]*tf6testserver.TestServer{ { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ Diagnostics: []*tfprotov6.Diagnostic{ { @@ -337,16 +384,22 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "PreparedConfig-multiple-different": { testServers: [3]*tf6testserver.TestServer{ { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config2, }, @@ -357,16 +410,22 @@ func TestMuxServerValidateProviderConfig(t *testing.T) { "PreparedConfig-multiple-equal": { testServers: [3]*tf6testserver.TestServer{ { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, }, { - ProviderSchema: &configSchema, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &configSchema, + }, ValidateProviderConfigResponse: &tfprotov6.ValidateProviderConfigResponse{ PreparedConfig: &config, }, diff --git a/tf6muxserver/mux_server_ValidateResourceConfig_test.go b/tf6muxserver/mux_server_ValidateResourceConfig_test.go index 0eed314..93c0297 100644 --- a/tf6muxserver/mux_server_ValidateResourceConfig_test.go +++ b/tf6muxserver/mux_server_ValidateResourceConfig_test.go @@ -8,6 +8,7 @@ import ( "testing" "github.com/hashicorp/terraform-plugin-go/tfprotov6" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -17,13 +18,17 @@ func TestMuxServerValidateResourceConfig(t *testing.T) { ctx := context.Background() testServer1 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server1": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server1": {}, + }, }, } testServer2 := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource_server2": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource_server2": {}, + }, }, } diff --git a/tf6muxserver/mux_server_test.go b/tf6muxserver/mux_server_test.go index 55a3c4c..53acf04 100644 --- a/tf6muxserver/mux_server_test.go +++ b/tf6muxserver/mux_server_test.go @@ -10,6 +10,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/tf6muxserver" ) @@ -24,13 +25,17 @@ func TestNewMuxServer(t *testing.T) { "duplicate-data-source": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -39,13 +44,17 @@ func TestNewMuxServer(t *testing.T) { "duplicate-resource": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_foo": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_foo": {}, + }, }, }).ProviderServer, }, @@ -54,41 +63,43 @@ func TestNewMuxServer(t *testing.T) { "provider-mismatch": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -98,41 +109,43 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -147,73 +160,75 @@ func TestNewMuxServer(t *testing.T) { "provider-ordering": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "other_feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, }, - }, - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "other_feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -223,73 +238,75 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, }, - }, - { - TypeName: "other_feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + { + TypeName: "other_feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -303,41 +320,43 @@ func TestNewMuxServer(t *testing.T) { "provider-meta-mismatch": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -347,41 +366,43 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Optional: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Optional: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -396,73 +417,75 @@ func TestNewMuxServer(t *testing.T) { "provider-meta-ordering": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, }, - }, - { - TypeName: "other_feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + { + TypeName: "other_feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -472,73 +495,75 @@ func TestNewMuxServer(t *testing.T) { }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ Version: 1, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "secret", - Type: tftypes.String, - Required: true, - Description: "the secret to authenticate with", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "account_id", - Type: tftypes.String, - Required: true, - Description: "the account ID to make requests for", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "other_feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "secret", + Type: tftypes.String, + Required: true, + Description: "the secret to authenticate with", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, - }, - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, }, - }, - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", + { + Name: "account_id", + Type: tftypes.String, + Required: true, + Description: "the account ID to make requests for", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "enabled", - Type: tftypes.Bool, - Required: true, - Description: "whether the feature is enabled", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "other_feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, - { - Name: "feature_id", - Type: tftypes.Number, - Required: true, - Description: "The ID of the feature", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "enabled", + Type: tftypes.Bool, + Required: true, + Description: "whether the feature is enabled", + DescriptionKind: tfprotov6.StringKindPlain, + }, + { + Name: "feature_id", + Type: tftypes.Number, + Required: true, + Description: "The ID of the feature", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, @@ -552,44 +577,48 @@ func TestNewMuxServer(t *testing.T) { "nested block MinItems and MaxItems diff are ignored": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{}, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{}, + }, + MinItems: 1, + MaxItems: 2, }, - MinItems: 1, - MaxItems: 2, }, }, }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Version: 1, - Block: &tfprotov6.SchemaBlock{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Version: 1, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "feature", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Version: 1, - Description: "features to enable on the provider", - DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{}, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "feature", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Version: 1, + Description: "features to enable on the provider", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{}, + }, + MinItems: 0, + MaxItems: 0, }, - MinItems: 0, - MaxItems: 0, }, }, }, @@ -600,16 +629,20 @@ func TestNewMuxServer(t *testing.T) { "server-capabilities": { servers: []func() tfprotov6.ProviderServer{ (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_with_server_capabilities": {}, - }, - ServerCapabilities: &tfprotov6.ServerCapabilities{ - PlanDestroy: true, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_with_server_capabilities": {}, + }, + ServerCapabilities: &tfprotov6.ServerCapabilities{ + PlanDestroy: true, + }, }, }).ProviderServer, (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_without_server_capabilities": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_without_server_capabilities": {}, + }, }, }).ProviderServer, }, diff --git a/tf6to5server/tf6to5server_test.go b/tf6to5server/tf6to5server_test.go index e291ccc..93b911f 100644 --- a/tf6to5server/tf6to5server_test.go +++ b/tf6to5server/tf6to5server_test.go @@ -12,6 +12,7 @@ import ( "github.com/hashicorp/terraform-plugin-go/tfprotov5" "github.com/hashicorp/terraform-plugin-go/tfprotov6" "github.com/hashicorp/terraform-plugin-go/tftypes" + "github.com/hashicorp/terraform-plugin-mux/internal/tf6testserver" "github.com/hashicorp/terraform-plugin-mux/internal/tfprotov6tov5" "github.com/hashicorp/terraform-plugin-mux/tf6to5server" @@ -26,82 +27,109 @@ func TestDowngradeServer(t *testing.T) { }{ "compatible": { v6Server: (&tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source": {}, - }, - ProviderSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_attribute", - Type: tftypes.String, - Required: true, - Description: "test_attribute description", - DescriptionKind: tfprotov6.StringKindPlain, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source": {}, + }, + Provider: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_attribute", + Type: tftypes.String, + Required: true, + Description: "test_attribute description", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "test_block", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Description: "test_block description", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_block_attribute", + Type: tftypes.Number, + Required: true, + Description: "test_block_attribute description", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + }, + }, }, }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "test_block", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Description: "test_block description", + }, + ProviderMeta: &tfprotov6.Schema{ + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_attribute", + Type: tftypes.String, + Required: true, + Description: "test_attribute description", DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_block_attribute", - Type: tftypes.Number, - Required: true, - Description: "test_block_attribute description", - DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + BlockTypes: []*tfprotov6.SchemaNestedBlock{ + { + TypeName: "test_block", + Nesting: tfprotov6.SchemaNestedBlockNestingModeList, + Block: &tfprotov6.SchemaBlock{ + Description: "test_block description", + DescriptionKind: tfprotov6.StringKindPlain, + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_block_attribute", + Type: tftypes.Number, + Required: true, + Description: "test_block_attribute description", + DescriptionKind: tfprotov6.StringKindPlain, + }, }, }, }, }, }, }, + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, - ProviderMetaSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_attribute", - Type: tftypes.String, - Required: true, - Description: "test_attribute description", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - BlockTypes: []*tfprotov6.SchemaNestedBlock{ - { - TypeName: "test_block", - Nesting: tfprotov6.SchemaNestedBlockNestingModeList, - Block: &tfprotov6.SchemaBlock{ - Description: "test_block description", - DescriptionKind: tfprotov6.StringKindPlain, - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_block_attribute", - Type: tftypes.Number, - Required: true, - Description: "test_block_attribute description", - DescriptionKind: tfprotov6.StringKindPlain, + }).ProviderServer, + }, + "SchemaAttribute-NestedType-data-source": { + v6Server: (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source": { + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_attribute", + NestedType: &tfprotov6.SchemaObject{ + Attributes: []*tfprotov6.SchemaAttribute{}, + Nesting: tfprotov6.SchemaObjectNestingModeSingle, }, + Required: true, + Description: "test_attribute description", + DescriptionKind: tfprotov6.StringKindPlain, }, }, }, }, }, }, - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, - }, }).ProviderServer, + expectedError: fmt.Errorf("unable to convert data source \"test_data_source\" schema: unable to convert attribute \"test_attribute\" schema: %s", tfprotov6tov5.ErrSchemaAttributeNestedTypeNotImplemented), }, - "SchemaAttribute-NestedType-data-source": { + "SchemaAttribute-NestedType-provider": { v6Server: (&tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source": { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + Provider: &tfprotov6.Schema{ Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{ { @@ -119,54 +147,12 @@ func TestDowngradeServer(t *testing.T) { }, }, }).ProviderServer, - expectedError: fmt.Errorf("unable to convert data source \"test_data_source\" schema: unable to convert attribute \"test_attribute\" schema: %s", tfprotov6tov5.ErrSchemaAttributeNestedTypeNotImplemented), - }, - "SchemaAttribute-NestedType-provider": { - v6Server: (&tf6testserver.TestServer{ - ProviderSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_attribute", - NestedType: &tfprotov6.SchemaObject{ - Attributes: []*tfprotov6.SchemaAttribute{}, - Nesting: tfprotov6.SchemaObjectNestingModeSingle, - }, - Required: true, - Description: "test_attribute description", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - }, - }, - }).ProviderServer, expectedError: fmt.Errorf("unable to convert provider schema: unable to convert attribute \"test_attribute\" schema: %s", tfprotov6tov5.ErrSchemaAttributeNestedTypeNotImplemented), }, "SchemaAttribute-NestedType-provider-meta": { v6Server: (&tf6testserver.TestServer{ - ProviderMetaSchema: &tfprotov6.Schema{ - Block: &tfprotov6.SchemaBlock{ - Attributes: []*tfprotov6.SchemaAttribute{ - { - Name: "test_attribute", - NestedType: &tfprotov6.SchemaObject{ - Attributes: []*tfprotov6.SchemaAttribute{}, - Nesting: tfprotov6.SchemaObjectNestingModeSingle, - }, - Required: true, - Description: "test_attribute description", - DescriptionKind: tfprotov6.StringKindPlain, - }, - }, - }, - }, - }).ProviderServer, - expectedError: fmt.Errorf("unable to convert provider meta schema: unable to convert attribute \"test_attribute\" schema: %s", tfprotov6tov5.ErrSchemaAttributeNestedTypeNotImplemented), - }, - "SchemaAttribute-NestedType-resource": { - v6Server: (&tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": { + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ProviderMeta: &tfprotov6.Schema{ Block: &tfprotov6.SchemaBlock{ Attributes: []*tfprotov6.SchemaAttribute{ { @@ -184,6 +170,31 @@ func TestDowngradeServer(t *testing.T) { }, }, }).ProviderServer, + expectedError: fmt.Errorf("unable to convert provider meta schema: unable to convert attribute \"test_attribute\" schema: %s", tfprotov6tov5.ErrSchemaAttributeNestedTypeNotImplemented), + }, + "SchemaAttribute-NestedType-resource": { + v6Server: (&tf6testserver.TestServer{ + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": { + Block: &tfprotov6.SchemaBlock{ + Attributes: []*tfprotov6.SchemaAttribute{ + { + Name: "test_attribute", + NestedType: &tfprotov6.SchemaObject{ + Attributes: []*tfprotov6.SchemaAttribute{}, + Nesting: tfprotov6.SchemaObjectNestingModeSingle, + }, + Required: true, + Description: "test_attribute description", + DescriptionKind: tfprotov6.StringKindPlain, + }, + }, + }, + }, + }, + }, + }).ProviderServer, expectedError: fmt.Errorf("unable to convert resource \"test_resource\" schema: unable to convert attribute \"test_attribute\" schema: %s", tfprotov6tov5.ErrSchemaAttributeNestedTypeNotImplemented), }, } @@ -218,8 +229,10 @@ func TestV6ToV5ServerApplyResourceChange(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -247,8 +260,10 @@ func TestV6ToV5ServerConfigureProvider(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -274,8 +289,10 @@ func TestV6ToV5ServerGetProviderSchema(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -301,8 +318,10 @@ func TestV6ToV5ServerImportResourceState(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -330,8 +349,10 @@ func TestV6ToV5ServerPlanResourceChange(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -359,8 +380,10 @@ func TestV6ToV5ServerPrepareProviderConfig(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -386,8 +409,10 @@ func TestV6ToV5ServerReadDataSource(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source": {}, + }, }, } @@ -415,8 +440,10 @@ func TestV6ToV5ServerReadResource(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -444,8 +471,10 @@ func TestV6ToV5ServerStopProvider(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -471,8 +500,10 @@ func TestV6ToV5ServerUpgradeResourceState(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, } @@ -500,8 +531,10 @@ func TestV6ToV5ServerValidateDataSourceConfig(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - DataSourceSchemas: map[string]*tfprotov6.Schema{ - "test_data_source": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + DataSourceSchemas: map[string]*tfprotov6.Schema{ + "test_data_source": {}, + }, }, } @@ -529,8 +562,10 @@ func TestV6ToV5ServerValidateResourceTypeConfig(t *testing.T) { ctx := context.Background() v6server := &tf6testserver.TestServer{ - ResourceSchemas: map[string]*tfprotov6.Schema{ - "test_resource": {}, + GetProviderSchemaResponse: &tfprotov6.GetProviderSchemaResponse{ + ResourceSchemas: map[string]*tfprotov6.Schema{ + "test_resource": {}, + }, }, }