@@ -5,6 +5,8 @@ package main
55import (
66 "testing"
77
8+ "regexp"
9+
810 "github.com/hashicorp/terraform/helper/resource"
911 "github.com/hashicorp/terraform/terraform"
1012 "github.com/oracle/bmcs-go-sdk"
@@ -25,11 +27,7 @@ func (s *DatasourceIdentityAvailabilityDomainsTestSuite) SetupTest() {
2527 s .Client = testAccClient
2628 s .Provider = testAccProvider
2729 s .Providers = testAccProviders
28- s .Config = testProviderConfig () + `
29- data "oci_identity_availability_domains" "t" {
30- compartment_id = "${var.compartment_id}"
31- }`
32-
30+ s .Config = testProviderConfig ()
3331 s .ResourceName = "data.oci_identity_availability_domains.t"
3432}
3533
@@ -38,13 +36,33 @@ func (s *DatasourceIdentityAvailabilityDomainsTestSuite) TestAccIdentityAvailabi
3836 PreventPostDestroyRefresh : true ,
3937 Providers : s .Providers ,
4038 Steps : []resource.TestStep {
39+ // Verify expected number of ADs in expected order
40+ {
41+ Config : s .Config + `
42+ data "oci_identity_availability_domains" "t" {
43+ compartment_id = "${var.compartment_id}"
44+ }` ,
45+ Check : resource .ComposeTestCheckFunc (
46+ resource .TestCheckResourceAttr (s .ResourceName , "availability_domains.#" , "3" ),
47+ resource .TestMatchResourceAttr (s .ResourceName , "availability_domains.0.name" , regexp .MustCompile (`\w*:\w{3}-AD-1` )),
48+ resource .TestMatchResourceAttr (s .ResourceName , "availability_domains.1.name" , regexp .MustCompile (`\w*:\w{3}-AD-2` )),
49+ resource .TestMatchResourceAttr (s .ResourceName , "availability_domains.2.name" , regexp .MustCompile (`\w*:\w{3}-AD-3` )),
50+ ),
51+ },
52+ // Verify regex filtering
4153 {
42- ImportState : true ,
43- ImportStateVerify : true ,
44- Config : s .Config ,
54+ Config : s .Config + `
55+ data "oci_identity_availability_domains" "t" {
56+ compartment_id = "${var.compartment_id}"
57+ filter {
58+ name = "name"
59+ values = ["\\w*:\\w{3}-AD-2"]
60+ regex = true
61+ }
62+ }` ,
4563 Check : resource .ComposeTestCheckFunc (
46- resource .TestCheckResourceAttrSet (s .ResourceName , "availability_domains.0.name " ),
47- resource .TestCheckResourceAttrSet (s .ResourceName , "availability_domains.1 .name" ),
64+ resource .TestCheckResourceAttr (s .ResourceName , "availability_domains.#" , "1 " ),
65+ resource .TestMatchResourceAttr (s .ResourceName , "availability_domains.0 .name" , regexp . MustCompile ( ".*AD-2" ) ),
4866 ),
4967 },
5068 },
0 commit comments