resets time to zero for all godog tests

Этот коммит содержится в:
gedi 2017-04-28 10:27:55 +03:00
родитель d3cf314381
коммит ef794d57ca
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 56604CDCCC201556
9 изменённых файлов: 46 добавлений и 26 удалений

2
fmt.go
Просмотреть файл

@ -305,7 +305,7 @@ func (f *basefmt) Summary() {
scenarios = append(scenarios, green(fmt.Sprintf("%d passed", passed)))
}
scenarios = append(scenarios, parts...)
elapsed := time.Since(f.started)
elapsed := timeNowFunc().Sub(f.started)
fmt.Fprintln(f.out, "")
if total == 0 {

Просмотреть файл

@ -29,7 +29,7 @@ func init() {
func cucumberFunc(suite string, out io.Writer) Formatter {
formatter := &cukefmt{
basefmt: basefmt{
started: time.Now(),
started: timeNowFunc(),
indent: 2,
out: out,
},
@ -252,7 +252,7 @@ func (f *cukefmt) step(res *stepResult) {
// determine if test case has finished
switch t := f.owner.(type) {
case *gherkin.TableRow:
d := int(time.Since(f.startTime).Nanoseconds())
d := int(timeNowFunc().Sub(f.startTime).Nanoseconds())
f.curStep.Result.Duration = &d
f.curStep.Line = t.Location.Line
f.curStep.Result.Status = res.typ.String()
@ -260,7 +260,7 @@ func (f *cukefmt) step(res *stepResult) {
f.curStep.Result.Error = res.err.Error()
}
case *gherkin.Scenario:
d := int(time.Since(f.startTime).Nanoseconds())
d := int(timeNowFunc().Sub(f.startTime).Nanoseconds())
f.curStep.Result.Duration = &d
f.curStep.Result.Status = res.typ.String()
if res.err != nil {
@ -271,7 +271,7 @@ func (f *cukefmt) step(res *stepResult) {
func (f *cukefmt) Defined(step *gherkin.Step, def *StepDef) {
f.startTime = time.Now() // start timing the step
f.startTime = timeNowFunc() // start timing the step
f.curElement.Steps = append(f.curElement.Steps, cukeStep{})
f.curStep = &f.curElement.Steps[len(f.curElement.Steps)-1]

Просмотреть файл

@ -4,7 +4,6 @@ import (
"encoding/json"
"fmt"
"io"
"time"
"github.com/DATA-DOG/godog/gherkin"
)
@ -19,7 +18,7 @@ func init() {
func eventsFunc(suite string, out io.Writer) Formatter {
formatter := &events{
basefmt: basefmt{
started: time.Now(),
started: timeNowFunc(),
indent: 2,
out: out,
},
@ -33,7 +32,7 @@ func eventsFunc(suite string, out io.Writer) Formatter {
}{
"TestRunStarted",
spec,
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
suite,
})
@ -87,7 +86,7 @@ func (f *events) Node(n interface{}) {
}{
"TestCaseStarted",
id,
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
})
if undefined {
@ -101,7 +100,7 @@ func (f *events) Node(n interface{}) {
}{
"TestCaseFinished",
id,
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
"undefined",
})
}
@ -148,7 +147,7 @@ func (f *events) Summary() {
}{
"TestRunFinished",
status.String(),
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
snips,
"", // @TODO not sure that could be correctly implemented
})
@ -168,7 +167,7 @@ func (f *events) step(res *stepResult) {
}{
"TestStepFinished",
fmt.Sprintf("%s:%d", f.path, res.step.Location.Line),
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
res.typ.String(),
errMsg,
})
@ -194,7 +193,7 @@ func (f *events) step(res *stepResult) {
}{
"TestCaseFinished",
fmt.Sprintf("%s:%d", f.path, line),
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
f.stat.String(),
})
}
@ -236,7 +235,7 @@ func (f *events) Defined(step *gherkin.Step, def *StepDef) {
}{
"TestStepStarted",
fmt.Sprintf("%s:%d", f.path, step.Location.Line),
time.Now().UnixNano() / nanoSec,
timeNowFunc().UnixNano() / nanoSec,
})
}

Просмотреть файл

@ -21,7 +21,7 @@ func junitFunc(suite string, out io.Writer) Formatter {
TestSuites: make([]*junitTestSuite, 0),
},
out: out,
started: time.Now(),
started: timeNowFunc(),
}
}
@ -45,9 +45,9 @@ func (j *junitFormatter) Feature(feature *gherkin.Feature, path string, c []byte
}
if len(j.suite.TestSuites) > 0 {
j.current().Time = time.Since(j.featStarted).String()
j.current().Time = timeNowFunc().Sub(j.featStarted).String()
}
j.featStarted = time.Now()
j.featStarted = timeNowFunc()
j.suite.TestSuites = append(j.suite.TestSuites, testSuite)
}
@ -79,9 +79,9 @@ func (j *junitFormatter) Node(node interface{}) {
return
}
if len(suite.TestCases) > 0 {
suite.current().Time = time.Since(j.caseStarted).String()
suite.current().Time = timeNowFunc().Sub(j.caseStarted).String()
}
j.caseStarted = time.Now()
j.caseStarted = timeNowFunc()
suite.TestCases = append(suite.TestCases, tcase)
}
@ -134,7 +134,7 @@ func (j *junitFormatter) Pending(step *gherkin.Step, match *StepDef) {
}
func (j *junitFormatter) Summary() {
j.suite.Time = time.Since(j.started).String()
j.suite.Time = timeNowFunc().Sub(j.started).String()
io.WriteString(j.out, xml.Header)
enc := xml.NewEncoder(j.out)

Просмотреть файл

@ -6,7 +6,6 @@ import (
"math"
"regexp"
"strings"
"time"
"unicode/utf8"
"github.com/DATA-DOG/godog/colors"
@ -20,7 +19,7 @@ func init() {
func prettyFunc(suite string, out io.Writer) Formatter {
return &pretty{
basefmt: basefmt{
started: time.Now(),
started: timeNowFunc(),
indent: 2,
out: out,
},

Просмотреть файл

@ -5,7 +5,6 @@ import (
"io"
"math"
"sync"
"time"
"github.com/DATA-DOG/godog/gherkin"
)
@ -17,7 +16,7 @@ func init() {
func progressFunc(suite string, out io.Writer) Formatter {
return &progress{
basefmt: basefmt{
started: time.Now(),
started: timeNowFunc(),
indent: 2,
out: out,
},

Просмотреть файл

@ -2,7 +2,6 @@ package godog
import (
"io"
"time"
"github.com/DATA-DOG/godog/gherkin"
)
@ -15,7 +14,7 @@ type testFormatter struct {
func testFormatterFunc(suite string, out io.Writer) Formatter {
return &testFormatter{
basefmt: basefmt{
started: time.Now(),
started: timeNowFunc(),
indent: 2,
out: out,
},

Просмотреть файл

@ -4,6 +4,7 @@ import (
"fmt"
"os"
"strings"
"time"
"github.com/DATA-DOG/godog/colors"
)
@ -33,3 +34,7 @@ func fatal(err error) {
os.Exit(1)
}
}
var timeNowFunc = func() time.Time {
return time.Now()
}

19
utils_test.go Обычный файл
Просмотреть файл

@ -0,0 +1,19 @@
package godog
import (
"testing"
"time"
)
func init() {
timeNowFunc = func() time.Time {
return time.Time{}
}
}
func TestTimeNowFunc(t *testing.T) {
now := timeNowFunc()
if !now.IsZero() {
t.Fatalf("expected zeroed time, but got: %s", now.Format(time.RFC3339))
}
}