github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_consul_test.go (about) 1 package circonus 2 3 import ( 4 "fmt" 5 "regexp" 6 "testing" 7 8 "github.com/circonus-labs/circonus-gometrics/api/config" 9 "github.com/hashicorp/terraform/helper/acctest" 10 "github.com/hashicorp/terraform/helper/resource" 11 ) 12 13 func TestAccCirconusCheckConsul_node(t *testing.T) { 14 checkName := fmt.Sprintf("Terraform test: consul.service.consul mode=state check - %s", acctest.RandString(5)) 15 16 checkNode := fmt.Sprintf("my-node-name-or-node-id-%s", acctest.RandString(5)) 17 18 resource.Test(t, resource.TestCase{ 19 PreCheck: func() { testAccPreCheck(t) }, 20 Providers: testAccProviders, 21 CheckDestroy: testAccCheckDestroyCirconusCheckBundle, 22 Steps: []resource.TestStep{ 23 { 24 Config: fmt.Sprintf(testAccCirconusCheckConsulConfigV1HealthNodeFmt, checkName, checkNode), 25 Check: resource.ComposeTestCheckFunc( 26 resource.TestCheckResourceAttr("circonus_check.consul_server", "active", "true"), 27 resource.TestMatchResourceAttr("circonus_check.consul_server", "check_id", regexp.MustCompile(config.CheckCIDRegex)), 28 resource.TestCheckResourceAttr("circonus_check.consul_server", "collector.#", "1"), 29 resource.TestCheckResourceAttr("circonus_check.consul_server", "collector.2084916526.id", "/broker/2110"), 30 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.#", "1"), 31 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.ca_chain", ""), 32 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.certificate_file", ""), 33 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.ciphers", ""), 34 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.key_file", ""), 35 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.dc", "dc2"), 36 resource.TestCheckNoResourceAttr("circonus_check.consul_server", "consul.0.headers"), 37 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.http_addr", "http://consul.service.consul:8501"), 38 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.node", checkNode), 39 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.node_blacklist.#", "3"), 40 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.node_blacklist.0", "a"), 41 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.node_blacklist.1", "bad"), 42 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.node_blacklist.2", "node"), 43 resource.TestCheckResourceAttr("circonus_check.consul_server", "notes", ""), 44 resource.TestCheckResourceAttr("circonus_check.consul_server", "period", "60s"), 45 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.#", "2"), 46 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.active", "true"), 47 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.name", "KnownLeader"), 48 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.#", "2"), 49 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.1401442048", "lifecycle:unittest"), 50 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.2058715988", "source:consul"), 51 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.type", "text"), 52 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.active", "true"), 53 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.name", "LastContact"), 54 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.#", "2"), 55 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.1401442048", "lifecycle:unittest"), 56 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.2058715988", "source:consul"), 57 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.type", "numeric"), 58 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.unit", "seconds"), 59 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.#", "2"), 60 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.1401442048", "lifecycle:unittest"), 61 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.2058715988", "source:consul"), 62 resource.TestCheckResourceAttr("circonus_check.consul_server", "target", "consul.service.consul"), 63 resource.TestCheckResourceAttr("circonus_check.consul_server", "type", "consul"), 64 ), 65 }, 66 }, 67 }) 68 } 69 70 func TestAccCirconusCheckConsul_service(t *testing.T) { 71 checkName := fmt.Sprintf("Terraform test: consul.service.consul mode=service check - %s", acctest.RandString(5)) 72 73 resource.Test(t, resource.TestCase{ 74 PreCheck: func() { testAccPreCheck(t) }, 75 Providers: testAccProviders, 76 CheckDestroy: testAccCheckDestroyCirconusCheckBundle, 77 Steps: []resource.TestStep{ 78 { 79 Config: fmt.Sprintf(testAccCirconusCheckConsulConfigV1HealthServiceFmt, checkName), 80 Check: resource.ComposeTestCheckFunc( 81 resource.TestCheckResourceAttr("circonus_check.consul_server", "active", "true"), 82 resource.TestMatchResourceAttr("circonus_check.consul_server", "check_id", regexp.MustCompile(config.CheckCIDRegex)), 83 resource.TestCheckResourceAttr("circonus_check.consul_server", "collector.#", "1"), 84 resource.TestCheckResourceAttr("circonus_check.consul_server", "collector.2084916526.id", "/broker/2110"), 85 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.#", "1"), 86 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.ca_chain", ""), 87 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.certificate_file", ""), 88 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.ciphers", ""), 89 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.key_file", ""), 90 resource.TestCheckNoResourceAttr("circonus_check.consul_server", "consul.0.headers"), 91 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.http_addr", "http://consul.service.consul"), 92 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.service", "consul"), 93 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.service_blacklist.#", "3"), 94 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.service_blacklist.0", "bad"), 95 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.service_blacklist.1", "hombre"), 96 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.service_blacklist.2", "service"), 97 resource.TestCheckResourceAttr("circonus_check.consul_server", "name", checkName), 98 resource.TestCheckResourceAttr("circonus_check.consul_server", "notes", ""), 99 resource.TestCheckResourceAttr("circonus_check.consul_server", "period", "60s"), 100 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.#", "2"), 101 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.active", "true"), 102 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.name", "KnownLeader"), 103 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.#", "2"), 104 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.1401442048", "lifecycle:unittest"), 105 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.2058715988", "source:consul"), 106 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.type", "text"), 107 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.active", "true"), 108 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.name", "LastContact"), 109 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.#", "2"), 110 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.1401442048", "lifecycle:unittest"), 111 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.2058715988", "source:consul"), 112 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.type", "numeric"), 113 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.unit", "seconds"), 114 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.#", "2"), 115 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.1401442048", "lifecycle:unittest"), 116 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.2058715988", "source:consul"), 117 resource.TestCheckResourceAttr("circonus_check.consul_server", "target", "consul.service.consul"), 118 resource.TestCheckResourceAttr("circonus_check.consul_server", "type", "consul"), 119 ), 120 }, 121 }, 122 }) 123 } 124 125 func TestAccCirconusCheckConsul_state(t *testing.T) { 126 checkName := fmt.Sprintf("Terraform test: consul.service.consul mode=state check - %s", acctest.RandString(5)) 127 128 checkState := "critical" 129 resource.Test(t, resource.TestCase{ 130 PreCheck: func() { testAccPreCheck(t) }, 131 Providers: testAccProviders, 132 CheckDestroy: testAccCheckDestroyCirconusCheckBundle, 133 Steps: []resource.TestStep{ 134 { 135 Config: fmt.Sprintf(testAccCirconusCheckConsulConfigV1HealthStateFmt, checkName, checkState), 136 Check: resource.ComposeTestCheckFunc( 137 resource.TestCheckResourceAttr("circonus_check.consul_server", "active", "true"), 138 resource.TestMatchResourceAttr("circonus_check.consul_server", "check_id", regexp.MustCompile(config.CheckCIDRegex)), 139 resource.TestCheckResourceAttr("circonus_check.consul_server", "collector.#", "1"), 140 resource.TestCheckResourceAttr("circonus_check.consul_server", "collector.2084916526.id", "/broker/2110"), 141 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.#", "1"), 142 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.ca_chain", ""), 143 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.certificate_file", ""), 144 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.ciphers", ""), 145 // resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.key_file", ""), 146 resource.TestCheckNoResourceAttr("circonus_check.consul_server", "consul.0.headers"), 147 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.http_addr", "http://consul.service.consul"), 148 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.state", checkState), 149 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.check_blacklist.#", "2"), 150 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.check_blacklist.0", "worthless"), 151 resource.TestCheckResourceAttr("circonus_check.consul_server", "consul.0.check_blacklist.1", "check"), 152 resource.TestCheckResourceAttr("circonus_check.consul_server", "name", checkName), 153 resource.TestCheckResourceAttr("circonus_check.consul_server", "notes", ""), 154 resource.TestCheckResourceAttr("circonus_check.consul_server", "period", "60s"), 155 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.#", "2"), 156 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.active", "true"), 157 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.name", "KnownLeader"), 158 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.#", "2"), 159 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.1401442048", "lifecycle:unittest"), 160 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.tags.2058715988", "source:consul"), 161 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3333874791.type", "text"), 162 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.active", "true"), 163 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.name", "LastContact"), 164 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.#", "2"), 165 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.1401442048", "lifecycle:unittest"), 166 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.tags.2058715988", "source:consul"), 167 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.type", "numeric"), 168 resource.TestCheckResourceAttr("circonus_check.consul_server", "metric.3148913305.unit", "seconds"), 169 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.#", "2"), 170 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.1401442048", "lifecycle:unittest"), 171 resource.TestCheckResourceAttr("circonus_check.consul_server", "tags.2058715988", "source:consul"), 172 resource.TestCheckResourceAttr("circonus_check.consul_server", "target", "consul.service.consul"), 173 resource.TestCheckResourceAttr("circonus_check.consul_server", "type", "consul"), 174 ), 175 }, 176 }, 177 }) 178 } 179 180 const testAccCirconusCheckConsulConfigV1HealthNodeFmt = ` 181 resource "circonus_check" "consul_server" { 182 active = true 183 name = "%s" 184 period = "60s" 185 186 collector { 187 id = "/broker/2110" 188 } 189 190 consul { 191 dc = "dc2" 192 http_addr = "http://consul.service.consul:8501" 193 node = "%s" 194 node_blacklist = ["a","bad","node"] 195 } 196 197 metric { 198 name = "LastContact" 199 tags = [ "source:consul", "lifecycle:unittest" ] 200 type = "numeric" 201 unit = "seconds" 202 } 203 204 metric { 205 name = "KnownLeader" 206 tags = [ "source:consul", "lifecycle:unittest" ] 207 type = "text" 208 } 209 210 tags = [ "source:consul", "lifecycle:unittest" ] 211 212 target = "consul.service.consul" 213 } 214 ` 215 216 const testAccCirconusCheckConsulConfigV1HealthServiceFmt = ` 217 resource "circonus_check" "consul_server" { 218 active = true 219 name = "%s" 220 period = "60s" 221 222 collector { 223 id = "/broker/2110" 224 } 225 226 consul { 227 service = "consul" 228 service_blacklist = ["bad","hombre","service"] 229 } 230 231 metric { 232 name = "LastContact" 233 tags = [ "source:consul", "lifecycle:unittest" ] 234 type = "numeric" 235 unit = "seconds" 236 } 237 238 metric { 239 name = "KnownLeader" 240 tags = [ "source:consul", "lifecycle:unittest" ] 241 type = "text" 242 } 243 244 tags = [ "source:consul", "lifecycle:unittest" ] 245 246 target = "consul.service.consul" 247 } 248 ` 249 250 const testAccCirconusCheckConsulConfigV1HealthStateFmt = ` 251 resource "circonus_check" "consul_server" { 252 active = true 253 name = "%s" 254 period = "60s" 255 256 collector { 257 id = "/broker/2110" 258 } 259 260 consul { 261 state = "%s" 262 check_blacklist = ["worthless","check"] 263 } 264 265 metric { 266 name = "LastContact" 267 tags = [ "source:consul", "lifecycle:unittest" ] 268 type = "numeric" 269 unit = "seconds" 270 } 271 272 metric { 273 name = "KnownLeader" 274 tags = [ "source:consul", "lifecycle:unittest" ] 275 type = "text" 276 } 277 278 tags = [ "source:consul", "lifecycle:unittest" ] 279 280 target = "consul.service.consul" 281 } 282 `