diff --git a/.changelog/77.txt b/.changelog/77.txt new file mode 100644 index 00000000..9ff9864f --- /dev/null +++ b/.changelog/77.txt @@ -0,0 +1,3 @@ +```release-note:note +all: This Go module has been updated to make it compatible with the breaking changes in terraform-plugin-framework version 0.16.0 +``` diff --git a/float64validator/at_least_test.go b/float64validator/at_least_test.go index ab8c8e50..4c0e85af 100644 --- a/float64validator/at_least_test.go +++ b/float64validator/at_least_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" ) func TestAtLeastValidator(t *testing.T) { @@ -21,31 +22,31 @@ func TestAtLeastValidator(t *testing.T) { } tests := map[string]testCase{ "not a Float64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Float64": { - val: types.Float64{Unknown: true}, + val: types.Float64Unknown(), min: 0.90, }, "null Float64": { - val: types.Float64{Null: true}, + val: types.Float64Null(), min: 0.90, }, "valid integer as Float64": { - val: types.Float64{Value: 2}, + val: types.Float64Value(2), min: 0.90, }, "valid float as Float64": { - val: types.Float64{Value: 2.2}, + val: types.Float64Value(2.2), min: 0.90, }, "valid float as Float64 min": { - val: types.Float64{Value: 0.9}, + val: types.Float64Value(0.9), min: 0.90, }, "too small float as Float64": { - val: types.Float64{Value: -1.1111}, + val: types.Float64Value(-1.1111), min: 0.90, expectError: true, }, diff --git a/float64validator/at_most_test.go b/float64validator/at_most_test.go index 2443c3b8..80f4ea73 100644 --- a/float64validator/at_most_test.go +++ b/float64validator/at_most_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" ) func TestAtMostValidator(t *testing.T) { @@ -21,31 +22,31 @@ func TestAtMostValidator(t *testing.T) { } tests := map[string]testCase{ "not a Float64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Float64": { - val: types.Float64{Unknown: true}, + val: types.Float64Unknown(), max: 2.00, }, "null Float64": { - val: types.Float64{Null: true}, + val: types.Float64Null(), max: 2.00, }, "valid integer as Float64": { - val: types.Float64{Value: 1}, + val: types.Float64Value(1), max: 2.00, }, "valid float as Float64": { - val: types.Float64{Value: 1.1}, + val: types.Float64Value(1.1), max: 2.00, }, "valid float as Float64 max": { - val: types.Float64{Value: 2.0}, + val: types.Float64Value(2.0), max: 2.00, }, "too large float as Float64": { - val: types.Float64{Value: 3.0}, + val: types.Float64Value(3.0), max: 2.00, expectError: true, }, diff --git a/float64validator/between_test.go b/float64validator/between_test.go index 74c2e608..82c4dee4 100644 --- a/float64validator/between_test.go +++ b/float64validator/between_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" ) func TestBetweenValidator(t *testing.T) { @@ -22,47 +23,47 @@ func TestBetweenValidator(t *testing.T) { } tests := map[string]testCase{ "not a Float64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Float64": { - val: types.Float64{Unknown: true}, + val: types.Float64Unknown(), min: 0.90, max: 3.10, }, "null Float64": { - val: types.Float64{Null: true}, + val: types.Float64Null(), min: 0.90, max: 3.10, }, "valid integer as Float64": { - val: types.Float64{Value: 2}, + val: types.Float64Value(2), min: 0.90, max: 3.10, }, "valid float as Float64": { - val: types.Float64{Value: 2.2}, + val: types.Float64Value(2.2), min: 0.90, max: 3.10, }, "valid float as Float64 min": { - val: types.Float64{Value: 0.9}, + val: types.Float64Value(0.9), min: 0.90, max: 3.10, }, "valid float as Float64 max": { - val: types.Float64{Value: 3.1}, + val: types.Float64Value(3.1), min: 0.90, max: 3.10, }, "too small float as Float64": { - val: types.Float64{Value: -1.1111}, + val: types.Float64Value(-1.1111), min: 0.90, max: 3.10, expectError: true, }, "too large float as Float64": { - val: types.Float64{Value: 4.2}, + val: types.Float64Value(4.2), min: 0.90, max: 3.10, expectError: true, diff --git a/float64validator/none_of.go b/float64validator/none_of.go index 85aeced7..ffb6999d 100644 --- a/float64validator/none_of.go +++ b/float64validator/none_of.go @@ -1,10 +1,11 @@ package float64validator import ( - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // NoneOf checks that the float64 held in the attribute @@ -12,7 +13,7 @@ import ( func NoneOf(unacceptableFloats ...float64) tfsdk.AttributeValidator { unacceptableFloatValues := make([]attr.Value, 0, len(unacceptableFloats)) for _, f := range unacceptableFloats { - unacceptableFloatValues = append(unacceptableFloatValues, types.Float64{Value: f}) + unacceptableFloatValues = append(unacceptableFloatValues, types.Float64Value(f)) } return primitivevalidator.NoneOf(unacceptableFloatValues...) diff --git a/float64validator/none_of_test.go b/float64validator/none_of_test.go index ceccda2c..62a121f7 100644 --- a/float64validator/none_of_test.go +++ b/float64validator/none_of_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" ) func TestNoneOfValidator(t *testing.T) { @@ -21,7 +22,7 @@ func TestNoneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.Float64{Value: 123.456}, + in: types.Float64Value(123.456), validator: float64validator.NoneOf( 123.456, 234.567, @@ -31,7 +32,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "simple-mismatch": { - in: types.Float64{Value: 123.456}, + in: types.Float64Value(123.456), validator: float64validator.NoneOf( 234.567, 8910.11, @@ -40,7 +41,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-null": { - in: types.Float64{Null: true}, + in: types.Float64Null(), validator: float64validator.NoneOf( 234.567, 8910.11, @@ -49,7 +50,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.Float64{Unknown: true}, + in: types.Float64Unknown(), validator: float64validator.NoneOf( 234.567, 8910.11, diff --git a/float64validator/one_of.go b/float64validator/one_of.go index cd5fba49..e4340dbd 100644 --- a/float64validator/one_of.go +++ b/float64validator/one_of.go @@ -1,10 +1,11 @@ package float64validator import ( - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // OneOf checks that the float64 held in the attribute @@ -12,7 +13,7 @@ import ( func OneOf(acceptableFloats ...float64) tfsdk.AttributeValidator { acceptableFloatValues := make([]attr.Value, 0, len(acceptableFloats)) for _, f := range acceptableFloats { - acceptableFloatValues = append(acceptableFloatValues, types.Float64{Value: f}) + acceptableFloatValues = append(acceptableFloatValues, types.Float64Value(f)) } return primitivevalidator.OneOf(acceptableFloatValues...) diff --git a/float64validator/one_of_test.go b/float64validator/one_of_test.go index dc1b55a9..0e03f8e3 100644 --- a/float64validator/one_of_test.go +++ b/float64validator/one_of_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/float64validator" ) func TestOneOfValidator(t *testing.T) { @@ -21,7 +22,7 @@ func TestOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.Float64{Value: 123.456}, + in: types.Float64Value(123.456), validator: float64validator.OneOf( 123.456, 234.567, @@ -31,7 +32,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "simple-mismatch": { - in: types.Float64{Value: 123.456}, + in: types.Float64Value(123.456), validator: float64validator.OneOf( 234.567, 8910.11, @@ -40,7 +41,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.Float64{Null: true}, + in: types.Float64Null(), validator: float64validator.OneOf( 234.567, 8910.11, @@ -49,7 +50,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.Float64{Unknown: true}, + in: types.Float64Unknown(), validator: float64validator.OneOf( 234.567, 8910.11, diff --git a/float64validator/type_validation_test.go b/float64validator/type_validation_test.go index 614a3585..a589505d 100644 --- a/float64validator/type_validation_test.go +++ b/float64validator/type_validation_test.go @@ -20,7 +20,7 @@ func TestValidateFloat(t *testing.T) { }{ "invalid-type": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Bool{Value: true}, + AttributeConfig: types.BoolValue(true), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -29,7 +29,7 @@ func TestValidateFloat(t *testing.T) { }, "float64-null": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Float64{Null: true}, + AttributeConfig: types.Float64Null(), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -38,7 +38,7 @@ func TestValidateFloat(t *testing.T) { }, "float64-value": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Float64{Value: 1.2}, + AttributeConfig: types.Float64Value(1.2), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -47,7 +47,7 @@ func TestValidateFloat(t *testing.T) { }, "float64-unknown": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Float64{Unknown: true}, + AttributeConfig: types.Float64Unknown(), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, diff --git a/go.mod b/go.mod index 1adf5108..f5b3b287 100644 --- a/go.mod +++ b/go.mod @@ -4,7 +4,7 @@ go 1.18 require ( github.com/google/go-cmp v0.5.9 - github.com/hashicorp/terraform-plugin-framework v0.15.0 + github.com/hashicorp/terraform-plugin-framework v0.16.0 github.com/hashicorp/terraform-plugin-go v0.14.1 ) diff --git a/go.sum b/go.sum index 49cb0703..2fc61595 100644 --- a/go.sum +++ b/go.sum @@ -13,8 +13,8 @@ github.com/google/go-cmp v0.5.9 h1:O2Tfq5qg4qc4AmwVlvv0oLiVAGB7enBSJ2x2DqQFi38= github.com/google/go-cmp v0.5.9/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= github.com/hashicorp/go-hclog v1.2.1 h1:YQsLlGDJgwhXFpucSPyVbCBviQtjlHv3jLTlp8YmtEw= github.com/hashicorp/go-hclog v1.2.1/go.mod h1:W4Qnvbt70Wk/zYJryRzDRU/4r0kIg0PVHBcfoyhpF5M= -github.com/hashicorp/terraform-plugin-framework v0.15.0 h1:6f4UY2yfp5UsSX9JhUA6RSptjd+ojStBGWA4jrPhB6Q= -github.com/hashicorp/terraform-plugin-framework v0.15.0/go.mod h1:wcZdk4+Uef6Ng+BiBJjGAcIPlIs5bhlEV/TA1k6Xkq8= +github.com/hashicorp/terraform-plugin-framework v0.16.0 h1:kEHh0d6dp5Ig/ey6PYXkWDZPMLIW8Me41T/Oa7bpO4s= +github.com/hashicorp/terraform-plugin-framework v0.16.0/go.mod h1:Vk5MuIJoE1qksHZawAZr6psx6YXsQBFIKDrWbROrwus= github.com/hashicorp/terraform-plugin-go v0.14.1 h1:cwZzPYla82XwAqpLhSzdVsOMU+6H29tczAwrB0z9Zek= github.com/hashicorp/terraform-plugin-go v0.14.1/go.mod h1:Bc/K6K26BQ2FHqIELPbpKtt2CzzbQou+0UQF3/0NsCQ= github.com/hashicorp/terraform-plugin-log v0.7.0 h1:SDxJUyT8TwN4l5b5/VkiTIaQgY6R+Y2BQ0sRZftGKQs= diff --git a/int64validator/at_least_sum_of_test.go b/int64validator/at_least_sum_of_test.go index fdfc0c89..9a2765b1 100644 --- a/int64validator/at_least_sum_of_test.go +++ b/int64validator/at_least_sum_of_test.go @@ -22,17 +22,17 @@ func TestAtLeastSumOfValidator(t *testing.T) { } tests := map[string]testCase{ "not an Int64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Int64": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), }, "null Int64": { - val: types.Int64{Null: true}, + val: types.Int64Null(), }, "valid integer as Int64 less than sum of attributes": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -44,7 +44,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 equal to sum of attributes": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -55,7 +55,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 greater than sum of attributes": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -66,7 +66,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 greater than sum of attributes, when one summed attribute is null": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -77,7 +77,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes are null": { - val: types.Int64{Null: true}, + val: types.Int64Null(), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -88,7 +88,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 returns error when all attributes to sum are null": { - val: types.Int64{Value: -1}, + val: types.Int64Value(-1), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -100,7 +100,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 greater than sum of attributes, when one summed attribute is unknown": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -111,7 +111,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes are unknown": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -122,7 +122,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes to sum are unknown": { - val: types.Int64{Value: -1}, + val: types.Int64Value(-1), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -133,7 +133,7 @@ func TestAtLeastSumOfValidator(t *testing.T) { }, }, "error when attribute to sum is not Number": { - val: types.Int64{Value: 9}, + val: types.Int64Value(9), attributesToSumExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), diff --git a/int64validator/at_least_test.go b/int64validator/at_least_test.go index b5294bdb..3f8e2a26 100644 --- a/int64validator/at_least_test.go +++ b/int64validator/at_least_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" ) func TestAtLeastValidator(t *testing.T) { @@ -21,27 +22,27 @@ func TestAtLeastValidator(t *testing.T) { } tests := map[string]testCase{ "not an Int64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Int64": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), min: 1, }, "null Int64": { - val: types.Int64{Null: true}, + val: types.Int64Null(), min: 1, }, "valid integer as Int64": { - val: types.Int64{Value: 2}, + val: types.Int64Value(2), min: 1, }, "valid integer as Int64 min": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), min: 1, }, "too small integer as Int64": { - val: types.Int64{Value: -1}, + val: types.Int64Value(-1), min: 1, expectError: true, }, diff --git a/int64validator/at_most_sum_of_test.go b/int64validator/at_most_sum_of_test.go index 7b65287d..ac74a661 100644 --- a/int64validator/at_most_sum_of_test.go +++ b/int64validator/at_most_sum_of_test.go @@ -22,17 +22,17 @@ func TestAtMostSumOfValidator(t *testing.T) { } tests := map[string]testCase{ "not an Int64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Int64": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), }, "null Int64": { - val: types.Int64{Null: true}, + val: types.Int64Null(), }, "valid integer as Int64 more than sum of attributes": { - val: types.Int64{Value: 11}, + val: types.Int64Value(11), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -44,7 +44,7 @@ func TestAtMostSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 equal to sum of attributes": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -55,7 +55,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 less than sum of attributes": { - val: types.Int64{Value: 7}, + val: types.Int64Value(7), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -66,7 +66,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 less than sum of attributes, when one summed attribute is null": { - val: types.Int64{Value: 8}, + val: types.Int64Value(8), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -77,7 +77,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes are null": { - val: types.Int64{Null: true}, + val: types.Int64Null(), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -88,7 +88,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 returns error when all attributes to sum are null": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -100,7 +100,7 @@ func TestAtMostSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 less than sum of attributes, when one summed attribute is unknown": { - val: types.Int64{Value: 8}, + val: types.Int64Value(8), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -111,7 +111,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes are unknown": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -122,7 +122,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes to sum are unknown": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -133,7 +133,7 @@ func TestAtMostSumOfValidator(t *testing.T) { }, }, "error when attribute to sum is not Number": { - val: types.Int64{Value: 9}, + val: types.Int64Value(9), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), diff --git a/int64validator/at_most_test.go b/int64validator/at_most_test.go index 72a2801c..debfac61 100644 --- a/int64validator/at_most_test.go +++ b/int64validator/at_most_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" ) func TestAtMostValidator(t *testing.T) { @@ -21,27 +22,27 @@ func TestAtMostValidator(t *testing.T) { } tests := map[string]testCase{ "not an Int64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Int64": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), max: 2, }, "null Int64": { - val: types.Int64{Null: true}, + val: types.Int64Null(), max: 2, }, "valid integer as Int64": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), max: 2, }, "valid integer as Int64 min": { - val: types.Int64{Value: 2}, + val: types.Int64Value(2), max: 2, }, "too large integer as Int64": { - val: types.Int64{Value: 4}, + val: types.Int64Value(4), max: 2, expectError: true, }, diff --git a/int64validator/between_test.go b/int64validator/between_test.go index 1d454b85..9a9996f8 100644 --- a/int64validator/between_test.go +++ b/int64validator/between_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" ) func TestBetweenValidator(t *testing.T) { @@ -22,42 +23,42 @@ func TestBetweenValidator(t *testing.T) { } tests := map[string]testCase{ "not an Int64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Int64": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), min: 1, max: 3, }, "null Int64": { - val: types.Int64{Null: true}, + val: types.Int64Null(), min: 1, max: 3, }, "valid integer as Int64": { - val: types.Int64{Value: 2}, + val: types.Int64Value(2), min: 1, max: 3, }, "valid integer as Int64 min": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), min: 1, max: 3, }, "valid integer as Int64 max": { - val: types.Int64{Value: 3}, + val: types.Int64Value(3), min: 1, max: 3, }, "too small integer as Int64": { - val: types.Int64{Value: -1}, + val: types.Int64Value(-1), min: 1, max: 3, expectError: true, }, "too large integer as Int64": { - val: types.Int64{Value: 42}, + val: types.Int64Value(42), min: 1, max: 3, expectError: true, diff --git a/int64validator/equal_to_sum_of_test.go b/int64validator/equal_to_sum_of_test.go index 6a99cdf0..dc981d03 100644 --- a/int64validator/equal_to_sum_of_test.go +++ b/int64validator/equal_to_sum_of_test.go @@ -22,17 +22,17 @@ func TestEqualToSumOfValidator(t *testing.T) { } tests := map[string]testCase{ "not an Int64": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown Int64": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), }, "null Int64": { - val: types.Int64{Null: true}, + val: types.Int64Null(), }, "valid integer as Int64 more than sum of attributes": { - val: types.Int64{Value: 11}, + val: types.Int64Value(11), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -44,7 +44,7 @@ func TestEqualToSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 less than sum of attributes": { - val: types.Int64{Value: 9}, + val: types.Int64Value(9), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -56,7 +56,7 @@ func TestEqualToSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 equal to sum of attributes": { - val: types.Int64{Value: 10}, + val: types.Int64Value(10), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -67,7 +67,7 @@ func TestEqualToSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 equal to sum of attributes, when one summed attribute is null": { - val: types.Int64{Value: 8}, + val: types.Int64Value(8), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -78,7 +78,7 @@ func TestEqualToSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes are null": { - val: types.Int64{Null: true}, + val: types.Int64Null(), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -89,7 +89,7 @@ func TestEqualToSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 returns error when all attributes to sum are null": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -101,7 +101,7 @@ func TestEqualToSumOfValidator(t *testing.T) { expectError: true, }, "valid integer as Int64 equal to sum of attributes, when one summed attribute is unknown": { - val: types.Int64{Value: 8}, + val: types.Int64Value(8), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -112,7 +112,7 @@ func TestEqualToSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes are unknown": { - val: types.Int64{Unknown: true}, + val: types.Int64Unknown(), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -123,7 +123,7 @@ func TestEqualToSumOfValidator(t *testing.T) { }, }, "valid integer as Int64 does not return error when all attributes to sum are unknown": { - val: types.Int64{Value: 1}, + val: types.Int64Value(1), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), @@ -134,7 +134,7 @@ func TestEqualToSumOfValidator(t *testing.T) { }, }, "error when attribute to sum is not Number": { - val: types.Int64{Value: 9}, + val: types.Int64Value(9), attributesToSumPathExpressions: path.Expressions{ path.MatchRoot("one"), path.MatchRoot("two"), diff --git a/int64validator/none_of.go b/int64validator/none_of.go index fedff940..b2e90fc3 100644 --- a/int64validator/none_of.go +++ b/int64validator/none_of.go @@ -1,10 +1,11 @@ package int64validator import ( - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // NoneOf checks that the int64 held in the attribute @@ -12,7 +13,7 @@ import ( func NoneOf(unacceptableInts ...int64) tfsdk.AttributeValidator { unacceptableIntValues := make([]attr.Value, 0, len(unacceptableInts)) for _, i := range unacceptableInts { - unacceptableIntValues = append(unacceptableIntValues, types.Int64{Value: i}) + unacceptableIntValues = append(unacceptableIntValues, types.Int64Value(i)) } return primitivevalidator.NoneOf(unacceptableIntValues...) diff --git a/int64validator/none_of_test.go b/int64validator/none_of_test.go index fea7ddcb..c91fee00 100644 --- a/int64validator/none_of_test.go +++ b/int64validator/none_of_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" ) func TestNoneOfValidator(t *testing.T) { @@ -21,7 +22,7 @@ func TestNoneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.Int64{Value: 123}, + in: types.Int64Value(123), validator: int64validator.NoneOf( 123, 234, @@ -31,7 +32,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "simple-mismatch": { - in: types.Int64{Value: 123}, + in: types.Int64Value(123), validator: int64validator.NoneOf( 234, 8910, @@ -40,7 +41,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-null": { - in: types.Int64{Null: true}, + in: types.Int64Null(), validator: int64validator.NoneOf( 234, 8910, @@ -49,7 +50,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.Int64{Unknown: true}, + in: types.Int64Unknown(), validator: int64validator.NoneOf( 234, 8910, diff --git a/int64validator/one_of.go b/int64validator/one_of.go index 13fa3df5..93d90cdf 100644 --- a/int64validator/one_of.go +++ b/int64validator/one_of.go @@ -1,10 +1,11 @@ package int64validator import ( - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // OneOf checks that the int64 held in the attribute @@ -12,7 +13,7 @@ import ( func OneOf(acceptableInts ...int64) tfsdk.AttributeValidator { acceptableIntValues := make([]attr.Value, 0, len(acceptableInts)) for _, i := range acceptableInts { - acceptableIntValues = append(acceptableIntValues, types.Int64{Value: i}) + acceptableIntValues = append(acceptableIntValues, types.Int64Value(i)) } return primitivevalidator.OneOf(acceptableIntValues...) diff --git a/int64validator/one_of_test.go b/int64validator/one_of_test.go index de2607cf..693d52a9 100644 --- a/int64validator/one_of_test.go +++ b/int64validator/one_of_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/int64validator" ) func TestOneOfValidator(t *testing.T) { @@ -21,7 +22,7 @@ func TestOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.Int64{Value: 123}, + in: types.Int64Value(123), validator: int64validator.OneOf( 123, 234, @@ -31,7 +32,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "simple-mismatch": { - in: types.Int64{Value: 123}, + in: types.Int64Value(123), validator: int64validator.OneOf( 234, 8910, @@ -40,7 +41,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.Int64{Null: true}, + in: types.Int64Null(), validator: int64validator.OneOf( 234, 8910, @@ -49,7 +50,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.Int64{Unknown: true}, + in: types.Int64Unknown(), validator: int64validator.OneOf( 234, 8910, diff --git a/int64validator/type_validation_test.go b/int64validator/type_validation_test.go index c651b0f7..62a89fc5 100644 --- a/int64validator/type_validation_test.go +++ b/int64validator/type_validation_test.go @@ -22,7 +22,7 @@ func TestValidateInt(t *testing.T) { }{ "invalid-type": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Bool{Value: true}, + AttributeConfig: types.BoolValue(true), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -33,7 +33,7 @@ func TestValidateInt(t *testing.T) { }, "int64-null": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64{Null: true}, + AttributeConfig: types.Int64Null(), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -44,7 +44,7 @@ func TestValidateInt(t *testing.T) { }, "int64-value": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64{Value: 123}, + AttributeConfig: types.Int64Value(123), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -53,7 +53,7 @@ func TestValidateInt(t *testing.T) { }, "int64-unknown": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64{Unknown: true}, + AttributeConfig: types.Int64Unknown(), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, diff --git a/internal/primitivevalidator/none_of_test.go b/internal/primitivevalidator/none_of_test.go index 91cebbbd..5aeb8138 100644 --- a/internal/primitivevalidator/none_of_test.go +++ b/internal/primitivevalidator/none_of_test.go @@ -6,10 +6,11 @@ import ( "math/big" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) func TestNoneOfValidator(t *testing.T) { @@ -34,134 +35,134 @@ func TestNoneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: primitivevalidator.NoneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 1, }, "simple-mismatch": { - in: types.String{Value: "foz"}, + in: types.StringValue("foz"), validator: primitivevalidator.NoneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 0, }, "mixed": { - in: types.Float64{Value: 1.234}, + in: types.Float64Value(1.234), validator: primitivevalidator.NoneOf( - types.String{Value: "foo"}, - types.Int64{Value: 567}, - types.Float64{Value: 1.234}, + types.StringValue("foo"), + types.Int64Value(567), + types.Float64Value(1.234), ), expErrors: 1, }, "list-not-allowed": { - in: types.List{ - ElemType: types.Int64Type, - Elems: []attr.Value{ - types.Int64{Value: 10}, - types.Int64{Value: 20}, - types.Int64{Value: 30}, + in: types.ListValueMust( + types.Int64Type, + []attr.Value{ + types.Int64Value(10), + types.Int64Value(20), + types.Int64Value(30), }, - }, + ), validator: primitivevalidator.NoneOf( - types.Int64{Value: 10}, - types.Int64{Value: 20}, - types.Int64{Value: 30}, - types.Int64{Value: 40}, - types.Int64{Value: 50}, + types.Int64Value(10), + types.Int64Value(20), + types.Int64Value(30), + types.Int64Value(40), + types.Int64Value(50), ), expErrors: 1, }, "set-not-allowed": { - in: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + in: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), }, - }, + ), validator: primitivevalidator.NoneOf( - types.String{Value: "bob"}, - types.String{Value: "alice"}, - types.String{Value: "john"}, - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("bob"), + types.StringValue("alice"), + types.StringValue("john"), + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 1, }, "map-not-allowed": { - in: types.Map{ - ElemType: types.NumberType, - Elems: map[string]attr.Value{ - "one.one": types.Number{Value: big.NewFloat(1.1)}, - "ten.twenty": types.Number{Value: big.NewFloat(10.20)}, - "five.four": types.Number{Value: big.NewFloat(5.4)}, + in: types.MapValueMust( + types.NumberType, + map[string]attr.Value{ + "one.one": types.NumberValue(big.NewFloat(1.1)), + "ten.twenty": types.NumberValue(big.NewFloat(10.20)), + "five.four": types.NumberValue(big.NewFloat(5.4)), }, - }, + ), validator: primitivevalidator.NoneOf( - types.Number{Value: big.NewFloat(1.1)}, - types.Number{Value: big.NewFloat(math.MaxFloat64)}, - types.Number{Value: big.NewFloat(math.SmallestNonzeroFloat64)}, - types.Number{Value: big.NewFloat(10.20)}, - types.Number{Value: big.NewFloat(5.4)}, + types.NumberValue(big.NewFloat(1.1)), + types.NumberValue(big.NewFloat(math.MaxFloat64)), + types.NumberValue(big.NewFloat(math.SmallestNonzeroFloat64)), + types.NumberValue(big.NewFloat(10.20)), + types.NumberValue(big.NewFloat(5.4)), ), expErrors: 1, }, "object-not-allowed": { - in: types.Object{ - AttrTypes: objAttrTypes, - Attrs: map[string]attr.Value{ - "Person": types.Object{ - AttrTypes: objPersonAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.Int64{Value: 40}, + in: types.ObjectValueMust( + objAttrTypes, + map[string]attr.Value{ + "Person": types.ObjectValueMust( + objPersonAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.Int64Value(40), }, - }, - "Address": types.String{Value: "1200 Park Avenue Emeryville"}, + ), + "Address": types.StringValue("1200 Park Avenue Emeryville"), }, - }, + ), validator: primitivevalidator.NoneOf( - types.Object{ - AttrTypes: map[string]attr.Type{}, - Attrs: map[string]attr.Value{}, - }, - types.Object{ - AttrTypes: objPersonAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.Int64{Value: 40}, + types.ObjectValueMust( + map[string]attr.Type{}, + map[string]attr.Value{}, + ), + types.ObjectValueMust( + objPersonAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.Int64Value(40), }, - }, - types.String{Value: "1200 Park Avenue Emeryville"}, - types.Int64{Value: 123}, - types.String{Value: "Bob Parr"}, + ), + types.StringValue("1200 Park Avenue Emeryville"), + types.Int64Value(123), + types.StringValue("Bob Parr"), ), expErrors: 1, }, "skip-validation-on-null": { - in: types.String{Null: true}, + in: types.StringNull(), validator: primitivevalidator.NoneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 0, }, "skip-validation-on-unknown": { - in: types.String{Unknown: true}, + in: types.StringUnknown(), validator: primitivevalidator.NoneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 0, }, diff --git a/internal/primitivevalidator/one_of_test.go b/internal/primitivevalidator/one_of_test.go index f55a1571..162ca60d 100644 --- a/internal/primitivevalidator/one_of_test.go +++ b/internal/primitivevalidator/one_of_test.go @@ -6,10 +6,11 @@ import ( "math/big" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) func TestOneOfValidator(t *testing.T) { @@ -34,134 +35,134 @@ func TestOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: primitivevalidator.OneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 0, }, "simple-mismatch": { - in: types.String{Value: "foz"}, + in: types.StringValue("foz"), validator: primitivevalidator.OneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 1, }, "mixed": { - in: types.Float64{Value: 1.234}, + in: types.Float64Value(1.234), validator: primitivevalidator.OneOf( - types.String{Value: "foo"}, - types.Int64{Value: 567}, - types.Float64{Value: 1.234}, + types.StringValue("foo"), + types.Int64Value(567), + types.Float64Value(1.234), ), expErrors: 0, }, "list-not-allowed": { - in: types.List{ - ElemType: types.Int64Type, - Elems: []attr.Value{ - types.Int64{Value: 10}, - types.Int64{Value: 20}, - types.Int64{Value: 30}, + in: types.ListValueMust( + types.Int64Type, + []attr.Value{ + types.Int64Value(10), + types.Int64Value(20), + types.Int64Value(30), }, - }, + ), validator: primitivevalidator.OneOf( - types.Int64{Value: 10}, - types.Int64{Value: 20}, - types.Int64{Value: 30}, - types.Int64{Value: 40}, - types.Int64{Value: 50}, + types.Int64Value(10), + types.Int64Value(20), + types.Int64Value(30), + types.Int64Value(40), + types.Int64Value(50), ), expErrors: 1, }, "set-not-allowed": { - in: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + in: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), }, - }, + ), validator: primitivevalidator.OneOf( - types.String{Value: "bob"}, - types.String{Value: "alice"}, - types.String{Value: "john"}, - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("bob"), + types.StringValue("alice"), + types.StringValue("john"), + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 1, }, "map-not-allowed": { - in: types.Map{ - ElemType: types.NumberType, - Elems: map[string]attr.Value{ - "one.one": types.Number{Value: big.NewFloat(1.1)}, - "ten.twenty": types.Number{Value: big.NewFloat(10.20)}, - "five.four": types.Number{Value: big.NewFloat(5.4)}, + in: types.MapValueMust( + types.NumberType, + map[string]attr.Value{ + "one.one": types.NumberValue(big.NewFloat(1.1)), + "ten.twenty": types.NumberValue(big.NewFloat(10.20)), + "five.four": types.NumberValue(big.NewFloat(5.4)), }, - }, + ), validator: primitivevalidator.OneOf( - types.Number{Value: big.NewFloat(1.1)}, - types.Number{Value: big.NewFloat(math.MaxFloat64)}, - types.Number{Value: big.NewFloat(math.SmallestNonzeroFloat64)}, - types.Number{Value: big.NewFloat(10.20)}, - types.Number{Value: big.NewFloat(5.4)}, + types.NumberValue(big.NewFloat(1.1)), + types.NumberValue(big.NewFloat(math.MaxFloat64)), + types.NumberValue(big.NewFloat(math.SmallestNonzeroFloat64)), + types.NumberValue(big.NewFloat(10.20)), + types.NumberValue(big.NewFloat(5.4)), ), expErrors: 1, }, "object-not-allowed": { - in: types.Object{ - AttrTypes: objAttrTypes, - Attrs: map[string]attr.Value{ - "Person": types.Object{ - AttrTypes: objPersonAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.Int64{Value: 40}, + in: types.ObjectValueMust( + objAttrTypes, + map[string]attr.Value{ + "Person": types.ObjectValueMust( + objPersonAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.Int64Value(40), }, - }, - "Address": types.String{Value: "1200 Park Avenue Emeryville"}, + ), + "Address": types.StringValue("1200 Park Avenue Emeryville"), }, - }, + ), validator: primitivevalidator.OneOf( - types.Object{ - AttrTypes: map[string]attr.Type{}, - Attrs: map[string]attr.Value{}, - }, - types.Object{ - AttrTypes: objPersonAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.Int64{Value: 40}, + types.ObjectValueMust( + map[string]attr.Type{}, + map[string]attr.Value{}, + ), + types.ObjectValueMust( + objPersonAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.Int64Value(40), }, - }, - types.String{Value: "1200 Park Avenue Emeryville"}, - types.Int64{Value: 123}, - types.String{Value: "Bob Parr"}, + ), + types.StringValue("1200 Park Avenue Emeryville"), + types.Int64Value(123), + types.StringValue("Bob Parr"), ), expErrors: 1, }, "skip-validation-on-null": { - in: types.String{Null: true}, + in: types.StringNull(), validator: primitivevalidator.OneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 0, }, "skip-validation-on-unknown": { - in: types.String{Unknown: true}, + in: types.StringUnknown(), validator: primitivevalidator.OneOf( - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), ), expErrors: 0, }, diff --git a/listvalidator/size_at_least_test.go b/listvalidator/size_at_least_test.go index 024f4007..c874f66a 100644 --- a/listvalidator/size_at_least_test.go +++ b/listvalidator/size_at_least_test.go @@ -20,49 +20,47 @@ func TestSizeAtLeastValidator(t *testing.T) { } tests := map[string]testCase{ "not a List": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "List unknown": { - val: types.List{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.ListUnknown( + types.StringType, + ), expectError: false, }, "List null": { - val: types.List{ - Null: true, - ElemType: types.StringType, - }, + val: types.ListNull( + types.StringType, + ), expectError: false, }, "List size greater than min": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), min: 1, expectError: false, }, "List size equal to min": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), }, - }, + ), min: 1, expectError: false, }, "List size less than min": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{}, - }, + val: types.ListValueMust( + types.StringType, + []attr.Value{}, + ), min: 1, expectError: true, }, diff --git a/listvalidator/size_at_most_test.go b/listvalidator/size_at_most_test.go index af4d121a..70c4c898 100644 --- a/listvalidator/size_at_most_test.go +++ b/listvalidator/size_at_most_test.go @@ -20,52 +20,51 @@ func TestSizeAtMostValidator(t *testing.T) { } tests := map[string]testCase{ "not a List": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "List unknown": { - val: types.List{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.ListUnknown( + types.StringType, + ), expectError: false, }, "List null": { - val: types.List{ - Null: true, - ElemType: types.StringType, - }, + val: types.ListNull( + types.StringType, + ), expectError: false, }, "List size less than max": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), }, - }, + ), max: 2, expectError: false, }, "List size equal to max": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), max: 2, expectError: false, }, "List size greater than max": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, - types.String{Value: "third"}, - }}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), + types.StringValue("third"), + }, + ), max: 2, expectError: true, }, diff --git a/listvalidator/size_between_test.go b/listvalidator/size_between_test.go index 7276e66d..959724e6 100644 --- a/listvalidator/size_between_test.go +++ b/listvalidator/size_between_test.go @@ -21,90 +21,88 @@ func TestSizeBetweenValidator(t *testing.T) { } tests := map[string]testCase{ "not a List": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "List unknown": { - val: types.List{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.ListUnknown( + types.StringType, + ), expectError: false, }, "List null": { - val: types.List{ - Null: true, - ElemType: types.StringType, - }, + val: types.ListNull( + types.StringType, + ), expectError: false, }, "List size greater than min": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), min: 1, max: 3, expectError: false, }, "List size equal to min": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), }, - }, + ), min: 1, max: 3, expectError: false, }, "List size less than max": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), min: 1, max: 3, expectError: false, }, "List size equal to max": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, - types.String{Value: "third"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), + types.StringValue("third"), }, - }, + ), min: 1, max: 3, expectError: false, }, "List size less than min": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{}, - }, + val: types.ListValueMust( + types.StringType, + []attr.Value{}, + ), min: 1, max: 3, expectError: true, }, "List size greater than max": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, - types.String{Value: "third"}, - types.String{Value: "fourth"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), + types.StringValue("third"), + types.StringValue("fourth"), }, - }, + ), min: 1, max: 3, expectError: true, diff --git a/listvalidator/type_validation_test.go b/listvalidator/type_validation_test.go index c2538a8c..dd72311f 100644 --- a/listvalidator/type_validation_test.go +++ b/listvalidator/type_validation_test.go @@ -21,7 +21,7 @@ func TestValidateList(t *testing.T) { }{ "invalid-type": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Bool{Value: true}, + AttributeConfig: types.BoolValue(true), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -30,7 +30,7 @@ func TestValidateList(t *testing.T) { }, "list-null": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.List{Null: true}, + AttributeConfig: types.ListNull(types.StringType), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -39,7 +39,7 @@ func TestValidateList(t *testing.T) { }, "list-unknown": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.List{Unknown: true}, + AttributeConfig: types.ListUnknown(types.StringType), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -48,19 +48,19 @@ func TestValidateList(t *testing.T) { }, "list-value": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + AttributeConfig: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, expectedListElems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + types.StringValue("first"), + types.StringValue("second"), }, expectedOk: true, }, diff --git a/listvalidator/values_are_test.go b/listvalidator/values_are_test.go index 6b9b1a50..4f88db62 100644 --- a/listvalidator/values_are_test.go +++ b/listvalidator/values_are_test.go @@ -23,46 +23,45 @@ func TestValuesAreValidator(t *testing.T) { } tests := map[string]testCase{ "not List": { - val: types.Set{ - ElemType: types.StringType, - }, + val: types.SetValueMust( + types.StringType, + []attr.Value{}, + ), expectError: true, }, "List unknown": { - val: types.List{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.ListUnknown( + types.StringType, + ), expectError: false, }, "List null": { - val: types.List{ - Null: true, - ElemType: types.StringType, - }, + val: types.ListNull( + types.StringType, + ), expectError: false, }, "List elems invalid": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(6), }, expectError: true, }, "List elems invalid for second validator": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(6), @@ -70,26 +69,26 @@ func TestValuesAreValidator(t *testing.T) { expectError: true, }, "List elems wrong type for validator": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ int64validator.AtLeast(6), }, expectError: true, }, "List elems valid": { - val: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(5), }, diff --git a/mapvalidator/keys_are.go b/mapvalidator/keys_are.go index a6466690..10cb1dca 100644 --- a/mapvalidator/keys_are.go +++ b/mapvalidator/keys_are.go @@ -46,7 +46,7 @@ func (v keysAreValidator) Validate(ctx context.Context, req tfsdk.ValidateAttrib request := tfsdk.ValidateAttributeRequest{ AttributePath: attrPath, AttributePathExpression: attrPath.Expression(), - AttributeConfig: types.String{Value: k}, + AttributeConfig: types.StringValue(k), Config: req.Config, } diff --git a/mapvalidator/keys_are_test.go b/mapvalidator/keys_are_test.go index 0eecda10..c8b01f84 100644 --- a/mapvalidator/keys_are_test.go +++ b/mapvalidator/keys_are_test.go @@ -23,46 +23,45 @@ func TestKeysAreValidator(t *testing.T) { } tests := map[string]testCase{ "not Map": { - val: types.List{ - ElemType: types.StringType, - }, + val: types.ListValueMust( + types.StringType, + []attr.Value{}, + ), expectErrorsCount: 1, }, "Map unknown": { - val: types.Map{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.MapUnknown( + types.StringType, + ), expectErrorsCount: 0, }, "Map null": { - val: types.Map{ - Null: true, - ElemType: types.StringType, - }, + val: types.MapNull( + types.StringType, + ), expectErrorsCount: 0, }, "Map key invalid": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), keysAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(4), }, expectErrorsCount: 2, }, "Map key invalid for second validator": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), keysAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(6), @@ -70,25 +69,25 @@ func TestKeysAreValidator(t *testing.T) { expectErrorsCount: 2, }, "Map keys wrong type for validator": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), keysAreValidators: []tfsdk.AttributeValidator{ int64validator.AtLeast(6), }, expectErrorsCount: 1, }, "Map keys for invalid multiple validators": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), }, - }, + ), keysAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(5), stringvalidator.LengthAtLeast(6), @@ -96,13 +95,13 @@ func TestKeysAreValidator(t *testing.T) { expectErrorsCount: 2, }, "Map keys valid": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), keysAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(3), }, diff --git a/mapvalidator/size_at_least_test.go b/mapvalidator/size_at_least_test.go index 26cd0b52..3da44e97 100644 --- a/mapvalidator/size_at_least_test.go +++ b/mapvalidator/size_at_least_test.go @@ -20,49 +20,47 @@ func TestSizeAtLeastValidator(t *testing.T) { } tests := map[string]testCase{ "not a Map": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "Map unknown": { - val: types.Map{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.MapUnknown( + types.StringType, + ), expectError: false, }, "Map null": { - val: types.Map{ - Null: true, - ElemType: types.StringType, - }, + val: types.MapNull( + types.StringType, + ), expectError: false, }, "Map size greater than min": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), min: 1, expectError: false, }, "Map size equal to min": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), }, - }, + ), min: 1, expectError: false, }, "Map size less than min": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{}, - }, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{}, + ), min: 1, expectError: true, }, diff --git a/mapvalidator/size_at_most_test.go b/mapvalidator/size_at_most_test.go index fe2c327e..92e437a5 100644 --- a/mapvalidator/size_at_most_test.go +++ b/mapvalidator/size_at_most_test.go @@ -20,52 +20,51 @@ func TestSizeAtMostValidator(t *testing.T) { } tests := map[string]testCase{ "not a Map": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "Map unknown": { - val: types.Map{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.MapUnknown( + types.StringType, + ), expectError: false, }, "Map null": { - val: types.Map{ - Null: true, - ElemType: types.StringType, - }, + val: types.MapNull( + types.StringType, + ), expectError: false, }, "Map size less than max": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), }, - }, + ), max: 2, expectError: false, }, "Map size equal to max": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), max: 2, expectError: false, }, "Map size greater than max": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, - "three": types.String{Value: "third"}, - }}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), + "three": types.StringValue("third"), + }, + ), max: 2, expectError: true, }, diff --git a/mapvalidator/size_between_test.go b/mapvalidator/size_between_test.go index d701ac76..2db93fa6 100644 --- a/mapvalidator/size_between_test.go +++ b/mapvalidator/size_between_test.go @@ -21,90 +21,88 @@ func TestSizeBetweenValidator(t *testing.T) { } tests := map[string]testCase{ "not a Map": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "Map unknown": { - val: types.Map{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.MapUnknown( + types.StringType, + ), expectError: false, }, "Map null": { - val: types.Map{ - Null: true, - ElemType: types.StringType, - }, + val: types.MapNull( + types.StringType, + ), expectError: false, }, "Map size greater than min": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Map size equal to min": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Map size less than max": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Map size equal to max": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, - "three": types.String{Value: "third"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), + "three": types.StringValue("third"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Map size less than min": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{}, - }, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{}, + ), min: 1, max: 3, expectError: true, }, "Map size greater than max": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, - "three": types.String{Value: "third"}, - "four": types.String{Value: "fourth"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), + "three": types.StringValue("third"), + "four": types.StringValue("fourth"), }, - }, + ), min: 1, max: 3, expectError: true, diff --git a/mapvalidator/type_validation_test.go b/mapvalidator/type_validation_test.go index 0c4cf8ae..4076bc98 100644 --- a/mapvalidator/type_validation_test.go +++ b/mapvalidator/type_validation_test.go @@ -21,7 +21,7 @@ func TestValidateMap(t *testing.T) { }{ "invalid-type": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Bool{Value: true}, + AttributeConfig: types.BoolValue(true), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -30,7 +30,7 @@ func TestValidateMap(t *testing.T) { }, "map-null": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Map{Null: true}, + AttributeConfig: types.MapNull(types.StringType), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -39,7 +39,7 @@ func TestValidateMap(t *testing.T) { }, "map-unknown": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Map{Unknown: true}, + AttributeConfig: types.MapUnknown(types.StringType), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -48,19 +48,19 @@ func TestValidateMap(t *testing.T) { }, "map-value": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + AttributeConfig: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, expectedMap: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, expectedOk: true, }, diff --git a/mapvalidator/values_are_test.go b/mapvalidator/values_are_test.go index d4eda8a8..614087bb 100644 --- a/mapvalidator/values_are_test.go +++ b/mapvalidator/values_are_test.go @@ -23,40 +23,38 @@ func TestValuesAreValidator(t *testing.T) { } tests := map[string]testCase{ "Map unknown": { - val: types.Map{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.MapUnknown( + types.StringType, + ), expectError: false, }, "Map null": { - val: types.Map{ - Null: true, - ElemType: types.StringType, - }, + val: types.MapNull( + types.StringType, + ), expectError: false, }, "Map value invalid": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "number_one": types.String{Value: "first"}, - "number_two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "number_one": types.StringValue("first"), + "number_two": types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(6), }, expectError: true, }, "Maps value invalid for second validator": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "number_one": types.String{Value: "first"}, - "number_two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "number_one": types.StringValue("first"), + "number_two": types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(6), @@ -64,26 +62,26 @@ func TestValuesAreValidator(t *testing.T) { expectError: true, }, "Map values wrong type for validator": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "number_one": types.String{Value: "first"}, - "number_two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "number_one": types.StringValue("first"), + "number_two": types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ int64validator.AtLeast(6), }, expectError: true, }, "Map values valid": { - val: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one": types.String{Value: "first"}, - "two": types.String{Value: "second"}, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one": types.StringValue("first"), + "two": types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(5), }, diff --git a/metavalidator/all_test.go b/metavalidator/all_test.go index 6203572f..b50d9c5a 100644 --- a/metavalidator/all_test.go +++ b/metavalidator/all_test.go @@ -26,7 +26,7 @@ func TestAllValidator(t *testing.T) { } tests := map[string]testCase{ "Type mismatch": { - val: types.Int64{Value: 12}, + val: types.Int64Value(12), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(3), stringvalidator.LengthAtLeast(5), @@ -41,7 +41,7 @@ func TestAllValidator(t *testing.T) { }, }, "String invalid": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(3), stringvalidator.LengthAtLeast(5), @@ -56,7 +56,7 @@ func TestAllValidator(t *testing.T) { }, }, "String valid": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(3), diff --git a/metavalidator/any_test.go b/metavalidator/any_test.go index 809992a3..e249110e 100644 --- a/metavalidator/any_test.go +++ b/metavalidator/any_test.go @@ -26,7 +26,7 @@ func TestAnyValidator(t *testing.T) { } tests := map[string]testCase{ "Type mismatch": { - val: types.Int64{Value: 12}, + val: types.Int64Value(12), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(3), stringvalidator.LengthAtLeast(5), @@ -41,7 +41,7 @@ func TestAnyValidator(t *testing.T) { }, }, "String invalid": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(4), stringvalidator.LengthAtLeast(5), @@ -61,7 +61,7 @@ func TestAnyValidator(t *testing.T) { }, }, "String valid": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(5), stringvalidator.LengthAtLeast(3), @@ -70,7 +70,7 @@ func TestAnyValidator(t *testing.T) { expectedValidatorDiags: diag.Diagnostics{}, }, "String invalid in all nested validators": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), stringvalidator.LengthAtLeast(3)), metavalidator.All(stringvalidator.LengthAtLeast(5), stringvalidator.LengthAtLeast(3)), @@ -90,7 +90,7 @@ func TestAnyValidator(t *testing.T) { }, }, "String valid in one of the nested validators": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), stringvalidator.LengthAtLeast(3)), metavalidator.All(stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(3)), @@ -99,7 +99,7 @@ func TestAnyValidator(t *testing.T) { expectedValidatorDiags: diag.Diagnostics{}, }, "String valid in one of the nested validators with warning": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), stringvalidator.LengthAtLeast(3)), metavalidator.All(stringvalidator.LengthAtLeast(2), warningValidator{ @@ -112,7 +112,7 @@ func TestAnyValidator(t *testing.T) { diag.NewWarningDiagnostic("Warning", "Warning")}, }, "String valid in one of the nested validators with warning and warnings from failed validations": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), warningValidator{ summary: "Warning", diff --git a/metavalidator/any_with_all_warnings_test.go b/metavalidator/any_with_all_warnings_test.go index 2a1044f7..88683c8f 100644 --- a/metavalidator/any_with_all_warnings_test.go +++ b/metavalidator/any_with_all_warnings_test.go @@ -45,7 +45,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { } tests := map[string]testCase{ "Type mismatch": { - val: types.Int64{Value: 12}, + val: types.Int64Value(12), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(3), stringvalidator.LengthAtLeast(5), @@ -60,7 +60,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { }, }, "String invalid": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(4), stringvalidator.LengthAtLeast(5), @@ -80,7 +80,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { }, }, "String valid": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(5), stringvalidator.LengthAtLeast(3), @@ -89,7 +89,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { expectedValidatorDiags: diag.Diagnostics{}, }, "String invalid in all nested validators": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), stringvalidator.LengthAtLeast(3)), metavalidator.All(stringvalidator.LengthAtLeast(5), stringvalidator.LengthAtLeast(3)), @@ -109,7 +109,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { }, }, "String valid in one of the nested validators": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), stringvalidator.LengthAtLeast(3)), metavalidator.All(stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(3)), @@ -118,7 +118,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { expectedValidatorDiags: diag.Diagnostics{}, }, "String valid in one of the nested validators with warning": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), stringvalidator.LengthAtLeast(3)), metavalidator.All(stringvalidator.LengthAtLeast(2), warningValidator{ @@ -131,7 +131,7 @@ func TestAnyWithAllWarningsValidator(t *testing.T) { diag.NewWarningDiagnostic("Warning", "Warning")}, }, "String valid in one of the nested validators with warning and warnings from failed validations": { - val: types.String{Value: "one"}, + val: types.StringValue("one"), valueValidators: []tfsdk.AttributeValidator{ metavalidator.All(stringvalidator.LengthAtLeast(6), warningValidator{ summary: "Warning", diff --git a/numbervalidator/none_of.go b/numbervalidator/none_of.go index 0650a16a..367d48bc 100644 --- a/numbervalidator/none_of.go +++ b/numbervalidator/none_of.go @@ -3,10 +3,11 @@ package numbervalidator import ( "math/big" - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // NoneOf checks that the *big.Float held in the attribute @@ -14,7 +15,7 @@ import ( func NoneOf(unacceptableFloats ...*big.Float) tfsdk.AttributeValidator { unacceptableFloatValues := make([]attr.Value, 0, len(unacceptableFloats)) for _, f := range unacceptableFloats { - unacceptableFloatValues = append(unacceptableFloatValues, types.Number{Value: f}) + unacceptableFloatValues = append(unacceptableFloatValues, types.NumberValue(f)) } return primitivevalidator.NoneOf(unacceptableFloatValues...) diff --git a/numbervalidator/none_of_test.go b/numbervalidator/none_of_test.go index 53623a90..95a819a9 100644 --- a/numbervalidator/none_of_test.go +++ b/numbervalidator/none_of_test.go @@ -5,10 +5,11 @@ import ( "math/big" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator" ) func TestNoneOfValidator(t *testing.T) { @@ -22,7 +23,7 @@ func TestNoneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.Number{Value: big.NewFloat(123.456)}, + in: types.NumberValue(big.NewFloat(123.456)), validator: numbervalidator.NoneOf( big.NewFloat(123.456), big.NewFloat(234.567), @@ -32,7 +33,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "simple-mismatch": { - in: types.Number{Value: big.NewFloat(123.456)}, + in: types.NumberValue(big.NewFloat(123.456)), validator: numbervalidator.NoneOf( big.NewFloat(234.567), big.NewFloat(8910.11), @@ -41,7 +42,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-null": { - in: types.Number{Null: true}, + in: types.NumberNull(), validator: numbervalidator.NoneOf( big.NewFloat(234.567), big.NewFloat(8910.11), @@ -50,7 +51,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.Number{Unknown: true}, + in: types.NumberUnknown(), validator: numbervalidator.NoneOf( big.NewFloat(234.567), big.NewFloat(8910.11), diff --git a/numbervalidator/one_of.go b/numbervalidator/one_of.go index f18fa3ab..24f4c71b 100644 --- a/numbervalidator/one_of.go +++ b/numbervalidator/one_of.go @@ -3,10 +3,11 @@ package numbervalidator import ( "math/big" - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // OneOf checks that the *big.Float held in the attribute @@ -14,7 +15,7 @@ import ( func OneOf(acceptableFloats ...*big.Float) tfsdk.AttributeValidator { acceptableFloatValues := make([]attr.Value, 0, len(acceptableFloats)) for _, f := range acceptableFloats { - acceptableFloatValues = append(acceptableFloatValues, types.Number{Value: f}) + acceptableFloatValues = append(acceptableFloatValues, types.NumberValue(f)) } return primitivevalidator.OneOf(acceptableFloatValues...) diff --git a/numbervalidator/one_of_test.go b/numbervalidator/one_of_test.go index e9f76b17..ea788756 100644 --- a/numbervalidator/one_of_test.go +++ b/numbervalidator/one_of_test.go @@ -5,10 +5,11 @@ import ( "math/big" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/numbervalidator" ) func TestOneOfValidator(t *testing.T) { @@ -22,7 +23,7 @@ func TestOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.Number{Value: big.NewFloat(123.456)}, + in: types.NumberValue(big.NewFloat(123.456)), validator: numbervalidator.OneOf( big.NewFloat(123.456), big.NewFloat(234.567), @@ -32,7 +33,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "simple-mismatch": { - in: types.Number{Value: big.NewFloat(123.456)}, + in: types.NumberValue(big.NewFloat(123.456)), validator: numbervalidator.OneOf( big.NewFloat(234.567), big.NewFloat(8910.11), @@ -41,7 +42,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.Number{Null: true}, + in: types.NumberNull(), validator: numbervalidator.OneOf( big.NewFloat(234.567), big.NewFloat(8910.11), @@ -50,7 +51,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.Number{Unknown: true}, + in: types.NumberUnknown(), validator: numbervalidator.OneOf( big.NewFloat(234.567), big.NewFloat(8910.11), diff --git a/schemavalidator/also_requires_test.go b/schemavalidator/also_requires_test.go index 46bb89c6..179fd062 100644 --- a/schemavalidator/also_requires_test.go +++ b/schemavalidator/also_requires_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" + + "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" ) func TestRequiredWithValidator(t *testing.T) { @@ -23,7 +24,7 @@ func TestRequiredWithValidator(t *testing.T) { testCases := map[string]testCase{ "base": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -54,7 +55,7 @@ func TestRequiredWithValidator(t *testing.T) { }, "self-is-null": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -85,7 +86,7 @@ func TestRequiredWithValidator(t *testing.T) { }, "error_missing-one": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -123,7 +124,7 @@ func TestRequiredWithValidator(t *testing.T) { }, "error_missing-two": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -161,7 +162,7 @@ func TestRequiredWithValidator(t *testing.T) { }, "allow-duplicate-input": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -199,7 +200,7 @@ func TestRequiredWithValidator(t *testing.T) { }, "unknowns": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -236,7 +237,7 @@ func TestRequiredWithValidator(t *testing.T) { }, "matches-no-attribute-in-schema": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ diff --git a/schemavalidator/at_least_one_of_test.go b/schemavalidator/at_least_one_of_test.go index 45a1dfd8..d2f0be0e 100644 --- a/schemavalidator/at_least_one_of_test.go +++ b/schemavalidator/at_least_one_of_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" + + "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" ) func TestAtLeastOneOfValidator(t *testing.T) { @@ -23,7 +24,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "base": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -54,7 +55,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { }, "self-is-null": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -85,7 +86,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { }, "error_none-set": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -123,7 +124,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { }, "multiple-set": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -160,7 +161,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { }, "allow-duplicate-input": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -198,7 +199,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { }, "unknowns": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -235,7 +236,7 @@ func TestAtLeastOneOfValidator(t *testing.T) { }, "matches-no-attribute-in-schema": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ diff --git a/schemavalidator/conflicts_with_test.go b/schemavalidator/conflicts_with_test.go index bd151f8e..c648563a 100644 --- a/schemavalidator/conflicts_with_test.go +++ b/schemavalidator/conflicts_with_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" + + "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" ) func TestConflictsWithValidator(t *testing.T) { @@ -23,7 +24,7 @@ func TestConflictsWithValidator(t *testing.T) { testCases := map[string]testCase{ "base": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -61,7 +62,7 @@ func TestConflictsWithValidator(t *testing.T) { }, "conflicting-is-nil": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -92,7 +93,7 @@ func TestConflictsWithValidator(t *testing.T) { }, "conflicting-is-unknown": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -123,7 +124,7 @@ func TestConflictsWithValidator(t *testing.T) { }, "self-is-null": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -154,7 +155,7 @@ func TestConflictsWithValidator(t *testing.T) { }, "error_allow-duplicate-input": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -193,7 +194,7 @@ func TestConflictsWithValidator(t *testing.T) { }, "error_unknowns": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -231,7 +232,7 @@ func TestConflictsWithValidator(t *testing.T) { }, "matches-no-attribute-in-schema": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ diff --git a/schemavalidator/exactly_one_of_test.go b/schemavalidator/exactly_one_of_test.go index d05fef5d..41d5137e 100644 --- a/schemavalidator/exactly_one_of_test.go +++ b/schemavalidator/exactly_one_of_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-go/tftypes" + + "github.com/hashicorp/terraform-plugin-framework-validators/schemavalidator" ) func TestExactlyOneOfValidator(t *testing.T) { @@ -23,7 +24,7 @@ func TestExactlyOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "base": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -55,7 +56,7 @@ func TestExactlyOneOfValidator(t *testing.T) { }, "self-is-null": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -86,7 +87,7 @@ func TestExactlyOneOfValidator(t *testing.T) { }, "error_too-many": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -124,7 +125,7 @@ func TestExactlyOneOfValidator(t *testing.T) { }, "error_too-few": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Null: true}, + AttributeConfig: types.StringNull(), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -162,7 +163,7 @@ func TestExactlyOneOfValidator(t *testing.T) { }, "allow-duplicate-input": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -200,7 +201,7 @@ func TestExactlyOneOfValidator(t *testing.T) { }, "other-attributes-are-unknown": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ @@ -237,7 +238,7 @@ func TestExactlyOneOfValidator(t *testing.T) { }, "matches-no-attribute-in-schema": { req: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "bar value"}, + AttributeConfig: types.StringValue("bar value"), AttributePath: path.Root("bar"), AttributePathExpression: path.MatchRoot("bar"), Config: tfsdk.Config{ diff --git a/setvalidator/size_at_least_test.go b/setvalidator/size_at_least_test.go index aa5b9bc6..e34763e9 100644 --- a/setvalidator/size_at_least_test.go +++ b/setvalidator/size_at_least_test.go @@ -20,49 +20,47 @@ func TestSizeAtLeastValidator(t *testing.T) { } tests := map[string]testCase{ "not a Set": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "Set unknown": { - val: types.Set{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.SetUnknown( + types.StringType, + ), expectError: false, }, "Set null": { - val: types.Set{ - Null: true, - ElemType: types.StringType, - }, + val: types.SetNull( + types.StringType, + ), expectError: false, }, "Set size greater than min": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), min: 1, expectError: false, }, "Set size equal to min": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), }, - }, + ), min: 1, expectError: false, }, "Set size less than min": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{}, - }, + val: types.SetValueMust( + types.StringType, + []attr.Value{}, + ), min: 1, expectError: true, }, diff --git a/setvalidator/size_at_most_test.go b/setvalidator/size_at_most_test.go index 26561f64..2cc3d2a2 100644 --- a/setvalidator/size_at_most_test.go +++ b/setvalidator/size_at_most_test.go @@ -20,52 +20,51 @@ func TestSizeAtMostValidator(t *testing.T) { } tests := map[string]testCase{ "not a Set": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "Set unknown": { - val: types.Set{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.SetUnknown( + types.StringType, + ), expectError: false, }, "Set null": { - val: types.Set{ - Null: true, - ElemType: types.StringType, - }, + val: types.SetNull( + types.StringType, + ), expectError: false, }, "Set size less than max": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), }, - }, + ), max: 2, expectError: false, }, "Set size equal to max": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), max: 2, expectError: false, }, "Set size greater than max": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, - types.String{Value: "third"}, - }}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), + types.StringValue("third"), + }, + ), max: 2, expectError: true, }, diff --git a/setvalidator/size_between_test.go b/setvalidator/size_between_test.go index 273130e2..3312f2ad 100644 --- a/setvalidator/size_between_test.go +++ b/setvalidator/size_between_test.go @@ -21,90 +21,88 @@ func TestSizeBetweenValidator(t *testing.T) { } tests := map[string]testCase{ "not a Set": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "Set unknown": { - val: types.Set{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.SetUnknown( + types.StringType, + ), expectError: false, }, "Set null": { - val: types.Set{ - Null: true, - ElemType: types.StringType, - }, + val: types.SetNull( + types.StringType, + ), expectError: false, }, "Set size greater than min": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Set size equal to min": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Set size less than max": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Set size equal to max": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, - types.String{Value: "third"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), + types.StringValue("third"), }, - }, + ), min: 1, max: 3, expectError: false, }, "Set size less than min": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{}, - }, + val: types.SetValueMust( + types.StringType, + []attr.Value{}, + ), min: 1, max: 3, expectError: true, }, "Set size greater than max": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, - types.String{Value: "third"}, - types.String{Value: "fourth"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), + types.StringValue("third"), + types.StringValue("fourth"), }, - }, + ), min: 1, max: 3, expectError: true, diff --git a/setvalidator/type_validation_test.go b/setvalidator/type_validation_test.go index db8f32be..887309a7 100644 --- a/setvalidator/type_validation_test.go +++ b/setvalidator/type_validation_test.go @@ -21,7 +21,7 @@ func TestValidateSet(t *testing.T) { }{ "invalid-type": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Bool{Value: true}, + AttributeConfig: types.BoolValue(true), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -30,7 +30,7 @@ func TestValidateSet(t *testing.T) { }, "set-null": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Set{Null: true}, + AttributeConfig: types.SetNull(types.StringType), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -39,7 +39,7 @@ func TestValidateSet(t *testing.T) { }, "set-unknown": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Set{Unknown: true}, + AttributeConfig: types.SetUnknown(types.StringType), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -48,19 +48,19 @@ func TestValidateSet(t *testing.T) { }, "set-value": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + AttributeConfig: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, expectedSetElems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + types.StringValue("first"), + types.StringValue("second"), }, expectedOk: true, }, diff --git a/setvalidator/values_are_test.go b/setvalidator/values_are_test.go index e5caa8e7..07b1935f 100644 --- a/setvalidator/values_are_test.go +++ b/setvalidator/values_are_test.go @@ -23,46 +23,45 @@ func TestValuesAreValidator(t *testing.T) { } tests := map[string]testCase{ "not Set": { - val: types.Map{ - ElemType: types.StringType, - }, + val: types.MapValueMust( + types.StringType, + map[string]attr.Value{}, + ), expectError: true, }, "Set unknown": { - val: types.Set{ - Unknown: true, - ElemType: types.StringType, - }, + val: types.SetUnknown( + types.StringType, + ), expectError: false, }, "Set null": { - val: types.Set{ - Null: true, - ElemType: types.StringType, - }, + val: types.SetNull( + types.StringType, + ), expectError: false, }, "Set elems invalid": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(6), }, expectError: true, }, "Set elems invalid for second validator": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(2), stringvalidator.LengthAtLeast(6), @@ -70,26 +69,26 @@ func TestValuesAreValidator(t *testing.T) { expectError: true, }, "Set elems wrong type for validator": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ int64validator.AtLeast(6), }, expectError: true, }, "Set elems valid": { - val: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "first"}, - types.String{Value: "second"}, + val: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("first"), + types.StringValue("second"), }, - }, + ), valuesAreValidators: []tfsdk.AttributeValidator{ stringvalidator.LengthAtLeast(5), }, diff --git a/stringvalidator/length_at_least_test.go b/stringvalidator/length_at_least_test.go index 0a3bbbc6..dfa50b78 100644 --- a/stringvalidator/length_at_least_test.go +++ b/stringvalidator/length_at_least_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" ) func TestLengthAtLeastValidator(t *testing.T) { @@ -21,23 +22,23 @@ func TestLengthAtLeastValidator(t *testing.T) { } tests := map[string]testCase{ "not a String": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown String": { - val: types.String{Unknown: true}, + val: types.StringUnknown(), minLength: 1, }, "null String": { - val: types.String{Null: true}, + val: types.StringNull(), minLength: 1, }, "valid String": { - val: types.String{Value: "ok"}, + val: types.StringValue("ok"), minLength: 1, }, "too short String": { - val: types.String{Value: ""}, + val: types.StringValue(""), minLength: 1, expectError: true, }, diff --git a/stringvalidator/length_at_most_test.go b/stringvalidator/length_at_most_test.go index 39d315d0..1bfe252b 100644 --- a/stringvalidator/length_at_most_test.go +++ b/stringvalidator/length_at_most_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" ) func TestLengthAtMostValidator(t *testing.T) { @@ -21,23 +22,23 @@ func TestLengthAtMostValidator(t *testing.T) { } tests := map[string]testCase{ "not a String": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown String": { - val: types.String{Unknown: true}, + val: types.StringUnknown(), maxLength: 1, }, "null String": { - val: types.String{Null: true}, + val: types.StringNull(), maxLength: 1, }, "valid String": { - val: types.String{Value: "ok"}, + val: types.StringValue("ok"), maxLength: 2, }, "too long String": { - val: types.String{Value: "not ok"}, + val: types.StringValue("not ok"), maxLength: 5, expectError: true, }, diff --git a/stringvalidator/length_between_test.go b/stringvalidator/length_between_test.go index ce8cf560..757d0c38 100644 --- a/stringvalidator/length_between_test.go +++ b/stringvalidator/length_between_test.go @@ -4,11 +4,12 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/path" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" ) func TestLengthBetweenValidator(t *testing.T) { @@ -22,32 +23,32 @@ func TestLengthBetweenValidator(t *testing.T) { } tests := map[string]testCase{ "not a String": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown String": { - val: types.String{Unknown: true}, + val: types.StringUnknown(), minLength: 1, maxLength: 3, }, "null String": { - val: types.String{Null: true}, + val: types.StringNull(), minLength: 1, maxLength: 3, }, "valid String": { - val: types.String{Value: "ok"}, + val: types.StringValue("ok"), minLength: 1, maxLength: 3, }, "too long String": { - val: types.String{Value: "not ok"}, + val: types.StringValue("not ok"), minLength: 1, maxLength: 3, expectError: true, }, "too short String": { - val: types.String{Value: ""}, + val: types.StringValue(""), minLength: 1, maxLength: 3, expectError: true, diff --git a/stringvalidator/none_of.go b/stringvalidator/none_of.go index c444e283..0c4f9a5a 100644 --- a/stringvalidator/none_of.go +++ b/stringvalidator/none_of.go @@ -1,10 +1,11 @@ package stringvalidator import ( - "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/internal/primitivevalidator" ) // NoneOf checks that the string held in the attribute @@ -12,7 +13,7 @@ import ( func NoneOf(unacceptableStrings ...string) tfsdk.AttributeValidator { unacceptableStringValues := make([]attr.Value, 0, len(unacceptableStrings)) for _, s := range unacceptableStrings { - unacceptableStringValues = append(unacceptableStringValues, types.String{Value: s}) + unacceptableStringValues = append(unacceptableStringValues, types.StringValue(s)) } return primitivevalidator.NoneOf(unacceptableStringValues...) diff --git a/stringvalidator/none_of_test.go b/stringvalidator/none_of_test.go index e4361e58..44e05188 100644 --- a/stringvalidator/none_of_test.go +++ b/stringvalidator/none_of_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" ) func TestNoneOfValidator(t *testing.T) { @@ -27,7 +28,7 @@ func TestNoneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.NoneOf( "foo", "bar", @@ -36,7 +37,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "simple-mismatch-case-insensitive": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.NoneOf( "FOO", "bar", @@ -45,7 +46,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "simple-mismatch": { - in: types.String{Value: "foz"}, + in: types.StringValue("foz"), validator: stringvalidator.NoneOf( "foo", "bar", @@ -54,14 +55,14 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "list-not-allowed": { - in: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "10"}, - types.String{Value: "20"}, - types.String{Value: "30"}, + in: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("10"), + types.StringValue("20"), + types.StringValue("30"), }, - }, + ), validator: stringvalidator.NoneOf( "10", "20", @@ -72,14 +73,14 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "set-not-allowed": { - in: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + in: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), }, - }, + ), validator: stringvalidator.NoneOf( "bob", "alice", @@ -91,14 +92,14 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "map-not-allowed": { - in: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one.one": types.String{Value: "1.1"}, - "ten.twenty": types.String{Value: "10.20"}, - "five.four": types.String{Value: "5.4"}, + in: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one.one": types.StringValue("1.1"), + "ten.twenty": types.StringValue("10.20"), + "five.four": types.StringValue("5.4"), }, - }, + ), validator: stringvalidator.NoneOf( "1.1", "10.20", @@ -109,14 +110,14 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "object-not-allowed": { - in: types.Object{ - AttrTypes: objAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.String{Value: "40"}, - "Address": types.String{Value: "1200 Park Avenue Emeryville"}, + in: types.ObjectValueMust( + objAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.StringValue("40"), + "Address": types.StringValue("1200 Park Avenue Emeryville"), }, - }, + ), validator: stringvalidator.NoneOf( "Bob Parr", "40", @@ -126,7 +127,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.String{Null: true}, + in: types.StringNull(), validator: stringvalidator.NoneOf( "foo", "bar", @@ -135,7 +136,7 @@ func TestNoneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.String{Unknown: true}, + in: types.StringUnknown(), validator: stringvalidator.NoneOf( "foo", "bar", @@ -186,7 +187,7 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.NoneOfCaseInsensitive( "foo", "bar", @@ -195,7 +196,7 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "simple-match-case-insensitive": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.NoneOfCaseInsensitive( "FOO", "bar", @@ -204,7 +205,7 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "simple-mismatch": { - in: types.String{Value: "foz"}, + in: types.StringValue("foz"), validator: stringvalidator.NoneOfCaseInsensitive( "foo", "bar", @@ -213,14 +214,14 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 0, }, "list-not-allowed": { - in: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "10"}, - types.String{Value: "20"}, - types.String{Value: "30"}, + in: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("10"), + types.StringValue("20"), + types.StringValue("30"), }, - }, + ), validator: stringvalidator.NoneOfCaseInsensitive( "10", "20", @@ -231,14 +232,14 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "set-not-allowed": { - in: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + in: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), }, - }, + ), validator: stringvalidator.NoneOfCaseInsensitive( "bob", "alice", @@ -250,14 +251,14 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "map-not-allowed": { - in: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one.one": types.String{Value: "1.1"}, - "ten.twenty": types.String{Value: "10.20"}, - "five.four": types.String{Value: "5.4"}, + in: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one.one": types.StringValue("1.1"), + "ten.twenty": types.StringValue("10.20"), + "five.four": types.StringValue("5.4"), }, - }, + ), validator: stringvalidator.NoneOfCaseInsensitive( "1.1", "10.20", @@ -268,14 +269,14 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "object-not-allowed": { - in: types.Object{ - AttrTypes: objAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.String{Value: "40"}, - "Address": types.String{Value: "1200 Park Avenue Emeryville"}, + in: types.ObjectValueMust( + objAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.StringValue("40"), + "Address": types.StringValue("1200 Park Avenue Emeryville"), }, - }, + ), validator: stringvalidator.NoneOfCaseInsensitive( "Bob Parr", "40", @@ -285,7 +286,7 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.String{Null: true}, + in: types.StringNull(), validator: stringvalidator.NoneOfCaseInsensitive( "foo", "bar", @@ -294,7 +295,7 @@ func TestNoneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.String{Unknown: true}, + in: types.StringUnknown(), validator: stringvalidator.NoneOfCaseInsensitive( "foo", "bar", diff --git a/stringvalidator/one_of.go b/stringvalidator/one_of.go index 5b41ad5a..8419fd53 100644 --- a/stringvalidator/one_of.go +++ b/stringvalidator/one_of.go @@ -12,7 +12,7 @@ import ( func OneOf(acceptableStrings ...string) tfsdk.AttributeValidator { acceptableStringValues := make([]attr.Value, 0, len(acceptableStrings)) for _, s := range acceptableStrings { - acceptableStringValues = append(acceptableStringValues, types.String{Value: s}) + acceptableStringValues = append(acceptableStringValues, types.StringValue(s)) } return primitivevalidator.OneOf(acceptableStringValues...) diff --git a/stringvalidator/one_of_test.go b/stringvalidator/one_of_test.go index 568dd120..0ef780a3 100644 --- a/stringvalidator/one_of_test.go +++ b/stringvalidator/one_of_test.go @@ -4,10 +4,11 @@ import ( "context" "testing" - "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" "github.com/hashicorp/terraform-plugin-framework/attr" "github.com/hashicorp/terraform-plugin-framework/tfsdk" "github.com/hashicorp/terraform-plugin-framework/types" + + "github.com/hashicorp/terraform-plugin-framework-validators/stringvalidator" ) func TestOneOfValidator(t *testing.T) { @@ -27,7 +28,7 @@ func TestOneOfValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.OneOf( "foo", "bar", @@ -36,7 +37,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "simple-mismatch-case-insensitive": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.OneOf( "FOO", "bar", @@ -45,7 +46,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "simple-mismatch": { - in: types.String{Value: "foz"}, + in: types.StringValue("foz"), validator: stringvalidator.OneOf( "foo", "bar", @@ -54,14 +55,14 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "list-not-allowed": { - in: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "10"}, - types.String{Value: "20"}, - types.String{Value: "30"}, + in: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("10"), + types.StringValue("20"), + types.StringValue("30"), }, - }, + ), validator: stringvalidator.OneOf( "10", "20", @@ -72,14 +73,14 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "set-not-allowed": { - in: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + in: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), }, - }, + ), validator: stringvalidator.OneOf( "bob", "alice", @@ -91,14 +92,14 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "map-not-allowed": { - in: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one.one": types.String{Value: "1.1"}, - "ten.twenty": types.String{Value: "10.20"}, - "five.four": types.String{Value: "5.4"}, + in: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one.one": types.StringValue("1.1"), + "ten.twenty": types.StringValue("10.20"), + "five.four": types.StringValue("5.4"), }, - }, + ), validator: stringvalidator.OneOf( "1.1", "10.20", @@ -109,14 +110,14 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "object-not-allowed": { - in: types.Object{ - AttrTypes: objAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.String{Value: "40"}, - "Address": types.String{Value: "1200 Park Avenue Emeryville"}, + in: types.ObjectValueMust( + objAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.StringValue("40"), + "Address": types.StringValue("1200 Park Avenue Emeryville"), }, - }, + ), validator: stringvalidator.OneOf( "Bob Parr", "40", @@ -126,7 +127,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.String{Null: true}, + in: types.StringNull(), validator: stringvalidator.OneOf( "foo", "bar", @@ -135,7 +136,7 @@ func TestOneOfValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.String{Unknown: true}, + in: types.StringUnknown(), validator: stringvalidator.OneOf( "foo", "bar", @@ -186,7 +187,7 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { testCases := map[string]testCase{ "simple-match": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.OneOfCaseInsensitive( "foo", "bar", @@ -195,7 +196,7 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 0, }, "simple-match-case-insensitive": { - in: types.String{Value: "foo"}, + in: types.StringValue("foo"), validator: stringvalidator.OneOfCaseInsensitive( "FOO", "bar", @@ -204,7 +205,7 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 0, }, "simple-mismatch": { - in: types.String{Value: "foz"}, + in: types.StringValue("foz"), validator: stringvalidator.OneOfCaseInsensitive( "foo", "bar", @@ -213,14 +214,14 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "list-not-allowed": { - in: types.List{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "10"}, - types.String{Value: "20"}, - types.String{Value: "30"}, + in: types.ListValueMust( + types.StringType, + []attr.Value{ + types.StringValue("10"), + types.StringValue("20"), + types.StringValue("30"), }, - }, + ), validator: stringvalidator.OneOfCaseInsensitive( "10", "20", @@ -231,14 +232,14 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "set-not-allowed": { - in: types.Set{ - ElemType: types.StringType, - Elems: []attr.Value{ - types.String{Value: "foo"}, - types.String{Value: "bar"}, - types.String{Value: "baz"}, + in: types.SetValueMust( + types.StringType, + []attr.Value{ + types.StringValue("foo"), + types.StringValue("bar"), + types.StringValue("baz"), }, - }, + ), validator: stringvalidator.OneOfCaseInsensitive( "bob", "alice", @@ -250,14 +251,14 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "map-not-allowed": { - in: types.Map{ - ElemType: types.StringType, - Elems: map[string]attr.Value{ - "one.one": types.String{Value: "1.1"}, - "ten.twenty": types.String{Value: "10.20"}, - "five.four": types.String{Value: "5.4"}, + in: types.MapValueMust( + types.StringType, + map[string]attr.Value{ + "one.one": types.StringValue("1.1"), + "ten.twenty": types.StringValue("10.20"), + "five.four": types.StringValue("5.4"), }, - }, + ), validator: stringvalidator.OneOfCaseInsensitive( "1.1", "10.20", @@ -268,14 +269,14 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "object-not-allowed": { - in: types.Object{ - AttrTypes: objAttrTypes, - Attrs: map[string]attr.Value{ - "Name": types.String{Value: "Bob Parr"}, - "Age": types.String{Value: "40"}, - "Address": types.String{Value: "1200 Park Avenue Emeryville"}, + in: types.ObjectValueMust( + objAttrTypes, + map[string]attr.Value{ + "Name": types.StringValue("Bob Parr"), + "Age": types.StringValue("40"), + "Address": types.StringValue("1200 Park Avenue Emeryville"), }, - }, + ), validator: stringvalidator.OneOfCaseInsensitive( "Bob Parr", "40", @@ -285,7 +286,7 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 1, }, "skip-validation-on-null": { - in: types.String{Null: true}, + in: types.StringNull(), validator: stringvalidator.OneOfCaseInsensitive( "foo", "bar", @@ -294,7 +295,7 @@ func TestOneOfCaseInsensitiveValidator(t *testing.T) { expErrors: 0, }, "skip-validation-on-unknown": { - in: types.String{Unknown: true}, + in: types.StringUnknown(), validator: stringvalidator.OneOfCaseInsensitive( "foo", "bar", diff --git a/stringvalidator/regex_matches_test.go b/stringvalidator/regex_matches_test.go index 76f04306..22e384d6 100644 --- a/stringvalidator/regex_matches_test.go +++ b/stringvalidator/regex_matches_test.go @@ -23,23 +23,23 @@ func TestRegexMatchesValidator(t *testing.T) { } tests := map[string]testCase{ "not a String": { - val: types.Bool{Value: true}, + val: types.BoolValue(true), expectError: true, }, "unknown String": { - val: types.String{Unknown: true}, + val: types.StringUnknown(), regexp: regexp.MustCompile(`^o[j-l]?$`), }, "null String": { - val: types.String{Null: true}, + val: types.StringNull(), regexp: regexp.MustCompile(`^o[j-l]?$`), }, "valid String": { - val: types.String{Value: "ok"}, + val: types.StringValue("ok"), regexp: regexp.MustCompile(`^o[j-l]?$`), }, "invalid String": { - val: types.String{Value: "not ok"}, + val: types.StringValue("not ok"), regexp: regexp.MustCompile(`^o[j-l]?$`), expectError: true, }, diff --git a/stringvalidator/type_validation_test.go b/stringvalidator/type_validation_test.go index b02ed6f5..2bf9541b 100644 --- a/stringvalidator/type_validation_test.go +++ b/stringvalidator/type_validation_test.go @@ -20,7 +20,7 @@ func TestValidateString(t *testing.T) { }{ "invalid-type": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Bool{Value: true}, + AttributeConfig: types.BoolValue(true), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -29,7 +29,7 @@ func TestValidateString(t *testing.T) { }, "string-null": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64{Null: true}, + AttributeConfig: types.Int64Null(), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -38,7 +38,7 @@ func TestValidateString(t *testing.T) { }, "string-value": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.String{Value: "test-value"}, + AttributeConfig: types.StringValue("test-value"), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), }, @@ -47,7 +47,7 @@ func TestValidateString(t *testing.T) { }, "string-unknown": { request: tfsdk.ValidateAttributeRequest{ - AttributeConfig: types.Int64{Unknown: true}, + AttributeConfig: types.Int64Unknown(), AttributePath: path.Root("test"), AttributePathExpression: path.MatchRoot("test"), },