Skip to content

Commit

Permalink
JUnit: create directory before creating output file
Browse files Browse the repository at this point in the history
Close #554
  • Loading branch information
thanabodee-c committed Jan 2, 2019
1 parent 505cc35 commit 2e4ceb0
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
4 changes: 4 additions & 0 deletions reporters/junit_reporter.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"fmt"
"math"
"os"
"path/filepath"
"strings"

"github.com/onsi/ginkgo/config"
Expand Down Expand Up @@ -124,6 +125,9 @@ func (reporter *JUnitReporter) SpecSuiteDidEnd(summary *types.SuiteSummary) {
reporter.suite.Time = math.Trunc(summary.RunTime.Seconds()*1000) / 1000
reporter.suite.Failures = summary.NumberOfFailedSpecs
reporter.suite.Errors = 0
if err := os.MkdirAll(filepath.Dir(reporter.filename), 0755); err != nil {
fmt.Printf("Failed to create JUnit report file: %s\n\t%s", reporter.filename, err.Error())
}
file, err := os.Create(reporter.filename)
if err != nil {
fmt.Printf("Failed to create JUnit report file: %s\n\t%s", reporter.filename, err.Error())
Expand Down
14 changes: 14 additions & 0 deletions reporters/junit_reporter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -255,4 +255,18 @@ var _ = Describe("JUnit Reporter", func() {
})
})
}

When("output directory doesn't exist", func() {
It("should create before open file", func() {
output := "/tmp/not/exists/report.xml"
reporter := reporters.NewJUnitReporter(output)
reporter.SpecSuiteDidEnd(&types.SuiteSummary{
NumberOfSpecsThatWillBeRun: 1,
NumberOfFailedSpecs: 0,
RunTime: testSuiteTime,
})
defer os.RemoveAll("/tmp/not")
Ω(output).Should(BeAnExistingFile())
})
})
})

0 comments on commit 2e4ceb0

Please sign in to comment.