github.com/vtorhonen/terraform@v0.9.0-beta2.0.20170307220345-5d894e4ffda7/builtin/providers/atlas/resource_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 TestAccArtifact_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: testAccArtifact_basic, 18 Check: resource.ComposeTestCheckFunc( 19 testAccCheckArtifactState("name", "hashicorp/tf-provider-test"), 20 ), 21 }, 22 }, 23 }) 24 } 25 26 func TestAccArtifact_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: testAccArtifact_metadata, 33 Check: resource.ComposeTestCheckFunc( 34 testAccCheckArtifactState("name", "hashicorp/tf-provider-test"), 35 testAccCheckArtifactState("id", "x86"), 36 testAccCheckArtifactState("metadata_full.arch", "x86"), 37 ), 38 }, 39 }, 40 }) 41 } 42 43 func TestAccArtifact_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: testAccArtifact_metadataSet, 50 Check: resource.ComposeTestCheckFunc( 51 testAccCheckArtifactState("name", "hashicorp/tf-provider-test"), 52 testAccCheckArtifactState("id", "x64"), 53 testAccCheckArtifactState("metadata_full.arch", "x64"), 54 ), 55 }, 56 }, 57 }) 58 } 59 60 func TestAccArtifact_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: testAccArtifact_buildLatest, 67 Check: resource.ComposeTestCheckFunc( 68 testAccCheckArtifactState("name", "hashicorp/tf-provider-test"), 69 ), 70 }, 71 }, 72 }) 73 } 74 75 func TestAccArtifact_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: testAccArtifact_versionAny, 82 Check: resource.ComposeTestCheckFunc( 83 testAccCheckArtifactState("name", "hashicorp/tf-provider-test"), 84 ), 85 }, 86 }, 87 }) 88 } 89 90 func testAccCheckArtifactState(key, value string) resource.TestCheckFunc { 91 return func(s *terraform.State) error { 92 rs, ok := s.RootModule().Resources["atlas_artifact.foobar"] 93 if !ok { 94 return fmt.Errorf("Not found: %s", "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 testAccArtifact_basic = ` 112 resource "atlas_artifact" "foobar" { 113 name = "hashicorp/tf-provider-test" 114 type = "foo" 115 }` 116 117 const testAccArtifact_metadata = ` 118 resource "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 testAccArtifact_metadataSet = ` 128 resource "atlas_artifact" "foobar" { 129 name = "hashicorp/tf-provider-test" 130 type = "foo" 131 metadata_keys = ["arch"] 132 version = "any" 133 }` 134 135 const testAccArtifact_buildLatest = ` 136 resource "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 testAccArtifact_versionAny = ` 146 resource "atlas_artifact" "foobar" { 147 name = "hashicorp/tf-provider-test" 148 type = "foo" 149 version = "any" 150 }`