Skip to content

Commit

Permalink
Adding Default to remaining resource schema attributes (#668)
Browse files Browse the repository at this point in the history
  • Loading branch information
bendbennett committed Mar 6, 2023
1 parent 23c6921 commit 54caecb
Show file tree
Hide file tree
Showing 26 changed files with 794 additions and 487 deletions.
10 changes: 5 additions & 5 deletions resource/schema/bool_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,11 @@ func (a BoolAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePa
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

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

// BoolPlanModifiers returns the PlanModifiers field value.
func (a BoolAttribute) BoolPlanModifiers() []planmodifier.Bool {
return a.PlanModifiers
Expand All @@ -164,11 +169,6 @@ func (a BoolAttribute) BoolValidators() []validator.Bool {
return a.Validators
}

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

// Equal returns true if the given Attribute is a BoolAttribute
// and all fields are equal.
func (a BoolAttribute) Equal(o fwschema.Attribute) bool {
Expand Down
72 changes: 36 additions & 36 deletions resource/schema/bool_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,22 +85,35 @@ func TestBoolAttributeApplyTerraform5AttributePathStep(t *testing.T) {
}
}

func TestBoolAttributeBoolPlanModifiers(t *testing.T) {
func TestBoolAttributeBoolDefaultValue(t *testing.T) {
t.Parallel()

opt := cmp.Comparer(func(x, y defaults.Bool) bool {
ctx := context.Background()
req := defaults.BoolRequest{}

xResp := defaults.BoolResponse{}
x.DefaultBool(ctx, req, &xResp)

yResp := defaults.BoolResponse{}
y.DefaultBool(ctx, req, &yResp)

return xResp.PlanValue.Equal(yResp.PlanValue)
})

testCases := map[string]struct {
attribute schema.BoolAttribute
expected []planmodifier.Bool
expected defaults.Bool
}{
"no-planmodifiers": {
"no-default": {
attribute: schema.BoolAttribute{},
expected: nil,
},
"planmodifiers": {
"default": {
attribute: schema.BoolAttribute{
PlanModifiers: []planmodifier.Bool{},
Default: booldefault.StaticValue(true),
},
expected: []planmodifier.Bool{},
expected: booldefault.StaticValue(true),
},
}

Expand All @@ -110,31 +123,31 @@ func TestBoolAttributeBoolPlanModifiers(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

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

if diff := cmp.Diff(got, testCase.expected); diff != "" {
if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestBoolAttributeBoolValidators(t *testing.T) {
func TestBoolAttributeBoolPlanModifiers(t *testing.T) {
t.Parallel()

testCases := map[string]struct {
attribute schema.BoolAttribute
expected []validator.Bool
expected []planmodifier.Bool
}{
"no-validators": {
"no-planmodifiers": {
attribute: schema.BoolAttribute{},
expected: nil,
},
"validators": {
"planmodifiers": {
attribute: schema.BoolAttribute{
Validators: []validator.Bool{},
PlanModifiers: []planmodifier.Bool{},
},
expected: []validator.Bool{},
expected: []planmodifier.Bool{},
},
}

Expand All @@ -144,7 +157,7 @@ func TestBoolAttributeBoolValidators(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.BoolValidators()
got := testCase.attribute.BoolPlanModifiers()

if diff := cmp.Diff(got, testCase.expected); diff != "" {
t.Errorf("unexpected difference: %s", diff)
Expand All @@ -153,35 +166,22 @@ func TestBoolAttributeBoolValidators(t *testing.T) {
}
}

func TestBoolAttributeDefault(t *testing.T) {
func TestBoolAttributeBoolValidators(t *testing.T) {
t.Parallel()

opt := cmp.Comparer(func(x, y defaults.Bool) bool {
ctx := context.Background()
req := defaults.BoolRequest{}

xResp := defaults.BoolResponse{}
x.DefaultBool(ctx, req, &xResp)

yResp := defaults.BoolResponse{}
y.DefaultBool(ctx, req, &yResp)

return xResp.PlanValue.Equal(yResp.PlanValue)
})

testCases := map[string]struct {
attribute schema.BoolAttribute
expected defaults.Bool
expected []validator.Bool
}{
"no-default": {
"no-validators": {
attribute: schema.BoolAttribute{},
expected: nil,
},
"default": {
"validators": {
attribute: schema.BoolAttribute{
Default: booldefault.StaticValue(true),
Validators: []validator.Bool{},
},
expected: booldefault.StaticValue(true),
expected: []validator.Bool{},
},
}

Expand All @@ -191,9 +191,9 @@ func TestBoolAttributeDefault(t *testing.T) {
t.Run(name, func(t *testing.T) {
t.Parallel()

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

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

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

// Equal returns true if the given Attribute is a Float64Attribute
// and all fields are equal.
func (a Float64Attribute) Equal(o fwschema.Attribute) bool {
Expand All @@ -172,6 +167,11 @@ func (a Float64Attribute) Equal(o fwschema.Attribute) bool {
return fwschema.AttributesEqual(a, o)
}

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

// Float64PlanModifiers returns the PlanModifiers field value.
func (a Float64Attribute) Float64PlanModifiers() []planmodifier.Float64 {
return a.PlanModifiers
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 @@ -84,7 +84,7 @@ func TestFloat64AttributeApplyTerraform5AttributePathStep(t *testing.T) {
}
}

func TestFloat64AttributeDefault(t *testing.T) {
func TestFloat64AttributeFloat64DefaultValue(t *testing.T) {
t.Parallel()

opt := cmp.Comparer(func(x, y defaults.Float64) bool {
Expand Down
10 changes: 5 additions & 5 deletions resource/schema/int64_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -157,11 +157,6 @@ func (a Int64Attribute) ApplyTerraform5AttributePathStep(step tftypes.AttributeP
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

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

// Equal returns true if the given Attribute is a Int64Attribute
// and all fields are equal.
func (a Int64Attribute) Equal(o fwschema.Attribute) bool {
Expand Down Expand Up @@ -196,6 +191,11 @@ func (a Int64Attribute) GetType() attr.Type {
return types.Int64Type
}

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

// Int64PlanModifiers returns the PlanModifiers field value.
func (a Int64Attribute) Int64PlanModifiers() []planmodifier.Int64 {
return a.PlanModifiers
Expand Down
94 changes: 47 additions & 47 deletions resource/schema/int64_attribute_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,53 +84,6 @@ func TestInt64AttributeApplyTerraform5AttributePathStep(t *testing.T) {
}
}

func TestInt64AttributeDefault(t *testing.T) {
t.Parallel()

opt := cmp.Comparer(func(x, y defaults.Int64) bool {
ctx := context.Background()
req := defaults.Int64Request{}

xResp := defaults.Int64Response{}
x.DefaultInt64(ctx, req, &xResp)

yResp := defaults.Int64Response{}
y.DefaultInt64(ctx, req, &yResp)

return xResp.PlanValue.Equal(yResp.PlanValue)
})

testCases := map[string]struct {
attribute schema.Int64Attribute
expected defaults.Int64
}{
"no-default": {
attribute: schema.Int64Attribute{},
expected: nil,
},
"default": {
attribute: schema.Int64Attribute{
Default: int64default.StaticValue(12345),
},
expected: int64default.StaticValue(12345),
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.Int64DefaultValue()

if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestInt64AttributeGetDeprecationMessage(t *testing.T) {
t.Parallel()

Expand Down Expand Up @@ -302,6 +255,53 @@ func TestInt64AttributeGetType(t *testing.T) {
}
}

func TestInt64AttributeInt64DefaultValue(t *testing.T) {
t.Parallel()

opt := cmp.Comparer(func(x, y defaults.Int64) bool {
ctx := context.Background()
req := defaults.Int64Request{}

xResp := defaults.Int64Response{}
x.DefaultInt64(ctx, req, &xResp)

yResp := defaults.Int64Response{}
y.DefaultInt64(ctx, req, &yResp)

return xResp.PlanValue.Equal(yResp.PlanValue)
})

testCases := map[string]struct {
attribute schema.Int64Attribute
expected defaults.Int64
}{
"no-default": {
attribute: schema.Int64Attribute{},
expected: nil,
},
"default": {
attribute: schema.Int64Attribute{
Default: int64default.StaticValue(12345),
},
expected: int64default.StaticValue(12345),
},
}

for name, testCase := range testCases {
name, testCase := name, testCase

t.Run(name, func(t *testing.T) {
t.Parallel()

got := testCase.attribute.Int64DefaultValue()

if diff := cmp.Diff(got, testCase.expected, opt); diff != "" {
t.Errorf("unexpected difference: %s", diff)
}
})
}
}

func TestInt64AttributeInt64PlanModifiers(t *testing.T) {
t.Parallel()

Expand Down
10 changes: 5 additions & 5 deletions resource/schema/list_attribute.go
Original file line number Diff line number Diff line change
Expand Up @@ -165,11 +165,6 @@ func (a ListAttribute) ApplyTerraform5AttributePathStep(step tftypes.AttributePa
return a.GetType().ApplyTerraform5AttributePathStep(step)
}

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

// Equal returns true if the given Attribute is a ListAttribute
// and all fields are equal.
func (a ListAttribute) Equal(o fwschema.Attribute) bool {
Expand Down Expand Up @@ -226,6 +221,11 @@ func (a ListAttribute) IsSensitive() bool {
return a.Sensitive
}

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

// ListPlanModifiers returns the PlanModifiers field value.
func (a ListAttribute) ListPlanModifiers() []planmodifier.List {
return a.PlanModifiers
Expand Down

0 comments on commit 54caecb

Please sign in to comment.