@@ -3,11 +3,16 @@ package argo_smart_routing_test
3
3
import (
4
4
"fmt"
5
5
"os"
6
+ "regexp"
6
7
"testing"
7
8
9
+ "github.com/hashicorp/terraform-plugin-testing/helper/resource"
10
+ "github.com/hashicorp/terraform-plugin-testing/knownvalue"
11
+ "github.com/hashicorp/terraform-plugin-testing/plancheck"
12
+ "github.com/hashicorp/terraform-plugin-testing/tfjsonpath"
13
+
8
14
"github.com/cloudflare/terraform-provider-cloudflare/internal/acctest"
9
15
"github.com/cloudflare/terraform-provider-cloudflare/internal/utils"
10
- "github.com/hashicorp/terraform-plugin-testing/helper/resource"
11
16
)
12
17
13
18
func TestAccCloudflareArgoSmartRouting_Basic (t * testing.T ) {
@@ -17,21 +22,83 @@ func TestAccCloudflareArgoSmartRouting_Basic(t *testing.T) {
17
22
18
23
resource .Test (t , resource.TestCase {
19
24
PreCheck : func () {
20
- acctest .TestAccPreCheck_AccountID (t )
25
+ acctest .TestAccPreCheck_ZoneID (t )
21
26
acctest .TestAccPreCheck_Credentials (t )
22
27
},
23
28
ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
24
29
Steps : []resource.TestStep {
25
30
{
26
- Config : testAccCheckCloudflareArgoSmartRoutingBasic (zoneID , rnd ),
31
+ Config : testAccCheckCloudflareArgoSmartRoutingEnable (zoneID , rnd ),
32
+ Check : resource .ComposeTestCheckFunc (
33
+ resource .TestCheckResourceAttr (name , "id" , zoneID ),
34
+ resource .TestCheckResourceAttr (name , "zone_id" , zoneID ),
35
+ resource .TestCheckResourceAttr (name , "value" , "on" ),
36
+ ),
37
+ },
38
+ {
39
+ Config : testAccCheckCloudflareArgoSmartRoutingEnable (zoneID , rnd ),
27
40
Check : resource .ComposeTestCheckFunc (
41
+ resource .TestCheckResourceAttr (name , "id" , zoneID ),
42
+ resource .TestCheckResourceAttr (name , "zone_id" , zoneID ),
28
43
resource .TestCheckResourceAttr (name , "value" , "on" ),
29
44
),
45
+ PlanOnly : true ,
46
+ ExpectNonEmptyPlan : false ,
47
+ },
48
+ {
49
+ Config : testAccCheckCloudflareArgoSmartRoutingDisable (zoneID , rnd ),
50
+ Check : resource .ComposeTestCheckFunc (
51
+ resource .TestCheckResourceAttr (name , "id" , zoneID ),
52
+ resource .TestCheckResourceAttr (name , "zone_id" , zoneID ),
53
+ resource .TestCheckResourceAttr (name , "value" , "off" ),
54
+ ),
55
+ ConfigPlanChecks : resource.ConfigPlanChecks {
56
+ PreApply : []plancheck.PlanCheck {
57
+ plancheck .ExpectResourceAction (name , plancheck .ResourceActionUpdate ),
58
+ plancheck .ExpectKnownValue (
59
+ name ,
60
+ tfjsonpath .New ("value" ),
61
+ knownvalue .StringExact ("off" ),
62
+ ),
63
+ },
64
+ },
65
+ },
66
+ {
67
+ ResourceName : name ,
68
+ ImportState : true ,
69
+ ImportStateVerify : true ,
30
70
},
31
71
},
32
72
})
33
73
}
34
74
35
- func testAccCheckCloudflareArgoSmartRoutingBasic (zoneID , name string ) string {
36
- return acctest .LoadTestCase ("basic.tf" , zoneID , name )
75
+ func TestAccCloudflareArgoSmartRouting_InvalidValue (t * testing.T ) {
76
+ zoneID := os .Getenv ("CLOUDFLARE_ZONE_ID" )
77
+ rnd := utils .GenerateRandomResourceName ()
78
+
79
+ resource .Test (t , resource.TestCase {
80
+ PreCheck : func () {
81
+ acctest .TestAccPreCheck_AccountID (t )
82
+ acctest .TestAccPreCheck_Credentials (t )
83
+ },
84
+ ProtoV6ProviderFactories : acctest .TestAccProtoV6ProviderFactories ,
85
+ Steps : []resource.TestStep {
86
+ {
87
+ Config : testAccCheckCloudflareArgoSmartRoutingInvalidValue (zoneID , rnd ),
88
+ ExpectError : regexp .MustCompile (regexp .QuoteMeta ("Invalid Attribute Value Match" )),
89
+ },
90
+ },
91
+ })
92
+ }
93
+
94
+ func testAccCheckCloudflareArgoSmartRoutingEnable (zoneID , name string ) string {
95
+ return acctest .LoadTestCase ("enable.tf" , zoneID , name )
96
+ }
97
+
98
+ func testAccCheckCloudflareArgoSmartRoutingDisable (zoneID , name string ) string {
99
+ return acctest .LoadTestCase ("disable.tf" , zoneID , name )
100
+ }
101
+
102
+ func testAccCheckCloudflareArgoSmartRoutingInvalidValue (zoneID , name string ) string {
103
+ return acctest .LoadTestCase ("invalid_value.tf" , zoneID , name )
37
104
}
0 commit comments