Skip to content

Commit cfa8e5b

Browse files
committed
enable binary acceptance testing
Absolute paths are now required for local filesystem resources created and checked during tests.
1 parent 6112311 commit cfa8e5b

File tree

3 files changed

+61
-44
lines changed

3 files changed

+61
-44
lines changed

archive/data_source_archive_file_test.go

Lines changed: 52 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package archive
22

33
import (
44
"fmt"
5+
"io/ioutil"
56
"os"
67
"path/filepath"
78
"regexp"
@@ -12,14 +13,19 @@ import (
1213
)
1314

1415
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+
1521
var fileSize string
1622
r.Test(t, r.TestCase{
1723
Providers: testProviders,
1824
Steps: []r.TestStep{
1925
{
20-
Config: testAccArchiveFileContentConfig,
26+
Config: testAccArchiveFileContentConfig(f),
2127
Check: r.ComposeTestCheckFunc(
22-
testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize),
28+
testAccArchiveFileExists(f, &fileSize),
2329
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
2430

2531
// We just check the hashes for syntax rather than exact
@@ -39,40 +45,34 @@ func TestAccArchiveFile_Basic(t *testing.T) {
3945
),
4046
},
4147
{
42-
Config: testAccArchiveFileFileConfig,
48+
Config: testAccArchiveFileFileConfig(f),
4349
Check: r.ComposeTestCheckFunc(
44-
testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize),
50+
testAccArchiveFileExists(f, &fileSize),
4551
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
4652
),
4753
},
4854
{
49-
Config: testAccArchiveFileDirConfig,
55+
Config: testAccArchiveFileDirConfig(f),
5056
Check: r.ComposeTestCheckFunc(
51-
testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize),
57+
testAccArchiveFileExists(f, &fileSize),
5258
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
5359
),
5460
},
5561
{
56-
Config: testAccArchiveFileDirExcludesConfig,
62+
Config: testAccArchiveFileDirExcludesConfig(f),
5763
Check: r.ComposeTestCheckFunc(
58-
testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize),
64+
testAccArchiveFileExists(f, &fileSize),
5965
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
6066
),
6167
},
6268

6369
{
64-
Config: testAccArchiveFileMultiConfig,
70+
Config: testAccArchiveFileMultiConfig(f),
6571
Check: r.ComposeTestCheckFunc(
66-
testAccArchiveFileExists("zip_file_acc_test.zip", &fileSize),
72+
testAccArchiveFileExists(f, &fileSize),
6773
r.TestCheckResourceAttrPtr("data.archive_file.foo", "output_size", &fileSize),
6874
),
6975
},
70-
{
71-
Config: testAccArchiveFileOutputPath,
72-
Check: r.ComposeTestCheckFunc(
73-
testAccArchiveFileExists(fmt.Sprintf("%s/test.zip", tmpDir), &fileSize),
74-
),
75-
},
7676
},
7777
})
7878
}
@@ -89,57 +89,65 @@ func testAccArchiveFileExists(filename string, fileSize *string) r.TestCheckFunc
8989
}
9090
}
9191

92-
var testAccArchiveFileContentConfig = `
92+
func testAccArchiveFileContentConfig(outputPath string) string {
93+
return fmt.Sprintf(`
9394
data "archive_file" "foo" {
9495
type = "zip"
9596
source_content = "This is some content"
9697
source_content_filename = "content.txt"
97-
output_path = "zip_file_acc_test.zip"
98+
output_path = "%s"
9899
}
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)
108101
}
109-
`, tmpDir)
110102

111-
var testAccArchiveFileFileConfig = `
103+
func testAccArchiveFileFileConfig(outputPath string) string {
104+
return fmt.Sprintf(`
112105
data "archive_file" "foo" {
113106
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)
116111
}
117-
`
118112

119-
var testAccArchiveFileDirConfig = `
113+
func testAccArchiveFileDirConfig(outputPath string) string {
114+
return fmt.Sprintf(`
120115
data "archive_file" "foo" {
121116
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)
124121
}
125-
`
126122

127-
var testAccArchiveFileDirExcludesConfig = `
123+
func testAccArchiveFileDirExcludesConfig(outputPath string) string {
124+
return fmt.Sprintf(`
128125
data "archive_file" "foo" {
129126
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)
133132
}
134-
`
135133

136-
var testAccArchiveFileMultiConfig = `
134+
func testAccArchiveFileMultiConfig(outputPath string) string {
135+
return fmt.Sprintf(`
137136
data "archive_file" "foo" {
138137
type = "zip"
139138
source {
140139
filename = "content.txt"
141140
content = "This is some content"
142141
}
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
144153
}
145-
`

archive/provider_test.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ package archive
33
import (
44
"testing"
55

6+
"github.com/hashicorp/terraform-plugin-sdk/acctest"
7+
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
68
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
79
"github.com/hashicorp/terraform-plugin-sdk/terraform"
810
)
@@ -16,3 +18,8 @@ func TestProvider(t *testing.T) {
1618
t.Fatalf("err: %s", err)
1719
}
1820
}
21+
22+
func TestMain(m *testing.M) {
23+
acctest.UseBinaryDriver("archive", Provider)
24+
resource.TestMain(m)
25+
}

go.mod

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
module github.com/terraform-providers/terraform-provider-archive
22

3+
go 1.14
4+
35
require (
46
github.com/hashicorp/hcl v1.0.0 // indirect
57
github.com/hashicorp/terraform-plugin-sdk v1.12.0

0 commit comments

Comments
 (0)