Skip to content

Commit 859e205

Browse files
author
Ivan De Marino
committed
Added "null-ness" and "unknown-ness" tests to all the types.*
1 parent adcbe03 commit 859e205

9 files changed

+66
-4
lines changed

types/bool_test.go

+6
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ func testBoolValueFromTerraform(t *testing.T, direct bool) {
7575
if !got.Equal(test.expectation) {
7676
t.Errorf("Expected %+v, got %+v", test.expectation, got)
7777
}
78+
if test.expectation.IsNull() != test.input.IsNull() {
79+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expectation.IsNull(), test.input.IsNull())
80+
}
81+
if test.expectation.IsUnknown() != !test.input.IsKnown() {
82+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expectation.IsUnknown(), !test.input.IsKnown())
83+
}
7884
})
7985
}
8086
}

types/float64_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9+
910
"github.com/hashicorp/terraform-plugin-framework/attr"
1011

1112
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -76,6 +77,12 @@ func testFloat64ValueFromTerraform(t *testing.T, direct bool) {
7677
if diff := cmp.Diff(got, test.expectation); diff != "" {
7778
t.Errorf("Unexpected response (+wanted, -got): %s", diff)
7879
}
80+
if test.expectation.IsNull() != test.input.IsNull() {
81+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expectation.IsNull(), test.input.IsNull())
82+
}
83+
if test.expectation.IsUnknown() != !test.input.IsKnown() {
84+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expectation.IsUnknown(), !test.input.IsKnown())
85+
}
7986
})
8087
}
8188
}

types/int64_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9+
910
"github.com/hashicorp/terraform-plugin-framework/attr"
1011

1112
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -72,6 +73,12 @@ func testInt64ValueFromTerraform(t *testing.T, direct bool) {
7273
if !got.Equal(test.expectation) {
7374
t.Errorf("Expected %+v, got %+v", test.expectation, got)
7475
}
76+
if test.expectation.IsNull() != test.input.IsNull() {
77+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expectation.IsNull(), test.input.IsNull())
78+
}
79+
if test.expectation.IsUnknown() != !test.input.IsKnown() {
80+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expectation.IsUnknown(), !test.input.IsKnown())
81+
}
7582
})
7683
}
7784
}

types/list_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,9 @@ import (
55
"testing"
66

77
"github.com/google/go-cmp/cmp"
8-
"github.com/hashicorp/terraform-plugin-framework/attr"
98
"github.com/hashicorp/terraform-plugin-go/tftypes"
9+
10+
"github.com/hashicorp/terraform-plugin-framework/attr"
1011
)
1112

1213
func TestListTypeTerraformType(t *testing.T) {
@@ -203,6 +204,12 @@ func TestListTypeValueFromTerraform(t *testing.T) {
203204
if diff := cmp.Diff(got, test.expected); diff != "" {
204205
t.Errorf("Unexpected diff (-expected, +got): %s", diff)
205206
}
207+
if test.expected != nil && test.expected.IsNull() != test.input.IsNull() {
208+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expected.IsNull(), test.input.IsNull())
209+
}
210+
if test.expected != nil && test.expected.IsUnknown() != !test.input.IsKnown() {
211+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expected.IsUnknown(), !test.input.IsKnown())
212+
}
206213
})
207214
}
208215
}

types/map_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9-
"github.com/hashicorp/terraform-plugin-framework/attr"
109
"github.com/hashicorp/terraform-plugin-go/tftypes"
10+
11+
"github.com/hashicorp/terraform-plugin-framework/attr"
1112
)
1213

1314
func TestMapTypeTerraformType(t *testing.T) {
@@ -162,6 +163,12 @@ func TestMapTypeValueFromTerraform(t *testing.T) {
162163
if diff := cmp.Diff(test.expected, got); diff != "" {
163164
t.Errorf("unexpected result (-expected, +got): %s", diff)
164165
}
166+
if test.expected != nil && test.expected.IsNull() != test.input.IsNull() {
167+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expected.IsNull(), test.input.IsNull())
168+
}
169+
if test.expected != nil && test.expected.IsUnknown() != !test.input.IsKnown() {
170+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expected.IsUnknown(), !test.input.IsKnown())
171+
}
165172
})
166173
}
167174
}

