github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/atlas/data_source_artifact_test.go (about) 1 package atlas 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 TestAccDataSourceArtifact_basic(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: testAccDataArtifact_basic, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckDataArtifactState("name", "hashicorp/tf-provider-test"), 20 ), 21 }, 22 }, 23 }) 24 } 25 26 func TestAccDataSourceArtifact_metadata(t *testing.T) { 27 resource.Test(t, resource.TestCase{ 28 PreCheck: func() { testAccPreCheck(t) }, 29 Providers: testAccProviders, 30 Steps: []resource.TestStep{ 31 resource.TestStep{ 32 Config: testAccDataArtifact_metadata, 33 Check: resource.ComposeTestCheckFunc( 34 testAccCheckDataArtifactState("name", "hashicorp/tf-provider-test"), 35 testAccCheckDataArtifactState("id", "x86"), 36 testAccCheckDataArtifactState("metadata_full.arch", "x86"), 37 ), 38 }, 39 }, 40 }) 41 } 42 43 func TestAccDataSourceArtifact_metadataSet(t *testing.T) { 44 resource.Test(t, resource.TestCase{ 45 PreCheck: func() { testAccPreCheck(t) }, 46 Providers: testAccProviders, 47 Steps: []resource.TestStep{ 48 resource.TestStep{ 49 Config: testAccDataArtifact_metadataSet, 50 Check: resource.ComposeTestCheckFunc( 51 testAccCheckDataArtifactState("name", "hashicorp/tf-provider-test"), 52 testAccCheckDataArtifactState("id", "x64"), 53 testAccCheckDataArtifactState("metadata_full.arch", "x64"), 54 ), 55 }, 56 }, 57 }) 58 } 59 60 func TestAccDataSourceArtifact_buildLatest(t *testing.T) { 61 resource.Test(t, resource.TestCase{ 62 PreCheck: func() { testAccPreCheck(t) }, 63 Providers: testAccProviders, 64 Steps: []resource.TestStep{ 65 resource.TestStep{ 66 Config: testAccDataArtifact_buildLatest, 67 Check: resource.ComposeTestCheckFunc( 68 testAccCheckDataArtifactState("name", "hashicorp/tf-provider-test"), 69 ), 70 }, 71 }, 72 }) 73 } 74 75 func TestAccDataSourceArtifact_versionAny(t *testing.T) { 76 resource.Test(t, resource.TestCase{ 77 PreCheck: func() { testAccPreCheck(t) }, 78 Providers: testAccProviders, 79 Steps: []resource.TestStep{ 80 resource.TestStep{ 81 Config: testAccDataArtifact_versionAny, 82 Check: resource.ComposeTestCheckFunc( 83 testAccCheckDataArtifactState("name", "hashicorp/tf-provider-test"), 84 ), 85 }, 86 }, 87 }) 88 } 89 90 func testAccCheckDataArtifactState(key, value string) resource.TestCheckFunc { 91 return func(s *terraform.State) error { 92 rs, ok := s.RootModule().Resources["data.atlas_artifact.foobar"] 93 if !ok { 94 return fmt.Errorf("Not found: %s", "data.atlas_artifact.foobar") 95 } 96 97 if rs.Primary.ID == "" { 98 return fmt.Errorf("No ID is set") 99 } 100 101 p := rs.Primary 102 if p.Attributes[key] != value { 103 return fmt.Errorf( 104 "%s != %s (actual: %s)", key, value, p.Attributes[key]) 105 } 106 107 return nil 108 } 109 } 110 111 const testAccDataArtifact_basic = ` 112 data "atlas_artifact" "foobar" { 113 name = "hashicorp/tf-provider-test" 114 type = "foo" 115 }` 116 117 const testAccDataArtifact_metadata = ` 118 data "atlas_artifact" "foobar" { 119 name = "hashicorp/tf-provider-test" 120 type = "foo" 121 metadata { 122 arch = "x86" 123 } 124 version = "any" 125 }` 126 127 const testAccDataArtifact_metadataSet = ` 128 data "atlas_artifact" "foobar" { 129 name = "hashicorp/tf-provider-test" 130 type = "foo" 131 metadata_keys = ["arch"] 132 version = "any" 133 }` 134 135 const testAccDataArtifact_buildLatest = ` 136 data "atlas_artifact" "foobar" { 137 name = "hashicorp/tf-provider-test" 138 type = "foo" 139 build = "latest" 140 metadata { 141 arch = "x86" 142 } 143 }` 144 145 const testAccDataArtifact_versionAny = ` 146 data "atlas_artifact" "foobar" { 147 name = "hashicorp/tf-provider-test" 148 type = "foo" 149 version = "any" 150 }`