diff --git a/.changelog/450.txt b/.changelog/450.txt new file mode 100644 index 000000000..389e5a4c5 --- /dev/null +++ b/.changelog/450.txt @@ -0,0 +1,15 @@ +```release-note:breaking-change +tfsdk: The `Schema` type `AttributeAtPath()` method signature has be updated with a `path.Path` parameter and `diag.Diagnostics` return. Use the `AttributeAtTerraformPath()` method instead if `*tftypes.AttributePath` or specific `error` handling is still necessary. +``` + +```release-note:breaking-change +tfsdk: The previously deprecated `Schema` type `AttributeTypeAtPath()` method has been removed. Use the `TypeAtPath()` or `TypeAtTerraformPath()` method instead. +``` + +```release-note:breaking-change +tfsdk: The previously deprecated `Schema` type `AttributeType()` method has been removed. Use the `Type()` method instead. +``` + +```release-note:breaking-change +tfsdk: The previously deprecated `Schema` type `TerraformType()` method has been removed. Use `Type().TerraformType()` instead. +``` diff --git a/internal/fwschema/schema.go b/internal/fwschema/schema.go index 3dccb1ec2..f74bdaf9f 100644 --- a/internal/fwschema/schema.go +++ b/internal/fwschema/schema.go @@ -17,9 +17,8 @@ type Schema interface { tftypes.AttributePathStepper // AttributeAtPath should return the Attribute at the given path or return - // an error. This will be added next release. - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/365 - // AttributeAtPath(context.Context, path.Path) (Attribute, diag.Diagnostics) + // an error. + AttributeAtPath(context.Context, path.Path) (Attribute, diag.Diagnostics) // AttributeAtTerraformPath should return the Attribute at the given // Terraform path or return an error. diff --git a/internal/fwserver/attribute_plan_modification_test.go b/internal/fwserver/attribute_plan_modification_test.go index d8d498f43..44acdfb57 100644 --- a/internal/fwserver/attribute_plan_modification_test.go +++ b/internal/fwserver/attribute_plan_modification_test.go @@ -10,7 +10,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" "github.com/hashicorp/terraform-plugin-framework/internal/privatestate" "github.com/hashicorp/terraform-plugin-framework/internal/testing/planmodifiers" - "github.com/hashicorp/terraform-plugin-framework/internal/totftypes" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/tfsdk" @@ -2720,28 +2719,15 @@ func TestAttributeModifyPlan(t *testing.T) { t.Parallel() ctx := context.Background() - - // TODO: Remove after schema refactoring - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/365 - tftypesPath, diags := totftypes.AttributePath(ctx, tc.req.AttributePath) + attribute, diags := tc.req.Config.Schema.AttributeAtPath(ctx, tc.req.AttributePath) if diags.HasError() { - for _, diagnostic := range diags { - t.Errorf("unexpected diagnostic: %s", diagnostic) - } - - return - } - - attribute, err := tc.req.Config.Schema.AttributeAtTerraformPath(ctx, tftypesPath) - - if err != nil { - t.Fatalf("Unexpected error getting %s", err) + t.Fatalf("Unexpected diagnostics: %s", diags) } tc.resp.Plan = tc.req.Plan - AttributeModifyPlan(context.Background(), attribute, tc.req, &tc.resp) + AttributeModifyPlan(ctx, attribute, tc.req, &tc.resp) if diff := cmp.Diff(tc.expectedResp, tc.resp, cmp.AllowUnexported(privatestate.ProviderData{})); diff != "" { t.Errorf("Unexpected response (-wanted, +got): %s", diff) diff --git a/internal/fwserver/attribute_validation_test.go b/internal/fwserver/attribute_validation_test.go index 808a05b63..d26311c7c 100644 --- a/internal/fwserver/attribute_validation_test.go +++ b/internal/fwserver/attribute_validation_test.go @@ -9,7 +9,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/diag" testtypes "github.com/hashicorp/terraform-plugin-framework/internal/testing/types" - "github.com/hashicorp/terraform-plugin-framework/internal/totftypes" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" @@ -1085,25 +1084,13 @@ func TestAttributeValidate(t *testing.T) { var got tfsdk.ValidateAttributeResponse - // TODO: Remove after schema refactoring - // Reference: https://github.com/hashicorp/terraform-plugin-framework/issues/365 - tftypesPath, diags := totftypes.AttributePath(ctx, tc.req.AttributePath) + attribute, diags := tc.req.Config.Schema.AttributeAtPath(ctx, tc.req.AttributePath) if diags.HasError() { - for _, diagnostic := range diags { - t.Errorf("unexpected diagnostic: %s", diagnostic) - } - - return - } - - attribute, err := tc.req.Config.Schema.AttributeAtTerraformPath(ctx, tftypesPath) - - if err != nil { - t.Fatalf("Unexpected error getting %s", err) + t.Fatalf("Unexpected diagnostics: %s", diags) } - AttributeValidate(context.Background(), attribute, tc.req, &got) + AttributeValidate(ctx, attribute, tc.req, &got) if diff := cmp.Diff(got, tc.resp); diff != "" { t.Errorf("Unexpected response (+wanted, -got): %s", diff) diff --git a/internal/fwserver/server_planresourcechange_test.go b/internal/fwserver/server_planresourcechange_test.go index 3f602bd30..6dbc5be72 100644 --- a/internal/fwserver/server_planresourcechange_test.go +++ b/internal/fwserver/server_planresourcechange_test.go @@ -153,7 +153,7 @@ func TestMarkComputedNilsAsUnknown(t *testing.T) { "string-set": tftypes.NewValue(tftypes.String, "bar"), }), }) - expected := tftypes.NewValue(s.TerraformType(context.Background()), map[string]tftypes.Value{ + expected := tftypes.NewValue(s.Type().TerraformType(context.Background()), map[string]tftypes.Value{ "string-value": tftypes.NewValue(tftypes.String, "hello, world"), "string-nil": tftypes.NewValue(tftypes.String, nil), "string-nil-computed": tftypes.NewValue(tftypes.String, tftypes.UnknownValue), diff --git a/tfsdk/schema.go b/tfsdk/schema.go index 2153b1985..b89be1c75 100644 --- a/tfsdk/schema.go +++ b/tfsdk/schema.go @@ -101,19 +101,6 @@ func (s Schema) ApplyTerraform5AttributePathStep(step tftypes.AttributePathStep) return nil, fmt.Errorf("could not find attribute or block %q in schema", a) } -// AttributeType returns a types.ObjectType composed from the schema types. -// Deprecated: Use Type() instead. -func (s Schema) AttributeType() attr.Type { - return s.Type() -} - -// AttributeTypeAtPath returns the attr.Type of the attribute at the given path. -// -// Deprecated: Use the TypeAtPath() or TypeAtTerraformPath() method. -func (s Schema) AttributeTypeAtPath(path *tftypes.AttributePath) (attr.Type, error) { - return s.TypeAtTerraformPath(context.Background(), path) -} - // TypeAtPath returns the framework type at the given schema path. func (s Schema) TypeAtPath(ctx context.Context, schemaPath path.Path) (attr.Type, diag.Diagnostics) { var diags diag.Diagnostics @@ -133,7 +120,7 @@ func (s Schema) TypeAtPath(ctx context.Context, schemaPath path.Path) (attr.Type schemaPath, "Invalid Schema Path", "When attempting to get the framework type associated with a schema path, an unexpected error was returned. "+ - "This is either an issue with the provider or terraform-plugin-framework. Please report this to the provider developers.\n\n"+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ fmt.Sprintf("Path: %s\n", schemaPath.String())+ fmt.Sprintf("Original Error: %s", err), ) @@ -198,12 +185,6 @@ func (s Schema) GetVersion() int64 { return s.Version } -// TerraformType returns a tftypes.Type that can represent the schema. -// Deprecated: Use Type().TerraformType() instead. -func (s Schema) TerraformType(ctx context.Context) tftypes.Type { - return s.Type().TerraformType(ctx) -} - // Type returns the framework type of the schema. func (s Schema) Type() attr.Type { attrTypes := map[string]attr.Type{} @@ -222,12 +203,32 @@ func (s Schema) Type() attr.Type { // AttributeAtPath returns the Attribute at the passed path. If the path points // to an element or attribute of a complex type, rather than to an Attribute, // it will return an ErrPathInsideAtomicAttribute error. -// -// Deprecated: The signature will be updated in the next release. -// Use AttributeAtTerraformPath() if the *tftypes.AttributePath parameter is -// still needed. -func (s Schema) AttributeAtPath(path *tftypes.AttributePath) (fwschema.Attribute, error) { - return s.AttributeAtTerraformPath(context.Background(), path) +func (s Schema) AttributeAtPath(ctx context.Context, schemaPath path.Path) (fwschema.Attribute, diag.Diagnostics) { + var diags diag.Diagnostics + + tftypesPath, tftypesDiags := totftypes.AttributePath(ctx, schemaPath) + + diags.Append(tftypesDiags...) + + if diags.HasError() { + return nil, diags + } + + attribute, err := s.AttributeAtTerraformPath(ctx, tftypesPath) + + if err != nil { + diags.AddAttributeError( + schemaPath, + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + fmt.Sprintf("Path: %s\n", schemaPath.String())+ + fmt.Sprintf("Original Error: %s", err), + ) + return nil, diags + } + + return attribute, diags } // AttributeAtPath returns the Attribute at the passed path. If the path points diff --git a/tfsdk/schema_test.go b/tfsdk/schema_test.go index 546ab85da..6c0e243b2 100644 --- a/tfsdk/schema_test.go +++ b/tfsdk/schema_test.go @@ -9,6 +9,7 @@ import ( "github.com/google/go-cmp/cmp" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/diag" + "github.com/hashicorp/terraform-plugin-framework/internal/fwschema" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" @@ -18,22 +19,25 @@ func TestSchemaAttributeAtPath(t *testing.T) { t.Parallel() testCases := map[string]struct { - schema Schema - path *tftypes.AttributePath - expected Attribute - expectedErr string + schema Schema + path path.Path + expected fwschema.Attribute + expectedDiags diag.Diagnostics }{ "empty-root": { - schema: Schema{}, - path: tftypes.NewAttributePath(), - expected: Attribute{}, - expectedErr: "got unexpected type tfsdk.Schema", - }, - "empty-nil": { - schema: Schema{}, - path: nil, - expected: Attribute{}, - expectedErr: "got unexpected type tfsdk.Schema", + schema: Schema{}, + path: path.Empty(), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Empty(), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: \n"+ + "Original Error: got unexpected type tfsdk.Schema", + ), + }, }, "root": { schema: Schema{ @@ -44,22 +48,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath(), - expected: Attribute{}, - expectedErr: "got unexpected type tfsdk.Schema", - }, - "nil": { - schema: Schema{ - Attributes: map[string]Attribute{ - "test": { - Type: types.StringType, - Required: true, - }, - }, + path: path.Empty(), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Empty(), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: \n"+ + "Original Error: got unexpected type tfsdk.Schema", + ), }, - path: nil, - expected: Attribute{}, - expectedErr: "got unexpected type tfsdk.Schema", }, "WithAttributeName": { schema: Schema{ @@ -74,7 +74,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test"), + path: path.Root("test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -102,9 +102,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), - expected: Attribute{}, - expectedErr: "AttributeName(\"sub_test\") still remains in the path: can't apply tftypes.AttributeName to ListNestedAttributes", + path: path.Root("test").AtName("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtName("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test.sub_test\n"+ + "Original Error: AttributeName(\"sub_test\") still remains in the path: can't apply tftypes.AttributeName to ListNestedAttributes", + ), + }, }, "WithAttributeName-ListNestedAttributes-WithElementKeyInt": { schema: Schema{ @@ -128,9 +137,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-ListNestedAttributes-WithElementKeyInt-WithAttributeName": { schema: Schema{ @@ -154,7 +172,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0).WithAttributeName("sub_test"), + path: path.Root("test").AtListIndex(0).AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -182,9 +200,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("sub_test"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to ListNestedAttributes", + path: path.Root("test").AtMapKey("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"sub_test\"]\n"+ + "Original Error: ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to ListNestedAttributes", + ), + }, }, "WithAttributeName-ListNestedAttributes-WithElementKeyValue": { schema: Schema{ @@ -208,9 +235,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "sub_test")), - expected: Attribute{}, - expectedErr: "ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't apply tftypes.ElementKeyValue to ListNestedAttributes", + path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"sub_test\")]\n"+ + "Original Error: ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't apply tftypes.ElementKeyValue to ListNestedAttributes", + ), + }, }, "WithAttributeName-ListNestedBlocks-WithAttributeName": { schema: Schema{ @@ -245,9 +281,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), - expected: Attribute{}, - expectedErr: "AttributeName(\"sub_test\") still remains in the path: can't apply tftypes.AttributeName to block NestingModeList", + path: path.Root("test").AtName("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtName("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test.sub_test\n"+ + "Original Error: AttributeName(\"sub_test\") still remains in the path: can't apply tftypes.AttributeName to block NestingModeList", + ), + }, }, "WithAttributeName-ListNestedBlocks-WithElementKeyInt": { schema: Schema{ @@ -282,9 +327,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-ListNestedBlocks-WithElementKeyInt-WithAttributeName": { schema: Schema{ @@ -319,7 +373,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0).WithAttributeName("sub_test"), + path: path.Root("test").AtListIndex(0).AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -358,9 +412,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("sub_test"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to block NestingModeList", + path: path.Root("test").AtMapKey("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"sub_test\"]\n"+ + "Original Error: ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to block NestingModeList", + ), + }, }, "WithAttributeName-ListNestedBlocks-WithElementKeyValue": { schema: Schema{ @@ -395,9 +458,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "sub_test")), - expected: Attribute{}, - expectedErr: "ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't apply tftypes.ElementKeyValue to block NestingModeList", + path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"sub_test\")]\n"+ + "Original Error: ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't apply tftypes.ElementKeyValue to block NestingModeList", + ), + }, }, "WithAttributeName-MapNestedAttributes-WithAttributeName": { schema: Schema{ @@ -421,9 +493,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), - expected: Attribute{}, - expectedErr: "AttributeName(\"sub_test\") still remains in the path: can't use tftypes.AttributeName on maps", + path: path.Root("test").AtName("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtName("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test.sub_test\n"+ + "Original Error: AttributeName(\"sub_test\") still remains in the path: can't use tftypes.AttributeName on maps", + ), + }, }, "WithAttributeName-MapNestedAttributes-WithElementKeyInt": { schema: Schema{ @@ -447,9 +528,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: "ElementKeyInt(0) still remains in the path: can't use tftypes.ElementKeyInt on maps", + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: ElementKeyInt(0) still remains in the path: can't use tftypes.ElementKeyInt on maps", + ), + }, }, "WithAttributeName-MapNestedAttributes-WithElementKeyString": { schema: Schema{ @@ -473,9 +563,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("sub_test"), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtMapKey("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"sub_test\"]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-MapNestedAttributes-WithElementKeyString-WithAttributeName": { schema: Schema{ @@ -499,7 +598,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("element").WithAttributeName("sub_test"), + path: path.Root("test").AtMapKey("element").AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -527,9 +626,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "sub_test")), - expected: Attribute{}, - expectedErr: "ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't use tftypes.ElementKeyValue on maps", + path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"sub_test\")]\n"+ + "Original Error: ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't use tftypes.ElementKeyValue on maps", + ), + }, }, "WithAttributeName-SetNestedAttributes-WithAttributeName": { schema: Schema{ @@ -553,9 +661,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), - expected: Attribute{}, - expectedErr: "AttributeName(\"sub_test\") still remains in the path: can't use tftypes.AttributeName on sets", + path: path.Root("test").AtName("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtName("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test.sub_test\n"+ + "Original Error: AttributeName(\"sub_test\") still remains in the path: can't use tftypes.AttributeName on sets", + ), + }, }, "WithAttributeName-SetNestedAttributes-WithElementKeyInt": { schema: Schema{ @@ -579,9 +696,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: "ElementKeyInt(0) still remains in the path: can't use tftypes.ElementKeyInt on sets", + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: ElementKeyInt(0) still remains in the path: can't use tftypes.ElementKeyInt on sets", + ), + }, }, "WithAttributeName-SetNestedAttributes-WithElementKeyString": { schema: Schema{ @@ -605,9 +731,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("sub_test"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"sub_test\") still remains in the path: can't use tftypes.ElementKeyString on sets", + path: path.Root("test").AtMapKey("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"sub_test\"]\n"+ + "Original Error: ElementKeyString(\"sub_test\") still remains in the path: can't use tftypes.ElementKeyString on sets", + ), + }, }, "WithAttributeName-SetNestedAttributes-WithElementKeyValue": { schema: Schema{ @@ -631,9 +766,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "sub_test")), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"sub_test\")]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-SetNestedAttributes-WithElementKeyValue-WithAttributeName": { schema: Schema{ @@ -657,7 +801,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "element")).WithAttributeName("sub_test"), + path: path.Root("test").AtSetValue(types.String{Value: "element"}).AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -696,9 +840,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), - expected: Attribute{}, - expectedErr: "AttributeName(\"sub_test\") still remains in the path: can't apply tftypes.AttributeName to block NestingModeSet", + path: path.Root("test").AtName("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtName("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test.sub_test\n"+ + "Original Error: AttributeName(\"sub_test\") still remains in the path: can't apply tftypes.AttributeName to block NestingModeSet", + ), + }, }, "WithAttributeName-SetNestedBlocks-WithElementKeyInt": { schema: Schema{ @@ -733,9 +886,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: "ElementKeyInt(0) still remains in the path: can't apply tftypes.ElementKeyInt to block NestingModeSet", + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: ElementKeyInt(0) still remains in the path: can't apply tftypes.ElementKeyInt to block NestingModeSet", + ), + }, }, "WithAttributeName-SetNestedBlocks-WithElementKeyString": { schema: Schema{ @@ -770,9 +932,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("sub_test"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to block NestingModeSet", + path: path.Root("test").AtMapKey("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"sub_test\"]\n"+ + "Original Error: ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to block NestingModeSet", + ), + }, }, "WithAttributeName-SetNestedBlocks-WithElementKeyValue": { schema: Schema{ @@ -807,9 +978,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "sub_test")), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"sub_test\")]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-SetNestedBlocks-WithElementKeyValue-WithAttributeName": { schema: Schema{ @@ -844,7 +1024,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "element")).WithAttributeName("sub_test"), + path: path.Root("test").AtSetValue(types.String{Value: "element"}).AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -872,7 +1052,7 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), + path: path.Root("test").AtName("sub_test"), expected: Attribute{ Type: types.StringType, Required: true, @@ -900,9 +1080,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: "ElementKeyInt(0) still remains in the path: can't apply tftypes.ElementKeyInt to Attributes", + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: ElementKeyInt(0) still remains in the path: can't apply tftypes.ElementKeyInt to Attributes", + ), + }, }, "WithAttributeName-SingleNestedAttributes-WithElementKeyString": { schema: Schema{ @@ -926,9 +1115,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("sub_test"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to Attributes", + path: path.Root("test").AtMapKey("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"sub_test\"]\n"+ + "Original Error: ElementKeyString(\"sub_test\") still remains in the path: can't apply tftypes.ElementKeyString to Attributes", + ), + }, }, "WithAttributeName-SingleNestedAttributes-WithElementKeyValue": { schema: Schema{ @@ -952,9 +1150,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "sub_test")), - expected: Attribute{}, - expectedErr: "ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't apply tftypes.ElementKeyValue to Attributes", + path: path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "sub_test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"sub_test\")]\n"+ + "Original Error: ElementKeyValue(tftypes.String<\"sub_test\">) still remains in the path: can't apply tftypes.ElementKeyValue to Attributes", + ), + }, }, "WithAttributeName-Object-WithAttributeName": { schema: Schema{ @@ -973,9 +1180,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithAttributeName("sub_test"), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtName("sub_test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtName("sub_test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test.sub_test\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-WithElementKeyInt-invalid-parent": { schema: Schema{ @@ -990,9 +1206,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: "ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to types.StringType", + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to types.StringType", + ), + }, }, "WithAttributeName-WithElementKeyInt-valid-parent": { schema: Schema{ @@ -1009,9 +1234,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[0]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-WithElementKeyString-invalid-parent": { schema: Schema{ @@ -1026,9 +1260,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("element"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"element\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to types.StringType", + path: path.Root("test").AtMapKey("element"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("element"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"element\"]\n"+ + "Original Error: ElementKeyString(\"element\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to types.StringType", + ), + }, }, "WithAttributeName-WithElementKeyString-valid-parent": { schema: Schema{ @@ -1045,9 +1288,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyString("element"), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtMapKey("element"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtMapKey("element"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[\"element\"]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithAttributeName-WithElementKeyValue-invalid-parent": { schema: Schema{ @@ -1062,9 +1314,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "element")), - expected: Attribute{}, - expectedErr: "ElementKeyValue(tftypes.String<\"element\">) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyValue to types.StringType", + path: path.Root("test").AtSetValue(types.String{Value: "element"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "element"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"element\")]\n"+ + "Original Error: ElementKeyValue(tftypes.String<\"element\">) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyValue to types.StringType", + ), + }, }, "WithAttributeName-WithElementKeyValue-valid-parent": { schema: Schema{ @@ -1081,9 +1342,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithAttributeName("test").WithElementKeyValue(tftypes.NewValue(tftypes.String, "element")), - expected: Attribute{}, - expectedErr: ErrPathInsideAtomicAttribute.Error(), + path: path.Root("test").AtSetValue(types.String{Value: "element"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Root("test").AtSetValue(types.String{Value: "element"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: test[Value(\"element\")]\n"+ + "Original Error: "+ErrPathInsideAtomicAttribute.Error(), + ), + }, }, "WithElementKeyInt": { schema: Schema{ @@ -1094,9 +1364,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithElementKeyInt(0), - expected: Attribute{}, - expectedErr: "ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to schema", + path: path.Empty().AtListIndex(0), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Empty().AtListIndex(0), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: [0]\n"+ + "Original Error: ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to schema", + ), + }, }, "WithElementKeyString": { schema: Schema{ @@ -1107,9 +1386,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithElementKeyString("test"), - expected: Attribute{}, - expectedErr: "ElementKeyString(\"test\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to schema", + path: path.Empty().AtMapKey("test"), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Empty().AtMapKey("test"), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: [\"test\"]\n"+ + "Original Error: ElementKeyString(\"test\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to schema", + ), + }, }, "WithElementKeyValue": { schema: Schema{ @@ -1120,9 +1408,18 @@ func TestSchemaAttributeAtPath(t *testing.T) { }, }, }, - path: tftypes.NewAttributePath().WithElementKeyValue(tftypes.NewValue(tftypes.String, "test")), - expected: Attribute{}, - expectedErr: "ElementKeyValue(tftypes.String<\"test\">) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyValue to schema", + path: path.Empty().AtSetValue(types.String{Value: "test"}), + expected: nil, + expectedDiags: diag.Diagnostics{ + diag.NewAttributeErrorDiagnostic( + path.Empty().AtSetValue(types.String{Value: "test"}), + "Invalid Schema Path", + "When attempting to get the framework attribute associated with a schema path, an unexpected error was returned. "+ + "This is always an issue with the provider. Please report this to the provider developers.\n\n"+ + "Path: [Value(\"test\")]\n"+ + "Original Error: ElementKeyValue(tftypes.String<\"test\">) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyValue to schema", + ), + }, }, } @@ -1132,24 +1429,10 @@ func TestSchemaAttributeAtPath(t *testing.T) { t.Run(name, func(t *testing.T) { t.Parallel() - got, err := tc.schema.AttributeAtPath(tc.path) - - if err != nil { - if tc.expectedErr == "" { - t.Errorf("Unexpected error: %s", err) - return - } - if err.Error() != tc.expectedErr { - t.Errorf("Expected error to be %q, got %q", tc.expectedErr, err.Error()) - return - } - // got expected error - return - } + got, diags := tc.schema.AttributeAtPath(context.Background(), tc.path) - if err == nil && tc.expectedErr != "" { - t.Errorf("Expected error to be %q, got nil", tc.expectedErr) - return + if diff := cmp.Diff(diags, tc.expectedDiags); diff != "" { + t.Errorf("Unexpected diagnostics (+wanted, -got): %s", diff) } if diff := cmp.Diff(got, tc.expected); diff != "" { @@ -2531,7 +2814,7 @@ func TestSchemaTypeAtPath(t *testing.T) { diag.NewAttributeErrorDiagnostic( path.Root("non-existent"), "Invalid Schema Path", - "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is either an issue with the provider or terraform-plugin-framework. Please report this to the provider developers.\n\n"+ + "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: non-existent\n"+ "Original Error: AttributeName(\"non-existent\") still remains in the path: could not find attribute or block \"non-existent\" in schema", ), @@ -2544,7 +2827,7 @@ func TestSchemaTypeAtPath(t *testing.T) { diag.NewAttributeErrorDiagnostic( path.Empty().AtListIndex(0), "Invalid Schema Path", - "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is either an issue with the provider or terraform-plugin-framework. Please report this to the provider developers.\n\n"+ + "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: [0]\n"+ "Original Error: ElementKeyInt(0) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyInt to schema", ), @@ -2557,7 +2840,7 @@ func TestSchemaTypeAtPath(t *testing.T) { diag.NewAttributeErrorDiagnostic( path.Empty().AtMapKey("invalid"), "Invalid Schema Path", - "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is either an issue with the provider or terraform-plugin-framework. Please report this to the provider developers.\n\n"+ + "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: [\"invalid\"]\n"+ "Original Error: ElementKeyString(\"invalid\") still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyString to schema", ), @@ -2570,7 +2853,7 @@ func TestSchemaTypeAtPath(t *testing.T) { diag.NewAttributeErrorDiagnostic( path.Empty().AtSetValue(types.String{Null: true}), "Invalid Schema Path", - "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is either an issue with the provider or terraform-plugin-framework. Please report this to the provider developers.\n\n"+ + "When attempting to get the framework type associated with a schema path, an unexpected error was returned. This is always an issue with the provider. Please report this to the provider developers.\n\n"+ "Path: [Value()]\n"+ "Original Error: ElementKeyValue(tftypes.String) still remains in the path: cannot apply AttributePathStep tftypes.ElementKeyValue to schema", ),