Add RemoveFile common function

Also cleans up left over test files
This commit is contained in:
Adrian Gallagher
2017-08-23 11:45:06 +10:00
parent 39548b23b9
commit f684b4d19f
2 changed files with 23 additions and 1 deletions

View File

@@ -383,7 +383,8 @@ func OutputCSV(path string, data [][]string) error {
return err
}
defer writer.Flush()
writer.Flush()
file.Close()
return nil
}
@@ -420,6 +421,11 @@ func WriteFile(file string, data []byte) error {
return nil
}
// RemoveFile removes a file
func RemoveFile(file string) error {
return os.Remove(file)
}
// GetURIPath returns the path of a URL given a URI
func GetURIPath(uri string) string {
urip, err := url.Parse(uri)

View File

@@ -652,6 +652,22 @@ func TestWriteFile(t *testing.T) {
}
}
func TestRemoveFile(t *testing.T) {
TestWriteFile(t)
path := "../testdata/writefiletest"
err := RemoveFile(path)
if err != nil {
t.Errorf("Test failed. Common RemoveFile error: %s", err)
}
TestOutputCSV(t)
path = "../testdata/dump"
err = RemoveFile(path)
if err != nil {
t.Errorf("Test failed. Common RemoveFile error: %s", err)
}
}
func TestGetURIPath(t *testing.T) {
t.Parallel()
// mapping of input vs expected result