Skip to content

Commit 44d4a25

Browse files
committed
Add missing IsWriteOnly() unit tests for ephemeral/schema package
1 parent f73d27e commit 44d4a25

File tree

4 files changed

+118
-3
lines changed

4 files changed

+118
-3
lines changed

ephemeral/schema/float64_attribute_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"testing"
1010

1111
"github.com/google/go-cmp/cmp"
12+
"github.com/hashicorp/terraform-plugin-go/tftypes"
13+
1214
"github.com/hashicorp/terraform-plugin-framework/attr"
1315
"github.com/hashicorp/terraform-plugin-framework/ephemeral/schema"
1416
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
1517
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
1618
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
1719
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1820
"github.com/hashicorp/terraform-plugin-framework/types"
19-
"github.com/hashicorp/terraform-plugin-go/tftypes"
2021
)
2122

2223
func TestFloat64AttributeApplyTerraform5AttributePathStep(t *testing.T) {
@@ -423,3 +424,31 @@ func TestFloat64AttributeIsSensitive(t *testing.T) {
423424
})
424425
}
425426
}
427+
428+
func TestFloat54AttributeIsWriteOnly(t *testing.T) {
429+
t.Parallel()
430+
431+
testCases := map[string]struct {
432+
attribute schema.Float64Attribute
433+
expected bool
434+
}{
435+
"not-writeOnly": {
436+
attribute: schema.Float64Attribute{},
437+
expected: false,
438+
},
439+
}
440+
441+
for name, testCase := range testCases {
442+
name, testCase := name, testCase
443+
444+
t.Run(name, func(t *testing.T) {
445+
t.Parallel()
446+
447+
got := testCase.attribute.IsWriteOnly()
448+
449+
if diff := cmp.Diff(got, testCase.expected); diff != "" {
450+
t.Errorf("unexpected difference: %s", diff)
451+
}
452+
})
453+
}
454+
}

ephemeral/schema/int32_attribute_test.go

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,3 +424,31 @@ func TestInt32AttributeIsSensitive(t *testing.T) {
424424
})
425425
}
426426
}
427+
428+
func TestInt2AttributeIsWriteOnly(t *testing.T) {
429+
t.Parallel()
430+
431+
testCases := map[string]struct {
432+
attribute schema.Int32Attribute
433+
expected bool
434+
}{
435+
"not-writeOnly": {
436+
attribute: schema.Int32Attribute{},
437+
expected: false,
438+
},
439+
}
440+
441+
for name, testCase := range testCases {
442+
name, testCase := name, testCase
443+
444+
t.Run(name, func(t *testing.T) {
445+
t.Parallel()
446+
447+
got := testCase.attribute.IsWriteOnly()
448+
449+
if diff := cmp.Diff(got, testCase.expected); diff != "" {
450+
t.Errorf("unexpected difference: %s", diff)
451+
}
452+
})
453+
}
454+
}

ephemeral/schema/int64_attribute_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,15 @@ import (
99
"testing"
1010

1111
"github.com/google/go-cmp/cmp"
12+
"github.com/hashicorp/terraform-plugin-go/tftypes"
13+
1214
"github.com/hashicorp/terraform-plugin-framework/attr"
1315
"github.com/hashicorp/terraform-plugin-framework/ephemeral/schema"
1416
"github.com/hashicorp/terraform-plugin-framework/internal/fwschema"
1517
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testschema"
1618
"github.com/hashicorp/terraform-plugin-framework/internal/testing/testtypes"
1719
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1820
"github.com/hashicorp/terraform-plugin-framework/types"
19-
"github.com/hashicorp/terraform-plugin-go/tftypes"
2021
)
2122

2223
func TestInt64AttributeApplyTerraform5AttributePathStep(t *testing.T) {
@@ -423,3 +424,31 @@ func TestInt64AttributeIsSensitive(t *testing.T) {
423424
})
424425
}
425426
}
427+
428+
func TestInt64AttributeIsWriteOnly(t *testing.T) {
429+
t.Parallel()
430+
431+
testCases := map[string]struct {
432+
attribute schema.Int64Attribute
433+
expected bool
434+
}{
435+
"not-writeOnly": {
436+
attribute: schema.Int64Attribute{},
437+
expected: false,
438+
},
439+
}
440+
441+
for name, testCase := range testCases {
442+
name, testCase := name, testCase
443+
444+
t.Run(name, func(t *testing.T) {
445+
t.Parallel()
446+
447+
got := testCase.attribute.IsWriteOnly()
448+
449+
if diff := cmp.Diff(got, testCase.expected); diff != "" {
450+
t.Errorf("unexpected difference: %s", diff)
451+
}
452+
})
453+
}
454+
}

ephemeral/schema/object_attribute_test.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ import (
1010
"testing"
1111

1212
"github.com/google/go-cmp/cmp"
13+
"github.com/hashicorp/terraform-plugin-go/tftypes"
14+
1315
"github.com/hashicorp/terraform-plugin-framework/attr"
1416
"github.com/hashicorp/terraform-plugin-framework/diag"
1517
"github.com/hashicorp/terraform-plugin-framework/ephemeral/schema"
@@ -19,7 +21,6 @@ import (
1921
"github.com/hashicorp/terraform-plugin-framework/path"
2022
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
2123
"github.com/hashicorp/terraform-plugin-framework/types"
22-
"github.com/hashicorp/terraform-plugin-go/tftypes"
2324
)
2425

2526
func TestObjectAttributeApplyTerraform5AttributePathStep(t *testing.T) {
@@ -438,6 +439,34 @@ func TestObjectAttributeObjectValidators(t *testing.T) {
438439
}
439440
}
440441

442+
func TestObjectAttributeIsWriteOnly(t *testing.T) {
443+
t.Parallel()
444+
445+
testCases := map[string]struct {
446+
attribute schema.ObjectAttribute
447+
expected bool
448+
}{
449+
"not-writeOnly": {
450+
attribute: schema.ObjectAttribute{},
451+
expected: false,
452+
},
453+
}
454+
455+
for name, testCase := range testCases {
456+
name, testCase := name, testCase
457+
458+
t.Run(name, func(t *testing.T) {
459+
t.Parallel()
460+
461+
got := testCase.attribute.IsWriteOnly()
462+
463+
if diff := cmp.Diff(got, testCase.expected); diff != "" {
464+
t.Errorf("unexpected difference: %s", diff)
465+
}
466+
})
467+
}
468+
}
469+
441470
func TestObjectAttributeValidateImplementation(t *testing.T) {
442471
t.Parallel()
443472

0 commit comments

Comments
 (0)