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

     1  package circonus
     2  
     3  import (
     4  	"fmt"
     5  	"testing"
     6  
     7  	"github.com/hashicorp/terraform/helper/resource"
     8  	"github.com/hashicorp/terraform/terraform"
     9  )
    10  
    11  func TestAccDataSourceCirconusCollector(t *testing.T) {
    12  	resource.Test(t, resource.TestCase{
    13  		PreCheck:  func() { testAccPreCheck(t) },
    14  		Providers: testAccProviders,
    15  		Steps: []resource.TestStep{
    16  			resource.TestStep{
    17  				Config: testAccDataSourceCirconusCollectorConfig,
    18  				Check: resource.ComposeTestCheckFunc(
    19  					testAccDataSourceCirconusCollectorCheck("data.circonus_collector.by_id", "/broker/1"),
    20  				),
    21  			},
    22  		},
    23  	})
    24  }
    25  
    26  func testAccDataSourceCirconusCollectorCheck(name, cid string) resource.TestCheckFunc {
    27  	return func(s *terraform.State) error {
    28  		rs, ok := s.RootModule().Resources[name]
    29  		if !ok {
    30  			return fmt.Errorf("root module has no resource called %s", name)
    31  		}
    32  
    33  		attr := rs.Primary.Attributes
    34  
    35  		if attr[collectorIDAttr] != cid {
    36  			return fmt.Errorf("bad id %s", attr[collectorIDAttr])
    37  		}
    38  
    39  		return nil
    40  	}
    41  }
    42  
    43  const testAccDataSourceCirconusCollectorConfig = `
    44  data "circonus_collector" "by_id" {
    45    id = "/broker/1"
    46  }
    47  `