Repository navigation
Expand file tree
/
Copy pathresource_artifact_test.go
More file actions
150 lines (134 loc) · 3.48 KB
/
Copy pathresource_artifact_test.go
File metadata and controls
150 lines (134 loc) · 3.48 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
package atlas
import (
"fmt"
"testing"
"github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform"
)
func TestAccArtifact_basic(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccArtifact_basic,
Check: resource.ComposeTestCheckFunc(
testAccCheckArtifactState("name", "hashicorp/tf-provider-test"),
),
},
},
})
}
func TestAccArtifact_metadata(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccArtifact_metadata,
Check: resource.ComposeTestCheckFunc(
testAccCheckArtifactState("name", "hashicorp/tf-provider-test"),
testAccCheckArtifactState("id", "x86"),
testAccCheckArtifactState("metadata_full.arch", "x86"),
),
},
},
})
}
func TestAccArtifact_metadataSet(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccArtifact_metadataSet,
Check: resource.ComposeTestCheckFunc(
testAccCheckArtifactState("name", "hashicorp/tf-provider-test"),
testAccCheckArtifactState("id", "x64"),
testAccCheckArtifactState("metadata_full.arch", "x64"),
),
},
},
})
}
func TestAccArtifact_buildLatest(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccArtifact_buildLatest,
Check: resource.ComposeTestCheckFunc(
testAccCheckArtifactState("name", "hashicorp/tf-provider-test"),
),
},
},
})
}
func TestAccArtifact_versionAny(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccArtifact_versionAny,
Check: resource.ComposeTestCheckFunc(
testAccCheckArtifactState("name", "hashicorp/tf-provider-test"),
),
},
},
})
}
func testAccCheckArtifactState(key, value string) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources["atlas_artifact.foobar"]
if !ok {
return fmt.Errorf("Not found: %s", "atlas_artifact.foobar")
}
if rs.Primary.ID == "" {
return fmt.Errorf("No ID is set")
}
p := rs.Primary
if p.Attributes[key] != value {
return fmt.Errorf(
"%s != %s (actual: %s)", key, value, p.Attributes[key])
}
return nil
}
}
const testAccArtifact_basic = `
resource "atlas_artifact" "foobar" {
name = "hashicorp/tf-provider-test"
type = "foo"
}`
const testAccArtifact_metadata = `
resource "atlas_artifact" "foobar" {
name = "hashicorp/tf-provider-test"
type = "foo"
metadata {
arch = "x86"
}
version = "any"
}`
const testAccArtifact_metadataSet = `
resource "atlas_artifact" "foobar" {
name = "hashicorp/tf-provider-test"
type = "foo"
metadata_keys = ["arch"]
version = "any"
}`
const testAccArtifact_buildLatest = `
resource "atlas_artifact" "foobar" {
name = "hashicorp/tf-provider-test"
type = "foo"
build = "latest"
metadata {
arch = "x86"
}
}`
const testAccArtifact_versionAny = `
resource "atlas_artifact" "foobar" {
name = "hashicorp/tf-provider-test"
type = "foo"
version = "any"
}`