github.com/lymingtonprecision/terraform@v0.9.9-0.20170613092852-62acef9611a9/builtin/providers/test/data_source_label_test.go (about)

     1  package test
     2  
     3  import (
     4  	"errors"
     5  	"fmt"
     6  	"strings"
     7  	"testing"
     8  
     9  	"github.com/hashicorp/terraform/helper/resource"
    10  	"github.com/hashicorp/terraform/terraform"
    11  )
    12  
    13  func TestProviderLabelDataSource(t *testing.T) {
    14  	resource.UnitTest(t, resource.TestCase{
    15  		Providers: testAccProviders,
    16  		CheckDestroy: func(s *terraform.State) error {
    17  			return nil
    18  		},
    19  		Steps: []resource.TestStep{
    20  			{
    21  				Config: strings.TrimSpace(`
    22  provider "test" {
    23    label = "foo"
    24  }
    25  
    26  data "test_provider_label" "test" {
    27  }
    28  				`),
    29  				Check: func(s *terraform.State) error {
    30  					res, hasRes := s.RootModule().Resources["data.test_provider_label.test"]
    31  					if !hasRes {
    32  						return errors.New("No test_provider_label in state")
    33  					}
    34  					if got, want := res.Primary.ID, "foo"; got != want {
    35  						return fmt.Errorf("wrong id %q; want %q", got, want)
    36  					}
    37  					if got, want := res.Primary.Attributes["label"], "foo"; got != want {
    38  						return fmt.Errorf("wrong id %q; want %q", got, want)
    39  					}
    40  					return nil
    41  				},
    42  			},
    43  		},
    44  	})
    45  }