Simplify tests by using T.TempDir (#1186)

This commit is contained in:
Oleksandr Redko authored and GitHub committed 2023-05-30 07:24:59 -05:00
1 parent 6705461b33
commit 6dbb0c5af5
5 files changed
+10 -37

No files matched your search

+1 -6
View File
@@ -11,7 +11,6 @@ import (
const (
expectPath = "../testdata/expected/"
tmpPath = "../testdata/tmp"
)
func TestReport(t *testing.T) {
@@ -80,22 +79,18 @@ func TestReport(t *testing.T) {
}
for i, test := range tests {
tmpfile, err := os.Create(filepath.Join(tmpPath, strconv.Itoa(i)+test.ext))
tmpfile, err := os.Create(filepath.Join(t.TempDir(), strconv.Itoa(i)+test.ext))
if err != nil {
os.Remove(tmpfile.Name())
t.Error(err)
}
err = Write(test.findings, config.Config{}, test.ext, tmpfile.Name())
if err != nil {
os.Remove(tmpfile.Name())
t.Error(err)
}
got, err := os.ReadFile(tmpfile.Name())
if err != nil {
os.Remove(tmpfile.Name())
t.Error(err)
}
os.Remove(tmpfile.Name())
if len(got) == 0 && !test.wantEmpty {
t.Errorf("got empty file with extension " + test.ext)