Skip to content

Commit

Permalink
Test Report Dir Bug Fix (#364)
Browse files Browse the repository at this point in the history
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 <kensipe@gmail.com>
  • Loading branch information
kensipe committed Apr 21, 2022
1 parent ce3eee1 commit 1572380
Showing 1 changed file with 16 additions and 9 deletions.
25 changes: 16 additions & 9 deletions pkg/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down

0 comments on commit 1572380

Please sign in to comment.