@@ -7,11 +7,12 @@ import (
77 "testing"
88
99 "github.com/hashicorp/go-version"
10+ "github.com/hashicorp/terraform-plugin-testing/config"
1011 "github.com/hashicorp/terraform-plugin-testing/helper/resource"
1112 "github.com/hashicorp/terraform-plugin-testing/tfversion"
1213)
1314
14- func TestIsNullFunction (t * testing.T ) {
15+ func TestNullFunction (t * testing.T ) {
1516 t .Parallel ()
1617 resource .UnitTest (t , resource.TestCase {
1718 TerraformVersionChecks : []tfversion.TerraformVersionCheck {
@@ -36,7 +37,86 @@ output "test" {
3637 })
3738}
3839
39- func TestIsNullFunction_falseCases (t * testing.T ) {
40+ func TestNullFunction_crossObjectValidation (t * testing.T ) {
41+ t .Parallel ()
42+ resource .UnitTest (t , resource.TestCase {
43+ TerraformVersionChecks : []tfversion.TerraformVersionCheck {
44+ tfversion .SkipBelow (version .Must (version .NewVersion (MinimalRequiredTerraformVersion ))),
45+ },
46+ ExternalProviders : map [string ]resource.ExternalProvider {
47+ "wireguard" : {
48+ Source : "OJFord/wireguard" ,
49+ VersionConstraint : "0.3.1" ,
50+ },
51+ },
52+ ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
53+ Steps : []resource.TestStep {
54+ {
55+ Config : `
56+ resource "wireguard_asymmetric_key" "main" {}
57+
58+ data "wireguard_config_document" "main" {
59+ private_key = wireguard_asymmetric_key.main.private_key
60+ }
61+
62+ output "test" {
63+ // .addresses is always null in this configuration
64+ value = provider::assert::null(data.wireguard_config_document.main.addresses)
65+ }
66+ ` ,
67+ Check : resource .ComposeAggregateTestCheckFunc (
68+ resource .TestCheckOutput ("test" , "true" ),
69+ ),
70+ },
71+ },
72+ })
73+ }
74+
75+ func TestNullFunction_compoundValidation (t * testing.T ) {
76+ t .Parallel ()
77+ resource .UnitTest (t , resource.TestCase {
78+ TerraformVersionChecks : []tfversion.TerraformVersionCheck {
79+ tfversion .SkipBelow (version .Must (version .NewVersion (MinimalRequiredTerraformVersion ))),
80+ },
81+ ProtoV6ProviderFactories : testAccProtoV6ProviderFactories ,
82+ Steps : []resource.TestStep {
83+ {
84+ Config : `
85+ variable "ipv4_ipam_pool_id" {
86+ default = null
87+ description = "ID of the IPv4 IPAM pool to use for the VPC."
88+ type = string
89+ }
90+
91+ variable "cidr_block" {
92+ default = null
93+ description = "CIDR block for the VPC."
94+ type = string
95+
96+ validation {
97+ condition = provider::assert::cidr(var.cidr_block)
98+ error_message = "CIDR block must be a valid CIDR range."
99+ }
100+
101+ validation {
102+ condition = anytrue([
103+ !provider::assert::null(var.cidr_block),
104+ !provider::assert::null(var.ipv4_ipam_pool_id)
105+ ])
106+ error_message = "Exactly one of cidr_block or ipv4_ipam_pool_id must be provided."
107+ }
108+ }
109+ ` ,
110+ ConfigVariables : config.Variables {
111+ "cidr_block" : config .StringVariable ("10.0.42.0/24" ),
112+ },
113+ Check : resource .ComposeAggregateTestCheckFunc (),
114+ },
115+ },
116+ })
117+ }
118+
119+ func TestNullFunction_falseCases (t * testing.T ) {
40120 t .Parallel ()
41121 resource .UnitTest (t , resource.TestCase {
42122 TerraformVersionChecks : []tfversion.TerraformVersionCheck {
0 commit comments