Skip to content

Commit

Permalink
test error when file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
mhristof committed Sep 10, 2021
1 parent 03bc315 commit deef65d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 14 deletions.
2 changes: 1 addition & 1 deletion internal/provider/resource_file.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func resourceFileCreate(ctx context.Context, d *schema.ResourceData, m interface
if _, err := os.Stat(path); !os.IsNotExist(err) {
return append(diags, diag.Diagnostic{
Severity: diag.Error,
Summary: "File already exists",
Summary: "EEXIST",
Detail: fmt.Sprintf("File [%s] exists in the filesystem and terraform would overwrite it. Please remove the file and try again", path),
})
}
Expand Down
28 changes: 15 additions & 13 deletions internal/provider/resource_file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"io/ioutil"
"os"
"path/filepath"
"regexp"
"testing"

"github.com/MakeNowJust/heredoc"
Expand Down Expand Up @@ -91,20 +92,21 @@ func TestFile(t *testing.T) {
},
),
},
// {
// // file got replaced with another file
// Config: config(file),
// PreConfig: func() {
// path := filepath.Join(dir, file)
// os.Remove(path)
// err := ioutil.WriteFile(path, []byte("test"), 0644)
// if err != nil {
// t.Fatal(err)
// }
{
// file got replaced with another file
Config: config(file),
ExpectError: regexp.MustCompile(`EEXIST`),
PreConfig: func() {
path := filepath.Join(dir, file)
os.Remove(path)
err := ioutil.WriteFile(path, []byte("test"), 0644)
if err != nil {
t.Fatal(err)
}

// },
// ExpectNonEmptyPlan: false,
// },
},
ExpectNonEmptyPlan: false,
},
},
})
}

0 comments on commit deef65d

Please sign in to comment.