@@ -152,5 +152,57 @@ resource "local_file" "file" {
152152 })
153153
154154 defer os .Remove (destinationDirPath )
155+ }
156+
157+ func TestLocalFile_EmptyContent (t * testing.T ) {
158+ var cases = []struct {
159+ path string
160+ content string
161+ config string
162+ }{
163+ {
164+ "local_file" ,
165+ "This is some content" ,
166+ `resource "local_file" "file" {
167+ content = "This is some content"
168+ filename = "local_file"
169+ }` ,
170+ },
171+ {
172+ "local_file" ,
173+ "" ,
174+ `resource "local_file" "file" {
175+ content = ""
176+ filename = "local_file"
177+ }` ,
178+ },
179+ }
155180
181+ for _ , tt := range cases {
182+ r .UnitTest (t , r.TestCase {
183+ Providers : testProviders ,
184+ Steps : []r.TestStep {
185+ {
186+ Config : tt .config ,
187+ Check : func (s * terraform.State ) error {
188+ content , err := ioutil .ReadFile (tt .path )
189+ if err != nil {
190+ return fmt .Errorf ("config:\n %s\n ,got: %s\n " , tt .config , err )
191+ }
192+ if string (content ) != tt .content {
193+ return fmt .Errorf ("config:\n %s\n got:\n %s\n want:\n %s\n " , tt .config , content , tt .content )
194+ }
195+ return nil
196+ },
197+ Destroy : false ,
198+ },
199+ },
200+ CheckDestroy : func (* terraform.State ) error {
201+ if _ , err := os .Stat (tt .path ); os .IsNotExist (err ) {
202+ return nil
203+ }
204+ return errors .New ("local_file did not get destroyed" )
205+ },
206+ })
207+ }
156208}
0 commit comments