github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_statsd_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 TestAccCirconusCheckStatsd_basic(t *testing.T) {
    12  	checkName := fmt.Sprintf("statsd test 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(testAccCirconusCheckStatsdConfigFmt, checkName),
    21  				Check: resource.ComposeTestCheckFunc(
    22  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "active", "true"),
    23  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "collector.#", "1"),
    24  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "collector.2084916526.id", "/broker/2110"),
    25  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "statsd.#", "1"),
    26  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "statsd.3733287963.source_ip", `127.0.0.2`),
    27  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "name", checkName),
    28  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "period", "60s"),
    29  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "metric.#", "1"),
    30  
    31  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "tags.#", "4"),
    32  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "tags.3728194417", "app:consul"),
    33  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "tags.2087084518", "author:terraform"),
    34  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "tags.1401442048", "lifecycle:unittest"),
    35  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "tags.2812916752", "source:statsd"),
    36  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "target", "127.0.0.2"),
    37  					resource.TestCheckResourceAttr("circonus_check.statsd_dump", "type", "statsd"),
    38  				),
    39  			},
    40  		},
    41  	})
    42  }
    43  
    44  const testAccCirconusCheckStatsdConfigFmt = `
    45  variable "test_tags" {
    46    type = "list"
    47    default = [ "app:consul", "author:terraform", "lifecycle:unittest", "source:statsd" ]
    48  }
    49  
    50  resource "circonus_check" "statsd_dump" {
    51    active = true
    52    name = "%s"
    53    period = "60s"
    54  
    55    collector {
    56      id = "/broker/2110"
    57    }
    58  
    59    statsd {
    60      source_ip = "127.0.0.2"
    61    }
    62  
    63    metric {
    64      name = "rando_metric"
    65      tags = [ "${var.test_tags}" ]
    66      type = "histogram"
    67    }
    68  
    69    tags = [ "${var.test_tags}" ]
    70  }
    71  `