Skip to content

Commit

Permalink
Refactoring func name to {TYPE}DefaultValue() (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Mar 6, 2023
1 parent bdd3313 commit 0438d70
Show file tree
Hide file tree
Showing 32 changed files with 75 additions and 75 deletions.
18 changes: 9 additions & 9 deletions internal/fwschema/attribute_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,69 +9,69 @@ import (
type AttributeWithBoolDefaultValue interface {
Attribute

DefaultValue() defaults.Bool
BoolDefaultValue() defaults.Bool
}

// AttributeWithFloat64DefaultValue is an optional interface on Attribute which
// enables Float64 default value support.
type AttributeWithFloat64DefaultValue interface {
Attribute

DefaultValue() defaults.Float64
Float64DefaultValue() defaults.Float64
}

// AttributeWithInt64DefaultValue is an optional interface on Attribute which
// enables Int64 default value support.
type AttributeWithInt64DefaultValue interface {
Attribute

DefaultValue() defaults.Int64
Int64DefaultValue() defaults.Int64
}

// AttributeWithListDefaultValue is an optional interface on Attribute which
// enables List default value support.
type AttributeWithListDefaultValue interface {
Attribute

DefaultValue() defaults.List
ListDefaultValue() defaults.List
}

// AttributeWithMapDefaultValue is an optional interface on Attribute which
// enables Map default value support.
type AttributeWithMapDefaultValue interface {
Attribute

DefaultValue() defaults.Map
MapDefaultValue() defaults.Map
}

// AttributeWithNumberDefaultValue is an optional interface on Attribute which
// enables Number default value support.
type AttributeWithNumberDefaultValue interface {
Attribute

DefaultValue() defaults.Number
NumberDefaultValue() defaults.Number
}

// AttributeWithObjectDefaultValue is an optional interface on Attribute which
// enables Object default value support.
type AttributeWithObjectDefaultValue interface {
Attribute

DefaultValue() defaults.Object
ObjectDefaultValue() defaults.Object
}

// AttributeWithSetDefaultValue is an optional interface on Attribute which
// enables Set default value support.
type AttributeWithSetDefaultValue interface {
Attribute

DefaultValue() defaults.Set
SetDefaultValue() defaults.Set
}

// AttributeWithStringDefaultValue is an optional interface on Attribute which
// enables String default value support.
type AttributeWithStringDefaultValue interface {
Attribute

DefaultValue() defaults.String
StringDefaultValue() defaults.String
}
18 changes: 9 additions & 9 deletions internal/fwschemadata/data_default.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,63 +71,63 @@ func (d *Data) TransformDefaults(ctx context.Context, configRaw tftypes.Value) d

switch a := attrAtPath.(type) {
case fwschema.AttributeWithBoolDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.BoolDefaultValue()
if defaultValue != nil {
resp := defaults.BoolResponse{}
defaultValue.DefaultBool(ctx, defaults.BoolRequest{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithFloat64DefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.Float64DefaultValue()
if defaultValue != nil {
resp := defaults.Float64Response{}
defaultValue.DefaultFloat64(ctx, defaults.Float64Request{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithInt64DefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.Int64DefaultValue()
if defaultValue != nil {
resp := defaults.Int64Response{}
defaultValue.DefaultInt64(ctx, defaults.Int64Request{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithListDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.ListDefaultValue()
if defaultValue != nil {
resp := defaults.ListResponse{}
defaultValue.DefaultList(ctx, defaults.ListRequest{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithMapDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.MapDefaultValue()
if defaultValue != nil {
resp := defaults.MapResponse{}
defaultValue.DefaultMap(ctx, defaults.MapRequest{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithNumberDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.NumberDefaultValue()
if defaultValue != nil {
resp := defaults.NumberResponse{}
defaultValue.DefaultNumber(ctx, defaults.NumberRequest{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithObjectDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.ObjectDefaultValue()
if defaultValue != nil {
resp := defaults.ObjectResponse{}
defaultValue.DefaultObject(ctx, defaults.ObjectRequest{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithSetDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.SetDefaultValue()
if defaultValue != nil {
resp := defaults.SetResponse{}
defaultValue.DefaultSet(ctx, defaults.SetRequest{}, &resp)
return resp.PlanValue.ToTerraformValue(ctx)
}
case fwschema.AttributeWithStringDefaultValue:
defaultValue := a.DefaultValue()
defaultValue := a.StringDefaultValue()
if defaultValue != nil {
resp := defaults.StringResponse{}
defaultValue.DefaultString(ctx, defaults.StringRequest{}, &resp)
Expand Down
18 changes: 9 additions & 9 deletions internal/fwserver/server_planresourcechange.go
Original file line number Diff line number Diff line change
Expand Up @@ -368,39 +368,39 @@ func MarkComputedNilsAsUnknown(ctx context.Context, config tftypes.Value, resour

switch a := attribute.(type) {
case fwschema.AttributeWithBoolDefaultValue:
if a.DefaultValue() != nil {
if a.BoolDefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithFloat64DefaultValue:
if a.DefaultValue() != nil {
if a.Float64DefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithInt64DefaultValue:
if a.DefaultValue() != nil {
if a.Int64DefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithListDefaultValue:
if a.DefaultValue() != nil {
if a.ListDefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithMapDefaultValue:
if a.DefaultValue() != nil {
if a.MapDefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithNumberDefaultValue:
if a.DefaultValue() != nil {
if a.NumberDefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithObjectDefaultValue:
if a.DefaultValue() != nil {
if a.ObjectDefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithSetDefaultValue:
if a.DefaultValue() != nil {
if a.SetDefaultValue() != nil {
return val, nil
}
case fwschema.AttributeWithStringDefaultValue:
if a.DefaultValue() != nil {
if a.StringDefaultValue() != nil {
return val, nil
}
}
Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithbooldefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (a AttributeWithBoolDefaultValue) ApplyTerraform5AttributePathStep(step tft
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwxschema.AttributeWithBoolDefaultValue interface.
func (a AttributeWithBoolDefaultValue) DefaultValue() defaults.Bool {
// BoolDefaultValue satisfies the fwxschema.AttributeWithBoolDefaultValue interface.
func (a AttributeWithBoolDefaultValue) BoolDefaultValue() defaults.Bool {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithfloat64default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (a AttributeWithFloat64DefaultValue) ApplyTerraform5AttributePathStep(step
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwxschema.AttributeWithFloat64DefaultValue interface.
func (a AttributeWithFloat64DefaultValue) DefaultValue() defaults.Float64 {
// Float64DefaultValue satisfies the fwxschema.AttributeWithFloat64DefaultValue interface.
func (a AttributeWithFloat64DefaultValue) Float64DefaultValue() defaults.Float64 {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithint64default.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (a AttributeWithInt64DefaultValue) ApplyTerraform5AttributePathStep(step tf
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwxschema.AttributeWithInt64DefaultValue interface.
func (a AttributeWithInt64DefaultValue) DefaultValue() defaults.Int64 {
// Int64DefaultValue satisfies the fwxschema.AttributeWithInt64DefaultValue interface.
func (a AttributeWithInt64DefaultValue) Int64DefaultValue() defaults.Int64 {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithlistdefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (a AttributeWithListDefaultValue) ApplyTerraform5AttributePathStep(step tft
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwschema.AttributeWithInt64DefaultValue interface.
func (a AttributeWithListDefaultValue) DefaultValue() defaults.List {
// ListDefaultValue satisfies the fwschema.AttributeWithInt64DefaultValue interface.
func (a AttributeWithListDefaultValue) ListDefaultValue() defaults.List {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithmapdefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (a AttributeWithMapDefaultValue) ApplyTerraform5AttributePathStep(step tfty
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwschema.AttributeWithInt64DefaultValue interface.
func (a AttributeWithMapDefaultValue) DefaultValue() defaults.Map {
// MapDefaultValue satisfies the fwschema.AttributeWithInt64DefaultValue interface.
func (a AttributeWithMapDefaultValue) MapDefaultValue() defaults.Map {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithnumberdefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (a AttributeWithNumberDefaultValue) ApplyTerraform5AttributePathStep(step t
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwxschema.AttributeWithNumberDefaultValue interface.
func (a AttributeWithNumberDefaultValue) DefaultValue() defaults.Number {
// NumberDefaultValue satisfies the fwxschema.AttributeWithNumberDefaultValue interface.
func (a AttributeWithNumberDefaultValue) NumberDefaultValue() defaults.Number {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithobjectdefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (a AttributeWithObjectDefaultValue) ApplyTerraform5AttributePathStep(step t
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwschema.AttributeWithObjectDefaultValue interface.
func (a AttributeWithObjectDefaultValue) DefaultValue() defaults.Object {
// ObjectDefaultValue satisfies the fwschema.AttributeWithObjectDefaultValue interface.
func (a AttributeWithObjectDefaultValue) ObjectDefaultValue() defaults.Object {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithsetdefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ func (a AttributeWithSetDefaultValue) ApplyTerraform5AttributePathStep(step tfty
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwschema.AttributeWithSetDefaultValue interface.
func (a AttributeWithSetDefaultValue) DefaultValue() defaults.Set {
// SetDefaultValue satisfies the fwschema.AttributeWithSetDefaultValue interface.
func (a AttributeWithSetDefaultValue) SetDefaultValue() defaults.Set {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions internal/testing/testschema/attributewithstringdefault.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@ func (a AttributeWithStringDefaultValue) ApplyTerraform5AttributePathStep(step t
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwxschema.AttributeWithStringDefaultValue interface.
func (a AttributeWithStringDefaultValue) DefaultValue() defaults.String {
// StringDefaultValue satisfies the fwxschema.AttributeWithStringDefaultValue interface.
func (a AttributeWithStringDefaultValue) StringDefaultValue() defaults.String {
return a.Default
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ func (a NestedAttributeWithListDefaultValue) ApplyTerraform5AttributePathStep(st
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue satisfies the fwschema.AttributeWithListDefaultValue interface.
func (a NestedAttributeWithListDefaultValue) DefaultValue() defaults.List {
// ListDefaultValue satisfies the fwschema.AttributeWithListDefaultValue interface.
func (a NestedAttributeWithListDefaultValue) ListDefaultValue() defaults.List {
return a.Default
}

Expand Down
4 changes: 2 additions & 2 deletions resource/schema/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -162,8 +162,8 @@ func (a BoolAttribute) BoolValidators() []validator.Bool {
return a.Validators
}

// DefaultValue returns the Default field value.
func (a BoolAttribute) DefaultValue() defaults.Bool {
// BoolDefaultValue returns the Default field value.
func (a BoolAttribute) BoolDefaultValue() defaults.Bool {
return a.Default
}

Expand Down
2 changes: 1 addition & 1 deletion resource/schema/bool_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ func TestBoolAttributeDefault(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.DefaultValue()
got := testCase.attribute.BoolDefaultValue()

if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
4 changes: 2 additions & 2 deletions resource/schema/float64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func (a Float64Attribute) ApplyTerraform5AttributePathStep(step tftypes.Attribut
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue returns the Default field value.
func (a Float64Attribute) DefaultValue() defaults.Float64 {
// Float64DefaultValue returns the Default field value.
func (a Float64Attribute) Float64DefaultValue() defaults.Float64 {
return a.Default
}

Expand Down
2 changes: 1 addition & 1 deletion resource/schema/float64_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestFloat64AttributeDefault(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.DefaultValue()
got := testCase.attribute.Float64DefaultValue()

if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
4 changes: 2 additions & 2 deletions resource/schema/int64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,8 @@ func (a Int64Attribute) ApplyTerraform5AttributePathStep(step tftypes.AttributeP
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue returns the Default field value.
func (a Int64Attribute) DefaultValue() defaults.Int64 {
// Int64DefaultValue returns the Default field value.
func (a Int64Attribute) Int64DefaultValue() defaults.Int64 {
return a.Default
}

Expand Down
2 changes: 1 addition & 1 deletion resource/schema/int64_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ func TestInt64AttributeDefault(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.DefaultValue()
got := testCase.attribute.Int64DefaultValue()

if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
4 changes: 2 additions & 2 deletions resource/schema/list_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,8 +163,8 @@ func (a ListAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePa
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

// DefaultValue returns the Default field value.
func (a ListAttribute) DefaultValue() defaults.List {
// ListDefaultValue returns the Default field value.
func (a ListAttribute) ListDefaultValue() defaults.List {
return a.Default
}

Expand Down
2 changes: 1 addition & 1 deletion resource/schema/list_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ func TestListAttributeDefault(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.DefaultValue()
got := testCase.attribute.ListDefaultValue()

if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand Down
2 changes: 1 addition & 1 deletion resource/schema/list_nested_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ func (a ListNestedAttribute) ApplyTerraform5AttributePathStep(step tftypes.Attri
return a.NestedObject, nil
}

func (a ListNestedAttribute) DefaultValue() defaults.List {
func (a ListNestedAttribute) ListDefaultValue() defaults.List {
return a.Default
}

Expand Down

0 comments on commit 0438d70

Please sign in to comment.