github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_icmp_ping_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 TestAccCirconusCheckICMPPing_basic(t *testing.T) {
    14  	checkName := fmt.Sprintf("ICMP Ping check - %s", acctest.RandString(5))
    15  
    16  	resource.Test(t, resource.TestCase{
    17  		PreCheck:     func() { testAccPreCheck(t) },
    18  		Providers:    testAccProviders,
    19  		CheckDestroy: testAccCheckDestroyCirconusCheckBundle,
    20  		Steps: []resource.TestStep{
    21  			{
    22  				Config: fmt.Sprintf(testAccCirconusCheckICMPPingConfigFmt, checkName),
    23  				Check: resource.ComposeTestCheckFunc(
    24  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "active", "true"),
    25  					resource.TestCheckNoResourceAttr("circonus_check.loopback_latency", "check_id"),
    26  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "checks.#", "2"),
    27  					resource.TestMatchResourceAttr("circonus_check.loopback_latency", "checks.0", regexp.MustCompile(config.CheckCIDRegex)),
    28  					resource.TestMatchResourceAttr("circonus_check.loopback_latency", "checks.1", regexp.MustCompile(config.CheckCIDRegex)),
    29  					resource.TestCheckNoResourceAttr("circonus_check.loopback_latency", "check_id"),
    30  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "check_by_collector.%", "2"),
    31  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "collector.#", "2"),
    32  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "collector.2388330941.id", "/broker/1"),
    33  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "icmp_ping.#", "1"),
    34  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "icmp_ping.979664239.availability", "100"),
    35  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "icmp_ping.979664239.count", "5"),
    36  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "icmp_ping.979664239.interval", "500ms"),
    37  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "name", checkName),
    38  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "period", "300s"),
    39  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.#", "5"),
    40  
    41  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.784357201.name", "available"),
    42  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.784357201.tags.#", "2"),
    43  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.784357201.tags.2087084518", "author:terraform"),
    44  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.784357201.tags.1401442048", "lifecycle:unittest"),
    45  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.784357201.type", "numeric"),
    46  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.784357201.unit", "%"),
    47  
    48  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.3166992875.name", "average"),
    49  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.3166992875.tags.#", "2"),
    50  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.3166992875.tags.2087084518", "author:terraform"),
    51  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.3166992875.tags.1401442048", "lifecycle:unittest"),
    52  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.3166992875.type", "numeric"),
    53  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.3166992875.unit", "seconds"),
    54  
    55  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.809361245.name", "count"),
    56  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.809361245.tags.#", "2"),
    57  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.809361245.tags.2087084518", "author:terraform"),
    58  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.809361245.tags.1401442048", "lifecycle:unittest"),
    59  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.809361245.type", "numeric"),
    60  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.809361245.unit", "packets"),
    61  
    62  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.839816201.name", "maximum"),
    63  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.839816201.tags.#", "2"),
    64  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.839816201.tags.2087084518", "author:terraform"),
    65  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.839816201.tags.1401442048", "lifecycle:unittest"),
    66  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.839816201.type", "numeric"),
    67  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.839816201.unit", "seconds"),
    68  
    69  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.1657693034.name", "minimum"),
    70  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.1657693034.tags.#", "2"),
    71  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.1657693034.tags.2087084518", "author:terraform"),
    72  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.1657693034.tags.1401442048", "lifecycle:unittest"),
    73  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.1657693034.type", "numeric"),
    74  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "metric.1657693034.unit", "seconds"),
    75  
    76  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "tags.#", "2"),
    77  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "tags.2087084518", "author:terraform"),
    78  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "tags.1401442048", "lifecycle:unittest"),
    79  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "target", "api.circonus.com"),
    80  					resource.TestCheckResourceAttr("circonus_check.loopback_latency", "type", "ping_icmp"),
    81  				),
    82  			},
    83  		},
    84  	})
    85  }
    86  
    87  const testAccCirconusCheckICMPPingConfigFmt = `
    88  variable "test_tags" {
    89    type = "list"
    90    default = [ "author:terraform", "lifecycle:unittest" ]
    91  }
    92  resource "circonus_check" "loopback_latency" {
    93    active = true
    94    name = "%s"
    95    period = "300s"
    96  
    97    collector {
    98      id = "/broker/1"
    99    }
   100  
   101    collector {
   102      id = "/broker/275"
   103    }
   104  
   105    icmp_ping {
   106      availability = "100.0"
   107      count = 5
   108      interval = "500ms"
   109    }
   110  
   111    metric {
   112      name = "available"
   113      tags = [ "${var.test_tags}" ]
   114      type = "numeric"
   115      unit = "%%"
   116    }
   117  
   118    metric {
   119      name = "average"
   120      tags = [ "${var.test_tags}" ]
   121      type = "numeric"
   122      unit = "seconds"
   123    }
   124  
   125    metric {
   126      name = "count"
   127      tags = [ "${var.test_tags}" ]
   128      type = "numeric"
   129      unit = "packets"
   130    }
   131  
   132    metric {
   133      name = "maximum"
   134      tags = [ "${var.test_tags}" ]
   135      type = "numeric"
   136      unit = "seconds"
   137    }
   138  
   139    metric {
   140      name = "minimum"
   141      tags = [ "${var.test_tags}" ]
   142      type = "numeric"
   143      unit = "seconds"
   144    }
   145  
   146    tags = [ "${var.test_tags}" ]
   147    target = "api.circonus.com"
   148  }
   149  `