@@ -2,6 +2,7 @@ package archive
2
2
3
3
import (
4
4
"fmt"
5
+ "io/ioutil"
5
6
"os"
6
7
"path/filepath"
7
8
"regexp"
@@ -12,14 +13,19 @@ import (
12
13
)
13
14
14
15
func TestAccArchiveFile_Basic (t * testing.T ) {
16
+ td := testTempDir (t )
17
+ defer os .RemoveAll (td )
18
+
19
+ f := filepath .Join (td , "zip_file_acc_test.zip" )
20
+
15
21
var fileSize string
16
22
r .Test (t , r.TestCase {
17
23
Providers : testProviders ,
18
24
Steps : []r.TestStep {
19
25
{
20
- Config : testAccArchiveFileContentConfig ,
26
+ Config : testAccArchiveFileContentConfig ( f ) ,
21
27
Check : r .ComposeTestCheckFunc (
22
- testAccArchiveFileExists ("zip_file_acc_test.zip" , & fileSize ),
28
+ testAccArchiveFileExists (f , & fileSize ),
23
29
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
24
30
25
31
// We just check the hashes for syntax rather than exact
@@ -39,40 +45,34 @@ func TestAccArchiveFile_Basic(t *testing.T) {
39
45
),
40
46
},
41
47
{
42
- Config : testAccArchiveFileFileConfig ,
48
+ Config : testAccArchiveFileFileConfig ( f ) ,
43
49
Check : r .ComposeTestCheckFunc (
44
- testAccArchiveFileExists ("zip_file_acc_test.zip" , & fileSize ),
50
+ testAccArchiveFileExists (f , & fileSize ),
45
51
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
46
52
),
47
53
},
48
54
{
49
- Config : testAccArchiveFileDirConfig ,
55
+ Config : testAccArchiveFileDirConfig ( f ) ,
50
56
Check : r .ComposeTestCheckFunc (
51
- testAccArchiveFileExists ("zip_file_acc_test.zip" , & fileSize ),
57
+ testAccArchiveFileExists (f , & fileSize ),
52
58
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
53
59
),
54
60
},
55
61
{
56
- Config : testAccArchiveFileDirExcludesConfig ,
62
+ Config : testAccArchiveFileDirExcludesConfig ( f ) ,
57
63
Check : r .ComposeTestCheckFunc (
58
- testAccArchiveFileExists ("zip_file_acc_test.zip" , & fileSize ),
64
+ testAccArchiveFileExists (f , & fileSize ),
59
65
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
60
66
),
61
67
},
62
68
63
69
{
64
- Config : testAccArchiveFileMultiConfig ,
70
+ Config : testAccArchiveFileMultiConfig ( f ) ,
65
71
Check : r .ComposeTestCheckFunc (
66
- testAccArchiveFileExists ("zip_file_acc_test.zip" , & fileSize ),
72
+ testAccArchiveFileExists (f , & fileSize ),
67
73
r .TestCheckResourceAttrPtr ("data.archive_file.foo" , "output_size" , & fileSize ),
68
74
),
69
75
},
70
- {
71
- Config : testAccArchiveFileOutputPath ,
72
- Check : r .ComposeTestCheckFunc (
73
- testAccArchiveFileExists (fmt .Sprintf ("%s/test.zip" , tmpDir ), & fileSize ),
74
- ),
75
- },
76
76
},
77
77
})
78
78
}
@@ -89,57 +89,65 @@ func testAccArchiveFileExists(filename string, fileSize *string) r.TestCheckFunc
89
89
}
90
90
}
91
91
92
- var testAccArchiveFileContentConfig = `
92
+ func testAccArchiveFileContentConfig (outputPath string ) string {
93
+ return fmt .Sprintf (`
93
94
data "archive_file" "foo" {
94
95
type = "zip"
95
96
source_content = "This is some content"
96
97
source_content_filename = "content.txt"
97
- output_path = "zip_file_acc_test.zip "
98
+ output_path = "%s "
98
99
}
99
- `
100
-
101
- var tmpDir = filepath .ToSlash (os .TempDir ()) + "/test"
102
- var testAccArchiveFileOutputPath = fmt .Sprintf (`
103
- data "archive_file" "foo" {
104
- type = "zip"
105
- source_content = "This is some content"
106
- source_content_filename = "content.txt"
107
- output_path = "%s/test.zip"
100
+ ` , outputPath )
108
101
}
109
- ` , tmpDir )
110
102
111
- var testAccArchiveFileFileConfig = `
103
+ func testAccArchiveFileFileConfig (outputPath string ) string {
104
+ return fmt .Sprintf (`
112
105
data "archive_file" "foo" {
113
106
type = "zip"
114
- source_file = "test-fixtures/test-file.txt"
115
- output_path = "zip_file_acc_test.zip"
107
+ source_file = "%s"
108
+ output_path = "%s"
109
+ }
110
+ ` , filepath .Join ("test-fixtures" , "test-file.txt" ), outputPath )
116
111
}
117
- `
118
112
119
- var testAccArchiveFileDirConfig = `
113
+ func testAccArchiveFileDirConfig (outputPath string ) string {
114
+ return fmt .Sprintf (`
120
115
data "archive_file" "foo" {
121
116
type = "zip"
122
- source_dir = "test-fixtures/test-dir"
123
- output_path = "zip_file_acc_test.zip"
117
+ source_dir = "%s"
118
+ output_path = "%s"
119
+ }
120
+ ` , filepath .Join ("test-fixtures" , "test-dir" ), outputPath )
124
121
}
125
- `
126
122
127
- var testAccArchiveFileDirExcludesConfig = `
123
+ func testAccArchiveFileDirExcludesConfig (outputPath string ) string {
124
+ return fmt .Sprintf (`
128
125
data "archive_file" "foo" {
129
126
type = "zip"
130
- source_dir = "../archive/test-fixtures/../test-fixtures/test-dir"
131
- excludes = ["test-fixtures/test-dir/file2.txt"]
132
- output_path = "zip_file_acc_test.zip"
127
+ source_dir = "%s"
128
+ excludes = ["%s"]
129
+ output_path = "%s"
130
+ }
131
+ ` , filepath .Join ("test-fixtures" , "test-dir" ), filepath .Join ("test-fixtures" , "test-dir" , "file2.txt" ), outputPath )
133
132
}
134
- `
135
133
136
- var testAccArchiveFileMultiConfig = `
134
+ func testAccArchiveFileMultiConfig (outputPath string ) string {
135
+ return fmt .Sprintf (`
137
136
data "archive_file" "foo" {
138
137
type = "zip"
139
138
source {
140
139
filename = "content.txt"
141
140
content = "This is some content"
142
141
}
143
- output_path = "zip_file_acc_test.zip"
142
+ output_path = "%s"
143
+ }
144
+ ` , outputPath )
145
+ }
146
+
147
+ func testTempDir (t * testing.T ) string {
148
+ tmp , err := ioutil .TempDir ("" , "tf" )
149
+ if err != nil {
150
+ t .Fatal (err )
151
+ }
152
+ return tmp
144
153
}
145
- `
0 commit comments