Skip to content

Commit

Permalink
enable binary acceptance testing
Browse files Browse the repository at this point in the history
Absolute paths are now required for local filesystem resources created and checked during tests.
  • Loading branch information
kmoe committed May 12, 2020
1 parent 6b5e190 commit a808802
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 22 deletions.
2 changes: 2 additions & 0 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
module github.com/terraform-providers/terraform-provider-local

go 1.14

require (
github.com/hashicorp/hcl v1.0.0 // indirect
github.com/hashicorp/terraform-plugin-sdk v1.12.0
Expand Down
7 changes: 7 additions & 0 deletions local/provider_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package local
import (
"testing"

"github.com/hashicorp/terraform-plugin-sdk/acctest"
"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
)
Expand All @@ -16,3 +18,8 @@ func TestProvider(t *testing.T) {
t.Fatalf("err: %s", err)
}
}

func TestMain(m *testing.M) {
acctest.UseBinaryDriver("local", Provider)
resource.TestMain(m)
}
57 changes: 35 additions & 22 deletions local/resource_local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,52 +5,57 @@ import (
"fmt"
"io/ioutil"
"os"
"path"
"path/filepath"
"runtime"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/acctest"
r "github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/terraform"
"path"
"runtime"
)

func TestLocalFile_Basic(t *testing.T) {
td := testTempDir(t)
defer os.RemoveAll(td)

f := filepath.Join(td, "local_file")

var cases = []struct {
path string
content string
config string
}{
{
"local_file",
"This is some content", `
f,
"This is some content", fmt.Sprintf(`
resource "local_file" "file" {
content = "This is some content"
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
{
"local_file",
"This is some sensitive content", `
f,
"This is some sensitive content", fmt.Sprintf(`
resource "local_file" "file" {
sensitive_content = "This is some sensitive content"
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
{
"local_file",
"This is some sensitive content", `
f,
"This is some sensitive content", fmt.Sprintf(`
resource "local_file" "file" {
content_base64 = "VGhpcyBpcyBzb21lIHNlbnNpdGl2ZSBjb250ZW50"
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
{
"local_file",
"This is some sensitive content", `
f,
"This is some sensitive content", fmt.Sprintf(`
resource "local_file" "file" {
content_base64 = base64encode("This is some sensitive content")
filename = "local_file"
}`,
filename = "%s"
}`, f),
},
}

Expand Down Expand Up @@ -85,10 +90,10 @@ resource "local_file" "file" {
}

func TestLocalFile_Permissions(t *testing.T) {
td := testTempDir(t)
defer os.RemoveAll(td)

randomPath := acctest.RandomWithPrefix("test-file-perms")

destinationDirPath := "../test/" + randomPath
destinationDirPath := td
destinationFilePath := destinationDirPath + "/local_file"
filePermission := os.FileMode(0600)
directoryPermission := os.FileMode(0700)
Expand Down Expand Up @@ -154,3 +159,11 @@ resource "local_file" "file" {
defer os.Remove(destinationDirPath)

}

func testTempDir(t *testing.T) string {
tmp, err := ioutil.TempDir("", "tf")
if err != nil {
t.Fatal(err)
}
return tmp
}

0 comments on commit a808802

Please sign in to comment.