types/number_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9+
910
"github.com/hashicorp/terraform-plugin-framework/attr"
1011

1112
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -76,6 +77,12 @@ func testNumberValueFromTerraform(t *testing.T, direct bool) {
7677
if !got.Equal(test.expectation) {
7778
t.Errorf("Expected %+v, got %+v", test.expectation, got)
7879
}
80+
if test.expectation.IsNull() != test.input.IsNull() {
81+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expectation.IsNull(), test.input.IsNull())
82+
}
83+
if test.expectation.IsUnknown() != !test.input.IsKnown() {
84+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expectation.IsUnknown(), !test.input.IsKnown())
85+
}
7986
})
8087
}
8188
}

types/object_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,9 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9-
"github.com/hashicorp/terraform-plugin-framework/attr"
109
"github.com/hashicorp/terraform-plugin-go/tftypes"
10+
11+
"github.com/hashicorp/terraform-plugin-framework/attr"
1112
)
1213

1314
func TestObjectTypeTerraformType_simple(t *testing.T) {
@@ -199,6 +200,12 @@ func TestObjectTypeValueFromTerraform(t *testing.T) {
199200
if diff := cmp.Diff(test.expected, got); diff != "" {
200201
t.Errorf("unexpected result (-expected, +got): %s", diff)
201202
}
203+
if test.expected != nil && test.expected.IsNull() != test.input.IsNull() {
204+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expected.IsNull(), test.input.IsNull())
205+
}
206+
if test.expected != nil && test.expected.IsUnknown() != !test.input.IsKnown() {
207+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expected.IsUnknown(), !test.input.IsKnown())
208+
}
202209
})
203210
}
204211
}

types/set_test.go

+8-1
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9+
"github.com/hashicorp/terraform-plugin-go/tftypes"
10+
911
"github.com/hashicorp/terraform-plugin-framework/attr"
1012
"github.com/hashicorp/terraform-plugin-framework/diag"
11-
"github.com/hashicorp/terraform-plugin-go/tftypes"
1213
)
1314

1415
func TestSetTypeTerraformType(t *testing.T) {
@@ -229,6 +230,12 @@ func TestSetTypeValueFromTerraform(t *testing.T) {
229230
if diff := cmp.Diff(got, test.expected); diff != "" {
230231
t.Errorf("Unexpected diff (-expected, +got): %s", diff)
231232
}
233+
if test.expected != nil && test.expected.IsNull() != test.input.IsNull() {
234+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expected.IsNull(), test.input.IsNull())
235+
}
236+
if test.expected != nil && test.expected.IsUnknown() != !test.input.IsKnown() {
237+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expected.IsUnknown(), !test.input.IsKnown())
238+
}
232239
})
233240
}
234241
}

types/string_test.go

+7
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import (
66
"testing"
77

88
"github.com/google/go-cmp/cmp"
9+
910
"github.com/hashicorp/terraform-plugin-framework/attr"
1011

1112
"github.com/hashicorp/terraform-plugin-go/tftypes"
@@ -72,6 +73,12 @@ func testStringValueFromTerraform(t *testing.T, direct bool) {
7273
if !got.Equal(test.expectation) {
7374
t.Errorf("Expected %+v, got %+v", test.expectation, got)
7475
}
76+
if test.expectation.IsNull() != test.input.IsNull() {
77+
t.Errorf("Expected null-ness match: expected %t, got %t", test.expectation.IsNull(), test.input.IsNull())
78+
}
79+
if test.expectation.IsUnknown() != !test.input.IsKnown() {
80+
t.Errorf("Expected unknown-ness match: expected %t, got %t", test.expectation.IsUnknown(), !test.input.IsKnown())
81+
}
7582
})
7683
}
7784
}

0 commit comments

Comments
 (0)