github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_httptrap_test.go (about)

     1  package circonus
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/acctest"
     8  	"github.com/hashicorp/terraform/helper/resource"
     9  )
    10  
    11  func TestAccCirconusCheckHTTPTrap_basic(t *testing.T) {
    12  	checkName := fmt.Sprintf("Terraform test: consul server httptrap check- %s", acctest.RandString(5))
    13  
    14  	resource.Test(t, resource.TestCase{
    15  		PreCheck:     func() { testAccPreCheck(t) },
    16  		Providers:    testAccProviders,
    17  		CheckDestroy: testAccCheckDestroyCirconusCheckBundle,
    18  		Steps: []resource.TestStep{
    19  			{
    20  				Config: fmt.Sprintf(testAccCirconusCheckHTTPTrapConfigFmt, checkName),
    21  				Check: resource.ComposeTestCheckFunc(
    22  					resource.TestCheckResourceAttr("circonus_check.consul", "active", "true"),
    23  					resource.TestCheckResourceAttr("circonus_check.consul", "collector.#", "1"),
    24  					resource.TestCheckResourceAttr("circonus_check.consul", "collector.2084916526.id", "/broker/2110"),
    25  					resource.TestCheckResourceAttr("circonus_check.consul", "httptrap.#", "1"),
    26  					resource.TestCheckResourceAttr("circonus_check.consul", "httptrap.2067899660.async_metrics", "false"),
    27  					resource.TestCheckResourceAttr("circonus_check.consul", "httptrap.2067899660.secret", "12345"),
    28  					resource.TestCheckResourceAttr("circonus_check.consul", "name", checkName),
    29  					resource.TestCheckResourceAttr("circonus_check.consul", "notes", "Check to receive consul server telemetry"),
    30  					resource.TestCheckResourceAttr("circonus_check.consul", "period", "60s"),
    31  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.#", "3"),
    32  
    33  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.active", "true"),
    34  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.name", "consul`consul-server-10-151-2-8`consul`session_ttl`active"),
    35  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.tags.#", "3"),
    36  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.tags.3728194417", "app:consul"),
    37  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.tags.1401442048", "lifecycle:unittest"),
    38  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.tags.2058715988", "source:consul"),
    39  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.1608647530.type", "numeric"),
    40  
    41  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.active", "true"),
    42  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.name", "consul`consul-server-10-151-2-8`runtime`alloc_bytes"),
    43  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.tags.#", "3"),
    44  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.tags.3728194417", "app:consul"),
    45  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.tags.1401442048", "lifecycle:unittest"),
    46  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.tags.2058715988", "source:consul"),
    47  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.type", "numeric"),
    48  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2293914935.unit", "bytes"),
    49  
    50  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.active", "true"),
    51  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.name", "consul`consul`http`GET`v1`kv`_"),
    52  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.tags.#", "3"),
    53  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.tags.3728194417", "app:consul"),
    54  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.tags.1401442048", "lifecycle:unittest"),
    55  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.tags.2058715988", "source:consul"),
    56  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.type", "histogram"),
    57  					resource.TestCheckResourceAttr("circonus_check.consul", "metric.2489694876.unit", "nanoseconds"),
    58  
    59  					resource.TestCheckResourceAttr("circonus_check.consul", "tags.#", "3"),
    60  					resource.TestCheckResourceAttr("circonus_check.consul", "tags.3728194417", "app:consul"),
    61  					resource.TestCheckResourceAttr("circonus_check.consul", "tags.1401442048", "lifecycle:unittest"),
    62  					resource.TestCheckResourceAttr("circonus_check.consul", "tags.2058715988", "source:consul"),
    63  					resource.TestCheckResourceAttr("circonus_check.consul", "target", "consul-server-10-151-2-8"),
    64  					resource.TestCheckResourceAttr("circonus_check.consul", "type", "httptrap"),
    65  				),
    66  			},
    67  		},
    68  	})
    69  }
    70  
    71  const testAccCirconusCheckHTTPTrapConfigFmt = `
    72  variable "httptrap_check_tags" {
    73    type = "list"
    74    default = [ "app:consul", "lifecycle:unittest", "source:consul" ]
    75  }
    76  
    77  variable "consul_hostname" {
    78    type = "string"
    79    default = "consul-server-10-151-2-8"
    80  }
    81  
    82  resource "circonus_check" "consul" {
    83    active = true
    84    name = "%s"
    85    notes = "Check to receive consul server telemetry"
    86    period = "60s"
    87  
    88    collector {
    89      id = "/broker/2110"
    90    }
    91  
    92    httptrap {
    93      async_metrics = "false"
    94      secret = "12345"
    95    }
    96  
    97    metric {
    98      name = "consul` + "`" + `${var.consul_hostname}` + "`" + `consul` + "`" + `session_ttl` + "`" + `active"
    99      tags = [ "${var.httptrap_check_tags}" ]
   100      type = "numeric"
   101    }
   102  
   103    metric {
   104      name = "consul` + "`" + `${var.consul_hostname}` + "`" + `runtime` + "`" + `alloc_bytes"
   105      tags = [ "${var.httptrap_check_tags}" ]
   106      type = "numeric"
   107      unit = "bytes"
   108    }
   109  
   110    metric {
   111      name = "consul` + "`" + `consul` + "`" + `http` + "`" + `GET` + "`" + `v1` + "`" + `kv` + "`" + `_"
   112      tags = [ "${var.httptrap_check_tags}" ]
   113      type = "histogram"
   114      unit = "nanoseconds"
   115    }
   116  
   117    tags = [ "${var.httptrap_check_tags}" ]
   118    target = "${var.consul_hostname}"
   119  }
   120  `