Skip to content

Commit

Permalink
add test for empty file content case
Browse files Browse the repository at this point in the history
  • Loading branch information
kmoe committed Feb 20, 2020
1 parent c2ebc9d commit 6a50f78
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions local/resource_local_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,5 +152,57 @@ resource "local_file" "file" {
})

defer os.Remove(destinationDirPath)
}

func TestLocalFile_EmptyContent(t *testing.T) {
var cases = []struct {
path string
content string
config string
}{
{
"local_file",
"This is some content",
`resource "local_file" "file" {
content = "This is some content"
filename = "local_file"
}`,
},
{
"local_file",
"",
`resource "local_file" "file" {
content = ""
filename = "local_file"
}`,
},
}

for _, tt := range cases {
r.UnitTest(t, r.TestCase{
Providers: testProviders,
Steps: []r.TestStep{
{
Config: tt.config,
Check: func(s *terraform.State) error {
content, err := ioutil.ReadFile(tt.path)
if err != nil {
return fmt.Errorf("config:\n%s\n,got: %s\n", tt.config, err)
}
if string(content) != tt.content {
return fmt.Errorf("config:\n%s\ngot:\n%s\nwant:\n%s\n", tt.config, content, tt.content)
}
return nil
},
Destroy: false,
},
},
CheckDestroy: func(*terraform.State) error {
if _, err := os.Stat(tt.path); os.IsNotExist(err) {
return nil
}
return errors.New("local_file did not get destroyed")
},
})
}
}

0 comments on commit 6a50f78

Please sign in to comment.