@@ -17,13 +17,13 @@ func TestAccArchiveFile_Basic(t *testing.T) {
17
17
f := filepath .Join (td , "zip_file_acc_test.zip" )
18
18
19
19
var fileSize string
20
- r .Test (t , r.TestCase {
20
+ r .ParallelTest (t , r.TestCase {
21
21
ProtoV5ProviderFactories : protoV5ProviderFactories (),
22
22
Steps : []r.TestStep {
23
23
{
24
24
Config : testAccArchiveFileContentConfig (f ),
25
25
Check : r .ComposeTestCheckFunc (
26
- testAccArchiveFileExists (f , & fileSize ),
26
+ testAccArchiveFileSize (f , & fileSize ),
27
27
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
28
28
r .TestCheckResourceAttr (
29
29
"data.archive_file.foo" , "output_base64sha256" , "P7VckxoEiUO411WN3nwuS/yOBL4zsbVWkQU9E1I5H6c=" ,
@@ -39,7 +39,7 @@ func TestAccArchiveFile_Basic(t *testing.T) {
39
39
{
40
40
Config : testAccArchiveFileFileConfig (f ),
41
41
Check : r .ComposeTestCheckFunc (
42
- testAccArchiveFileExists (f , & fileSize ),
42
+ testAccArchiveFileSize (f , & fileSize ),
43
43
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
44
44
r .TestCheckResourceAttr (
45
45
"data.archive_file.foo" , "output_base64sha256" , "UTE4f5cWfaR6p0HfOrLILxgvF8UUwiJTjTRwjQTgdWs=" ,
@@ -55,7 +55,7 @@ func TestAccArchiveFile_Basic(t *testing.T) {
55
55
{
56
56
Config : testAccArchiveFileDirConfig (f ),
57
57
Check : r .ComposeTestCheckFunc (
58
- testAccArchiveFileExists (f , & fileSize ),
58
+ testAccArchiveFileSize (f , & fileSize ),
59
59
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
60
60
r .TestCheckResourceAttr (
61
61
"data.archive_file.foo" , "output_base64sha256" , "ydB8wtq8nK9vQ77VH6YTwoHmyljK46jW+uIJSwCzNpo=" ,
@@ -71,22 +71,250 @@ func TestAccArchiveFile_Basic(t *testing.T) {
71
71
{
72
72
Config : testAccArchiveFileDirExcludesConfig (f ),
73
73
Check : r .ComposeTestCheckFunc (
74
- testAccArchiveFileExists (f , & fileSize ),
74
+ testAccArchiveFileSize (f , & fileSize ),
75
75
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
76
76
),
77
77
},
78
78
{
79
- Config : testAccArchiveFileMultiConfig (f ),
79
+ Config : testAccArchiveFileMultiSourceConfig (f ),
80
80
Check : r .ComposeTestCheckFunc (
81
- testAccArchiveFileExists (f , & fileSize ),
81
+ testAccArchiveFileSize (f , & fileSize ),
82
82
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
83
83
),
84
84
},
85
85
},
86
86
})
87
87
}
88
88
89
- func testAccArchiveFileExists (filename string , fileSize * string ) r.TestCheckFunc {
89
+ func TestDataSource_UpgradeFromVersion2_2_0_ContentConfig (t * testing.T ) {
90
+ td := testTempDir (t )
91
+ defer os .RemoveAll (td )
92
+
93
+ f := filepath .Join (td , "zip_file_acc_test_upgrade_content_config.zip" )
94
+
95
+ var fileSize string
96
+
97
+ r .ParallelTest (t , r.TestCase {
98
+ Steps : []r.TestStep {
99
+ {
100
+ ExternalProviders : map [string ]r.ExternalProvider {
101
+ "archive" : {
102
+ VersionConstraint : "2.2.0" ,
103
+ Source : "hashicorp/archive" ,
104
+ },
105
+ },
106
+ Config : testAccArchiveFileContentConfig (f ),
107
+ Check : r .ComposeTestCheckFunc (
108
+ testAccArchiveFileSize (f , & fileSize ),
109
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
110
+ r .TestCheckResourceAttr (
111
+ "data.archive_file.foo" , "output_base64sha256" , "P7VckxoEiUO411WN3nwuS/yOBL4zsbVWkQU9E1I5H6c=" ,
112
+ ),
113
+ r .TestCheckResourceAttr (
114
+ "data.archive_file.foo" , "output_md5" , "ea35f0444ea9a3d5641d8760bc2815cc" ,
115
+ ),
116
+ r .TestCheckResourceAttr (
117
+ "data.archive_file.foo" , "output_sha" , "019c79c4dc14dbe1edb3e467b2de6a6aad148717" ,
118
+ ),
119
+ ),
120
+ },
121
+ {
122
+ ProtoV5ProviderFactories : protoV5ProviderFactories (),
123
+ Config : testAccArchiveFileContentConfig (f ),
124
+ Check : r .ComposeTestCheckFunc (
125
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
126
+ r .TestCheckResourceAttr (
127
+ "data.archive_file.foo" , "output_base64sha256" , "P7VckxoEiUO411WN3nwuS/yOBL4zsbVWkQU9E1I5H6c=" ,
128
+ ),
129
+ r .TestCheckResourceAttr (
130
+ "data.archive_file.foo" , "output_md5" , "ea35f0444ea9a3d5641d8760bc2815cc" ,
131
+ ),
132
+ r .TestCheckResourceAttr (
133
+ "data.archive_file.foo" , "output_sha" , "019c79c4dc14dbe1edb3e467b2de6a6aad148717" ,
134
+ ),
135
+ ),
136
+ },
137
+ },
138
+ })
139
+ }
140
+
141
+ func TestDataSource_UpgradeFromVersion2_2_0_FileConfig (t * testing.T ) {
142
+ td := testTempDir (t )
143
+ defer os .RemoveAll (td )
144
+
145
+ f := filepath .Join (td , "zip_file_acc_test_upgrade_file_config.zip" )
146
+
147
+ var fileSize string
148
+
149
+ r .ParallelTest (t , r.TestCase {
150
+ Steps : []r.TestStep {
151
+ {
152
+ ExternalProviders : map [string ]r.ExternalProvider {
153
+ "archive" : {
154
+ VersionConstraint : "2.2.0" ,
155
+ Source : "hashicorp/archive" ,
156
+ },
157
+ },
158
+ Config : testAccArchiveFileFileConfig (f ),
159
+ Check : r .ComposeTestCheckFunc (
160
+ testAccArchiveFileSize (f , & fileSize ),
161
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
162
+ r .TestCheckResourceAttr (
163
+ "data.archive_file.foo" , "output_base64sha256" , "UTE4f5cWfaR6p0HfOrLILxgvF8UUwiJTjTRwjQTgdWs=" ,
164
+ ),
165
+ r .TestCheckResourceAttr (
166
+ "data.archive_file.foo" , "output_md5" , "59fbc9e62af3cbc2f588f97498240dae" ,
167
+ ),
168
+ r .TestCheckResourceAttr (
169
+ "data.archive_file.foo" , "output_sha" , "ce4ee1450ab93ac86e11446649e44cea907b6568" ,
170
+ ),
171
+ ),
172
+ },
173
+ {
174
+ ProtoV5ProviderFactories : protoV5ProviderFactories (),
175
+ Config : testAccArchiveFileFileConfig (f ),
176
+ Check : r .ComposeTestCheckFunc (
177
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
178
+ r .TestCheckResourceAttr (
179
+ "data.archive_file.foo" , "output_base64sha256" , "UTE4f5cWfaR6p0HfOrLILxgvF8UUwiJTjTRwjQTgdWs=" ,
180
+ ),
181
+ r .TestCheckResourceAttr (
182
+ "data.archive_file.foo" , "output_md5" , "59fbc9e62af3cbc2f588f97498240dae" ,
183
+ ),
184
+ r .TestCheckResourceAttr (
185
+ "data.archive_file.foo" , "output_sha" , "ce4ee1450ab93ac86e11446649e44cea907b6568" ,
186
+ ),
187
+ ),
188
+ },
189
+ },
190
+ })
191
+ }
192
+
193
+ func TestDataSource_UpgradeFromVersion2_2_0_DirConfig (t * testing.T ) {
194
+ td := testTempDir (t )
195
+ defer os .RemoveAll (td )
196
+
197
+ f := filepath .Join (td , "zip_file_acc_test_upgrade_dir_config.zip" )
198
+
199
+ var fileSize string
200
+
201
+ r .ParallelTest (t , r.TestCase {
202
+ Steps : []r.TestStep {
203
+ {
204
+ ExternalProviders : map [string ]r.ExternalProvider {
205
+ "archive" : {
206
+ VersionConstraint : "2.2.0" ,
207
+ Source : "hashicorp/archive" ,
208
+ },
209
+ },
210
+ Config : testAccArchiveFileDirConfig (f ),
211
+ Check : r .ComposeTestCheckFunc (
212
+ testAccArchiveFileSize (f , & fileSize ),
213
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
214
+ r .TestCheckResourceAttr (
215
+ "data.archive_file.foo" , "output_base64sha256" , "ydB8wtq8nK9vQ77VH6YTwoHmyljK46jW+uIJSwCzNpo=" ,
216
+ ),
217
+ r .TestCheckResourceAttr (
218
+ "data.archive_file.foo" , "output_md5" , "b73f64a383716070aa4a29563b8b14d4" ,
219
+ ),
220
+ r .TestCheckResourceAttr (
221
+ "data.archive_file.foo" , "output_sha" , "76d20a402eefd1cfbdc47886abd4e0909616c191" ,
222
+ ),
223
+ ),
224
+ },
225
+ {
226
+ ProtoV5ProviderFactories : protoV5ProviderFactories (),
227
+ Config : testAccArchiveFileDirConfig (f ),
228
+ Check : r .ComposeTestCheckFunc (
229
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
230
+ r .TestCheckResourceAttr (
231
+ "data.archive_file.foo" , "output_base64sha256" , "ydB8wtq8nK9vQ77VH6YTwoHmyljK46jW+uIJSwCzNpo=" ,
232
+ ),
233
+ r .TestCheckResourceAttr (
234
+ "data.archive_file.foo" , "output_md5" , "b73f64a383716070aa4a29563b8b14d4" ,
235
+ ),
236
+ r .TestCheckResourceAttr (
237
+ "data.archive_file.foo" , "output_sha" , "76d20a402eefd1cfbdc47886abd4e0909616c191" ,
238
+ ),
239
+ ),
240
+ },
241
+ },
242
+ })
243
+ }
244
+
245
+ func TestDataSource_UpgradeFromVersion2_2_0_DirExcludesConfig (t * testing.T ) {
246
+ td := testTempDir (t )
247
+ defer os .RemoveAll (td )
248
+
249
+ f := filepath .Join (td , "zip_file_acc_test_upgrade_dir_excludes.zip" )
250
+
251
+ var fileSize , outputSha string
252
+
253
+ r .ParallelTest (t , r.TestCase {
254
+ Steps : []r.TestStep {
255
+ {
256
+ ExternalProviders : map [string ]r.ExternalProvider {
257
+ "archive" : {
258
+ VersionConstraint : "2.2.0" ,
259
+ Source : "hashicorp/archive" ,
260
+ },
261
+ },
262
+ Config : testAccArchiveFileDirExcludesConfig (f ),
263
+ Check : r .ComposeTestCheckFunc (
264
+ testAccArchiveFileSize (f , & fileSize ),
265
+ testExtractResourceAttr ("data.archive_file.foo" , "output_sha" , & outputSha ),
266
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
267
+ ),
268
+ },
269
+ {
270
+ ProtoV5ProviderFactories : protoV5ProviderFactories (),
271
+ Config : testAccArchiveFileDirExcludesConfig (f ),
272
+ Check : r .ComposeTestCheckFunc (
273
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
274
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_sha" , & outputSha ),
275
+ ),
276
+ },
277
+ },
278
+ })
279
+ }
280
+
281
+ func TestDataSource_UpgradeFromVersion2_2_0_SourceConfig (t * testing.T ) {
282
+ td := testTempDir (t )
283
+ defer os .RemoveAll (td )
284
+
285
+ f := filepath .Join (td , "zip_file_acc_test_upgrade_source.zip" )
286
+
287
+ var fileSize , outputSha string
288
+
289
+ r .ParallelTest (t , r.TestCase {
290
+ Steps : []r.TestStep {
291
+ {
292
+ ExternalProviders : map [string ]r.ExternalProvider {
293
+ "archive" : {
294
+ VersionConstraint : "2.2.0" ,
295
+ Source : "hashicorp/archive" ,
296
+ },
297
+ },
298
+ Config : testAccArchiveFileMultiSourceConfig (f ),
299
+ Check : r .ComposeTestCheckFunc (
300
+ testAccArchiveFileSize (f , & fileSize ),
301
+ testExtractResourceAttr ("data.archive_file.foo" , "output_sha" , & outputSha ),
302
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
303
+ ),
304
+ },
305
+ {
306
+ ProtoV5ProviderFactories : protoV5ProviderFactories (),
307
+ Config : testAccArchiveFileMultiSourceConfig (f ),
308
+ Check : r .ComposeTestCheckFunc (
309
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
310
+ r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_sha" , & outputSha ),
311
+ ),
312
+ },
313
+ },
314
+ })
315
+ }
316
+
317
+ func testAccArchiveFileSize (filename string , fileSize * string ) r.TestCheckFunc {
90
318
return func (s * terraform.State ) error {
91
319
* fileSize = ""
92
320
fi , err := os .Stat (filename )
@@ -142,7 +370,7 @@ data "archive_file" "foo" {
142
370
` , filepath .ToSlash (outputPath ))
143
371
}
144
372
145
- func testAccArchiveFileMultiConfig (outputPath string ) string {
373
+ func testAccArchiveFileMultiSourceConfig (outputPath string ) string {
146
374
return fmt .Sprintf (`
147
375
data "archive_file" "foo" {
148
376
type = "zip"
@@ -166,3 +394,21 @@ func testTempDir(t *testing.T) string {
166
394
}
167
395
return tmp
168
396
}
397
+
398
+ func testExtractResourceAttr (resourceName string , attributeName string , attributeValue * string ) r.TestCheckFunc {
399
+ return func (s * terraform.State ) error {
400
+ rs , ok := s .RootModule ().Resources [resourceName ]
401
+ if ! ok {
402
+ return fmt .Errorf ("resource name %s not found in state" , resourceName )
403
+ }
404
+
405
+ attrValue , ok := rs .Primary .Attributes [attributeName ]
406
+ if ! ok {
407
+ return fmt .Errorf ("attribute %s not found in resource %s state" , attributeName , resourceName )
408
+ }
409
+
410
+ * attributeValue = attrValue
411
+
412
+ return nil
413
+ }
414
+ }
0 commit comments