From 15723806929c3150269e54ce060bdfc4409c8c08 Mon Sep 17 00:00:00 2001 From: Ken Sipe Date: Thu, 21 Apr 2022 10:31:22 -0500 Subject: [PATCH] Test Report Dir Bug Fix (#364) A newly added feature was to create the directory for test reports if it didn't exist. The default if not specified location of the test report was "", which equated to the current directory. The check on "" existence was false which lead to the mkdir "" which is obvious going to fail. The solution is to verify that the artifactsDir isn't "" prior to that logic. Signed-off-by: Ken Sipe --- pkg/report/report.go | 25 ++++++++++++++++--------- 1 file changed, 16 insertions(+), 9 deletions(-) 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)