github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/circonus/resource_circonus_check_mysql_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 TestAccCirconusCheckMySQL_basic(t *testing.T) { 12 checkName := fmt.Sprintf("MySQL binlog total - %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(testAccCirconusCheckMySQLConfigFmt, checkName), 21 Check: resource.ComposeTestCheckFunc( 22 resource.TestCheckResourceAttr("circonus_check.table_ops", "active", "true"), 23 resource.TestCheckResourceAttr("circonus_check.table_ops", "collector.#", "1"), 24 resource.TestCheckResourceAttr("circonus_check.table_ops", "collector.2388330941.id", "/broker/1"), 25 resource.TestCheckResourceAttr("circonus_check.table_ops", "mysql.#", "1"), 26 resource.TestCheckResourceAttr("circonus_check.table_ops", "mysql.3110376931.dsn", "user=mysql host=mydb1.example.org port=3306 password=12345 sslmode=require"), 27 resource.TestCheckResourceAttr("circonus_check.table_ops", "mysql.3110376931.query", `select 'binlog', total from (select variable_value as total from information_schema.global_status where variable_name='BINLOG_CACHE_USE') total`), 28 resource.TestCheckResourceAttr("circonus_check.table_ops", "name", checkName), 29 resource.TestCheckResourceAttr("circonus_check.table_ops", "period", "300s"), 30 resource.TestCheckResourceAttr("circonus_check.table_ops", "metric.#", "1"), 31 32 resource.TestCheckResourceAttr("circonus_check.table_ops", "metric.885029470.name", "binlog`total"), 33 resource.TestCheckResourceAttr("circonus_check.table_ops", "metric.885029470.tags.#", "2"), 34 resource.TestCheckResourceAttr("circonus_check.table_ops", "metric.885029470.tags.2087084518", "author:terraform"), 35 resource.TestCheckResourceAttr("circonus_check.table_ops", "metric.885029470.tags.1401442048", "lifecycle:unittest"), 36 resource.TestCheckResourceAttr("circonus_check.table_ops", "metric.885029470.type", "numeric"), 37 38 resource.TestCheckResourceAttr("circonus_check.table_ops", "tags.#", "2"), 39 resource.TestCheckResourceAttr("circonus_check.table_ops", "tags.2087084518", "author:terraform"), 40 resource.TestCheckResourceAttr("circonus_check.table_ops", "tags.1401442048", "lifecycle:unittest"), 41 resource.TestCheckResourceAttr("circonus_check.table_ops", "target", "mydb.example.org"), 42 resource.TestCheckResourceAttr("circonus_check.table_ops", "type", "mysql"), 43 ), 44 }, 45 }, 46 }) 47 } 48 49 const testAccCirconusCheckMySQLConfigFmt = ` 50 variable "test_tags" { 51 type = "list" 52 default = [ "author:terraform", "lifecycle:unittest" ] 53 } 54 55 resource "circonus_check" "table_ops" { 56 active = true 57 name = "%s" 58 period = "300s" 59 60 collector { 61 id = "/broker/1" 62 } 63 64 mysql { 65 dsn = "user=mysql host=mydb1.example.org port=3306 password=12345 sslmode=require" 66 query = <<EOF 67 select 'binlog', total from (select variable_value as total from information_schema.global_status where variable_name='BINLOG_CACHE_USE') total 68 EOF 69 } 70 71 metric { 72 name = "binlog` + "`" + `total" 73 tags = [ "${var.test_tags}" ] 74 type = "numeric" 75 } 76 77 tags = [ "${var.test_tags}" ] 78 target = "mydb.example.org" 79 } 80 `