diff --git a/go.mod b/go.mod index fbd85bba..11fa5aaa 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/local/provider_test.go b/local/provider_test.go index cc7e0f38..e86e623c 100644 --- a/local/provider_test.go +++ b/local/provider_test.go @@ -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" ) @@ -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) +} diff --git a/local/resource_local_file_test.go b/local/resource_local_file_test.go index 43fba769..2ebe539b 100644 --- a/local/resource_local_file_test.go +++ b/local/resource_local_file_test.go @@ -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), }, } @@ -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) @@ -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 +}