Skip to content

Commit

Permalink
Fixed report file path after chdir changes
Browse files Browse the repository at this point in the history
This fixes the path to write the report file to disk.
  • Loading branch information
martinrode committed Sep 5, 2022
1 parent 95c2de4 commit 3ca76f4
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 14 deletions.
18 changes: 9 additions & 9 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -148,9 +148,17 @@ func runApiTests(cmd *cobra.Command, args []string) {
}
}

currDir, _ := os.Getwd()
absPath := func(p string) string {
if filepath.IsAbs(p) {
return p
}
return filepath.Join(currDir, p)
}

server := Config.Apitest.Server
reportFormat = Config.Apitest.Report.Format
reportFile = Config.Apitest.Report.File
reportFile = absPath(Config.Apitest.Report.File)

rep := report.NewReport()
rep.StatsGroups = int(reportStatsGroups)
Expand Down Expand Up @@ -188,14 +196,6 @@ func runApiTests(cmd *cobra.Command, args []string) {
return suite.Run()
}

currDir, _ := os.Getwd()
absPath := func(p string) string {
if filepath.IsAbs(p) {
return p
}
return filepath.Join(currDir, p)
}

// Decide if run only one test
if len(singleTests) > 0 {
for _, singleTest := range singleTests {
Expand Down
10 changes: 5 additions & 5 deletions pkg/lib/report/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,13 @@ func NewReport() *Report {
return &report
}

//GetTestResult Parses the test report with the given function from the report root on
// GetTestResult Parses the test report with the given function from the report root on
func (r Report) GetTestResult(parsingFunction func(baseResult *ReportElement) []byte) []byte {

return parsingFunction(r.root.getTestResult())
}

//DidFail, Check if the testsuite did produce failures
// DidFail, Check if the testsuite did produce failures
func (r Report) DidFail() bool {
aggRes := r.root.getTestResult()
if aggRes.Failures > 0 {
Expand Down Expand Up @@ -84,7 +84,7 @@ func (re ReportElements) Flat() ReportElements {
return rElements
}

//NewChild create new report element and return its reference
// NewChild create new report element and return its reference
func (r *ReportElement) NewChild(name string) (newElem *ReportElement) {
r.report.m.Lock()
defer r.report.m.Unlock()
Expand Down Expand Up @@ -127,7 +127,7 @@ func (r *ReportElement) Leave(result bool) {
r.ExecutionTime = time.Since(r.StartTime)
}

//aggregate results of subtests
// aggregate results of subtests
func (r *ReportElement) getTestResult() *ReportElement {
for _, v := range r.SubTests {
subResults := v.getTestResult()
Expand Down Expand Up @@ -188,7 +188,7 @@ func (r *Report) WriteToFile(reportFile, reportFormat string) error {
case "stats":
parsingFunction = ParseJSONStatsResult
default:
logrus.Errorf(
logrus.Warnf(
"Given report format '%s' not supported. Saving report '%s' as json",
reportFormat,
reportFile)
Expand Down

0 comments on commit 3ca76f4

Please sign in to comment.