diff --git a/pkg/report/report.go b/pkg/report/report.go index 9ec3e3e5..080b6913 100644 --- a/pkg/report/report.go +++ b/pkg/report/report.go @@ -218,15 +218,8 @@ func latestEnd(start time.Time, testcases []*Testcase) time.Time { func (ts *Testsuites) Report(dir, name string, ftype Type) error { ts.Close() - // Create the folder to save the report if it doesn't exist - _, err := os.Stat(dir) - - if os.IsNotExist(err) { - err = os.MkdirAll(dir, 0755) - if err != nil { - return err - } - } else if err != nil { + err := ensureDir(dir) + if err != nil { return err } @@ -241,6 +234,20 @@ func (ts *Testsuites) Report(dir, name string, ftype Type) error { } } +func ensureDir(dir string) error { + if dir == "" { + return nil + } + _, err := os.Stat(dir) + // TODO log this, need to passing logger or have logger added to Testsuites + // Create the folder to save the report if it doesn't exist + if os.IsNotExist(err) { + err = os.MkdirAll(dir, 0755) + // no need for error check, it is always returned and handled by caller + } + return err +} + // NewSuite creates and assigns a TestSuite to the TestSuites (then returns the suite) func (ts *Testsuites) NewSuite(name string) *Testsuite { suite := NewSuite(name)