Skip to content
This repository was archived by the owner on Jun 12, 2025. It is now read-only.

Commit c88fd10

Browse files
test: improve compound validation
1 parent aecff3b commit c88fd10

File tree

2 files changed

+19
-30
lines changed

2 files changed

+19
-30
lines changed

internal/provider/not_null_function_test.go

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -225,39 +225,33 @@ func TestNotNullFunction_compoundValidation(t *testing.T) {
225225
t.Parallel()
226226
resource.UnitTest(t, resource.TestCase{
227227
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
228-
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
228+
tfversion.SkipBelow(version.Must(version.NewVersion("1.2.0"))),
229229
},
230230
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
231231
Steps: []resource.TestStep{
232232
{
233233
Config: `
234-
variable "ipv4_ipam_pool_id" {
234+
variable "example_value_a" {
235235
default = null
236-
description = "ID of the IPv4 IPAM pool to use for the VPC."
236+
description = "Example input A for validation."
237237
type = string
238238
}
239-
240-
variable "cidr_block" {
239+
variable "example_value_b" {
241240
default = null
242-
description = "CIDR block for the VPC."
241+
description = "Example input B for validation."
243242
type = string
244-
245-
validation {
246-
condition = provider::assert::cidr(var.cidr_block)
247-
error_message = "CIDR block must be a valid CIDR range."
248-
}
249-
250243
validation {
251244
condition = anytrue([
252-
provider::assert::not_null(var.cidr_block),
253-
provider::assert::not_null(var.ipv4_ipam_pool_id)
245+
provider::assert::not_null(var.example_value_a),
246+
provider::assert::not_null(var.example_value_b)
247+
254248
])
255-
error_message = "Exactly one of cidr_block or ipv4_ipam_pool_id must be provided."
249+
error_message = "At least one of example_value_a or example_value_b must be provided."
256250
}
257251
}
258252
`,
259253
ConfigVariables: config.Variables{
260-
"cidr_block": config.StringVariable("10.0.42.0/24"),
254+
"example_value_b": config.StringVariable("example-format-value"),
261255
},
262256
Check: resource.ComposeAggregateTestCheckFunc(),
263257
},

internal/provider/null_function_test.go

Lines changed: 9 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -76,39 +76,34 @@ func TestNullFunction_compoundValidation(t *testing.T) {
7676
t.Parallel()
7777
resource.UnitTest(t, resource.TestCase{
7878
TerraformVersionChecks: []tfversion.TerraformVersionCheck{
79-
tfversion.SkipBelow(version.Must(version.NewVersion(MinimalRequiredTerraformVersion))),
79+
tfversion.SkipBelow(version.Must(version.NewVersion("1.2.0"))),
8080
},
8181
ProtoV6ProviderFactories: testAccProtoV6ProviderFactories,
8282
Steps: []resource.TestStep{
8383
{
8484
Config: `
85-
variable "ipv4_ipam_pool_id" {
85+
variable "example_value_a" {
8686
default = null
87-
description = "ID of the IPv4 IPAM pool to use for the VPC."
87+
description = "Example option A for testing null validation."
8888
type = string
8989
}
9090
91-
variable "cidr_block" {
91+
variable "example_value_b" {
9292
default = null
93-
description = "CIDR block for the VPC."
93+
description = "Example option B for testing null validation."
9494
type = string
9595
96-
validation {
97-
condition = provider::assert::cidr(var.cidr_block)
98-
error_message = "CIDR block must be a valid CIDR range."
99-
}
100-
10196
validation {
10297
condition = anytrue([
103-
!provider::assert::null(var.cidr_block),
104-
!provider::assert::null(var.ipv4_ipam_pool_id)
98+
!provider::assert::null(var.example_value_a),
99+
!provider::assert::null(var.example_value_b)
105100
])
106-
error_message = "Exactly one of cidr_block or ipv4_ipam_pool_id must be provided."
101+
error_message = "Exactly one of example_value_a or example_value_b must be provided."
107102
}
108103
}
109104
`,
110105
ConfigVariables: config.Variables{
111-
"cidr_block": config.StringVariable("10.0.42.0/24"),
106+
"example_value_b": config.StringVariable("example-value"),
112107
},
113108
Check: resource.ComposeAggregateTestCheckFunc(),
114109
},

0 commit comments

Comments
 (0)