Skip to content

Commit 202d605

Browse files
committed
add test for empty file content case
1 parent c507fd8 commit 202d605

File tree

1 file changed

+53
-0
lines changed

1 file changed

+53
-0
lines changed

local/resource_local_file_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,3 +62,56 @@ func TestLocalFile_Basic(t *testing.T) {
6262
})
6363
}
6464
}
65+
66+
func TestLocalFile_EmptyContent(t *testing.T) {
67+
var cases = []struct {
68+
path string
69+
content string
70+
config string
71+
}{
72+
{
73+
"local_file",
74+
"This is some content",
75+
`resource "local_file" "file" {
76+
content = "This is some content"
77+
filename = "local_file"
78+
}`,
79+
},
80+
{
81+
"local_file",
82+
"",
83+
`resource "local_file" "file" {
84+
content = ""
85+
filename = "local_file"
86+
}`,
87+
},
88+
}
89+
90+
for _, tt := range cases {
91+
r.UnitTest(t, r.TestCase{
92+
Providers: testProviders,
93+
Steps: []r.TestStep{
94+
{
95+
Config: tt.config,
96+
Check: func(s *terraform.State) error {
97+
content, err := ioutil.ReadFile(tt.path)
98+
if err != nil {
99+
return fmt.Errorf("config:\n%s\n,got: %s\n", tt.config, err)
100+
}
101+
if string(content) != tt.content {
102+
return fmt.Errorf("config:\n%s\ngot:\n%s\nwant:\n%s\n", tt.config, content, tt.content)
103+
}
104+
return nil
105+
},
106+
Destroy: false,
107+
},
108+
},
109+
CheckDestroy: func(*terraform.State) error {
110+
if _, err := os.Stat(tt.path); os.IsNotExist(err) {
111+
return nil
112+
}
113+
return errors.New("local_file did not get destroyed")
114+
},
115+
})
116+
}
117+
}

0 commit comments

Comments
 (0)