Ensure some tests remove temporary directories they created

This commit is contained in:
Matthew Holt
2016-11-28 22:26:54 -07:00
parent e2917784d0
commit 36f8759a7b
2 changed files with 15 additions and 9 deletions

View File

@ -746,14 +746,16 @@ func TestFiles(t *testing.T) {
// Create directory / files from test case.
if test.fileNames != nil {
dirPath, err = ioutil.TempDir(fmt.Sprintf("%s", context.Root), "caddy_test")
dirPath, err = ioutil.TempDir(fmt.Sprintf("%s", context.Root), "caddy_ctxtest")
if err != nil {
os.RemoveAll(dirPath)
t.Fatalf(testPrefix+"Expected no error creating directory, got: '%s'", err.Error())
}
for _, name := range test.fileNames {
absFilePath := filepath.Join(dirPath, name)
if err = ioutil.WriteFile(absFilePath, []byte(""), os.ModePerm); err != nil {
os.RemoveAll(dirPath)
t.Fatalf(testPrefix+"Expected no error creating file, got: '%s'", err.Error())
}
}