github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_caql_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 TestAccCirconusCheckCAQL_basic(t *testing.T) {
    12  	checkName := fmt.Sprintf("Consul's Go GC latency (Merged Histogram) - %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(testAccCirconusCheckCAQLConfigFmt, checkName),
    21  				Check: resource.ComposeTestCheckFunc(
    22  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "active", "true"),
    23  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "collector.#", "1"),
    24  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "collector.36214388.id", "/broker/1490"),
    25  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "caql.#", "1"),
    26  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "caql.4060628048.query", `search:metric:histogram("*consul*runtime`+"`"+`gc_pause_ns* (active:1)") | histogram:merge() | histogram:percentile(99)`),
    27  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "name", checkName),
    28  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "period", "60s"),
    29  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "metric.#", "1"),
    30  
    31  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "tags.#", "4"),
    32  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "tags.3728194417", "app:consul"),
    33  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "tags.2087084518", "author:terraform"),
    34  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "tags.1401442048", "lifecycle:unittest"),
    35  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "tags.3480593708", "source:goruntime"),
    36  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "target", "q._caql"),
    37  					resource.TestCheckResourceAttr("circonus_check.go_gc_latency", "type", "caql"),
    38  				),
    39  			},
    40  		},
    41  	})
    42  }
    43  
    44  const testAccCirconusCheckCAQLConfigFmt = `
    45  variable "test_tags" {
    46    type = "list"
    47    default = [ "app:consul", "author:terraform", "lifecycle:unittest", "source:goruntime" ]
    48  }
    49  
    50  resource "circonus_check" "go_gc_latency" {
    51    active = true
    52    name = "%s"
    53    period = "60s"
    54  
    55    collector {
    56      id = "/broker/1490"
    57    }
    58  
    59    caql {
    60      query = <<EOF
    61  search:metric:histogram("*consul*runtime` + "`" + `gc_pause_ns* (active:1)") | histogram:merge() | histogram:percentile(99)
    62  EOF
    63    }
    64  
    65    metric {
    66      name = "output[1]"
    67      tags = [ "${var.test_tags}" ]
    68      type = "histogram"
    69      unit = "seconds"
    70    }
    71  
    72    tags = [ "${var.test_tags}" ]
    73  }
    74  `