github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/ultradns/resource_ultradns_probe_ping_test.go (about) 1 package ultradns 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/Ensighten/udnssdk" 8 "github.com/hashicorp/terraform/helper/resource" 9 ) 10 11 func TestAccUltradnsProbePing(t *testing.T) { 12 var record udnssdk.RRSet 13 domain := "ultradns.phinze.com" 14 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { testAccPreCheck(t) }, 17 Providers: testAccProviders, 18 CheckDestroy: testAccTcpoolCheckDestroy, 19 Steps: []resource.TestStep{ 20 resource.TestStep{ 21 Config: fmt.Sprintf(testCfgProbePingRecord, domain, domain), 22 Check: resource.ComposeTestCheckFunc( 23 testAccCheckUltradnsRecordExists("ultradns_tcpool.test-probe-ping-record", &record), 24 // Specified 25 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "zone", domain), 26 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "name", "test-probe-ping-record"), 27 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "pool_record", "10.3.0.1"), 28 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "agents.0", "DALLAS"), 29 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "agents.1", "AMSTERDAM"), 30 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "interval", "ONE_MINUTE"), 31 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "threshold", "2"), 32 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.packets", "15"), 33 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.packet_size", "56"), 34 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.#", "2"), 35 36 // hashLimits(): lossPercent -> 3375621462 37 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.name", "lossPercent"), 38 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.warning", "1"), 39 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.critical", "2"), 40 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.fail", "3"), 41 42 // hashLimits(): total -> 3257917790 43 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.name", "total"), 44 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.warning", "2"), 45 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.critical", "3"), 46 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.fail", "4"), 47 ), 48 }, 49 resource.TestStep{ 50 Config: fmt.Sprintf(testCfgProbePingPool, domain, domain), 51 Check: resource.ComposeTestCheckFunc( 52 testAccCheckUltradnsRecordExists("ultradns_tcpool.test-probe-ping-pool", &record), 53 // Specified 54 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "zone", domain), 55 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "name", "test-probe-ping-pool"), 56 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "agents.0", "DALLAS"), 57 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "agents.1", "AMSTERDAM"), 58 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "interval", "ONE_MINUTE"), 59 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "threshold", "2"), 60 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.packets", "15"), 61 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.packet_size", "56"), 62 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.#", "2"), 63 64 // hashLimits(): lossPercent -> 3375621462 65 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.name", "lossPercent"), 66 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.warning", "1"), 67 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.critical", "2"), 68 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3375621462.fail", "3"), 69 70 // hashLimits(): total -> 3257917790 71 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.name", "total"), 72 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.warning", "2"), 73 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.critical", "3"), 74 resource.TestCheckResourceAttr("ultradns_probe_ping.it", "ping_probe.0.limit.3257917790.fail", "4"), 75 ), 76 }, 77 }, 78 }) 79 } 80 81 const testCfgProbePingRecord = ` 82 resource "ultradns_tcpool" "test-probe-ping-record" { 83 zone = "%s" 84 name = "test-probe-ping-record" 85 86 ttl = 30 87 description = "traffic controller pool with probes" 88 89 run_probes = true 90 act_on_probes = true 91 max_to_lb = 2 92 93 rdata { 94 host = "10.3.0.1" 95 96 state = "NORMAL" 97 run_probes = true 98 priority = 1 99 failover_delay = 0 100 threshold = 1 101 weight = 2 102 } 103 104 rdata { 105 host = "10.3.0.2" 106 107 state = "NORMAL" 108 run_probes = true 109 priority = 2 110 failover_delay = 0 111 threshold = 1 112 weight = 2 113 } 114 115 backup_record_rdata = "10.3.0.3" 116 } 117 118 resource "ultradns_probe_ping" "it" { 119 zone = "%s" 120 name = "test-probe-ping-record" 121 122 pool_record = "10.3.0.1" 123 124 agents = ["DALLAS", "AMSTERDAM"] 125 126 interval = "ONE_MINUTE" 127 threshold = 2 128 129 ping_probe { 130 packets = 15 131 packet_size = 56 132 133 limit { 134 name = "lossPercent" 135 warning = 1 136 critical = 2 137 fail = 3 138 } 139 140 limit { 141 name = "total" 142 warning = 2 143 critical = 3 144 fail = 4 145 } 146 } 147 148 depends_on = ["ultradns_tcpool.test-probe-ping-record"] 149 } 150 ` 151 152 const testCfgProbePingPool = ` 153 resource "ultradns_tcpool" "test-probe-ping-pool" { 154 zone = "%s" 155 name = "test-probe-ping-pool" 156 157 ttl = 30 158 description = "traffic controller pool with probes" 159 160 run_probes = true 161 act_on_probes = true 162 max_to_lb = 2 163 164 rdata { 165 host = "10.3.0.1" 166 167 state = "NORMAL" 168 run_probes = true 169 priority = 1 170 failover_delay = 0 171 threshold = 1 172 weight = 2 173 } 174 175 rdata { 176 host = "10.3.0.2" 177 178 state = "NORMAL" 179 run_probes = true 180 priority = 2 181 failover_delay = 0 182 threshold = 1 183 weight = 2 184 } 185 186 backup_record_rdata = "10.3.0.3" 187 } 188 189 resource "ultradns_probe_ping" "it" { 190 zone = "%s" 191 name = "test-probe-ping-pool" 192 193 agents = ["DALLAS", "AMSTERDAM"] 194 195 interval = "ONE_MINUTE" 196 threshold = 2 197 198 ping_probe { 199 packets = 15 200 packet_size = 56 201 202 limit { 203 name = "lossPercent" 204 warning = 1 205 critical = 2 206 fail = 3 207 } 208 209 limit { 210 name = "total" 211 warning = 2 212 critical = 3 213 fail = 4 214 } 215 } 216 217 depends_on = ["ultradns_tcpool.test-probe-ping-pool"] 218 } 219 `