forked from github/multus-cni
vendor: add ginkgo and gomega
This commit is contained in:
committed by
Kuralamudhan Ramakrishnan
parent
1c8ad953d0
commit
5820658a5e
15
vendor/github.com/onsi/ginkgo/internal/specrunner/random_id.go
generated
vendored
Normal file
15
vendor/github.com/onsi/ginkgo/internal/specrunner/random_id.go
generated
vendored
Normal file
@@ -0,0 +1,15 @@
|
||||
package specrunner
|
||||
|
||||
import (
|
||||
"crypto/rand"
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func randomID() string {
|
||||
b := make([]byte, 8)
|
||||
_, err := rand.Read(b)
|
||||
if err != nil {
|
||||
return ""
|
||||
}
|
||||
return fmt.Sprintf("%x-%x-%x-%x", b[0:2], b[2:4], b[4:6], b[6:8])
|
||||
}
|
324
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go
generated
vendored
Normal file
324
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner.go
generated
vendored
Normal file
@@ -0,0 +1,324 @@
|
||||
package specrunner
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/signal"
|
||||
"sync"
|
||||
"syscall"
|
||||
|
||||
"github.com/onsi/ginkgo/config"
|
||||
"github.com/onsi/ginkgo/internal/leafnodes"
|
||||
"github.com/onsi/ginkgo/internal/spec"
|
||||
Writer "github.com/onsi/ginkgo/internal/writer"
|
||||
"github.com/onsi/ginkgo/reporters"
|
||||
"github.com/onsi/ginkgo/types"
|
||||
|
||||
"time"
|
||||
)
|
||||
|
||||
type SpecRunner struct {
|
||||
description string
|
||||
beforeSuiteNode leafnodes.SuiteNode
|
||||
specs *spec.Specs
|
||||
afterSuiteNode leafnodes.SuiteNode
|
||||
reporters []reporters.Reporter
|
||||
startTime time.Time
|
||||
suiteID string
|
||||
runningSpec *spec.Spec
|
||||
writer Writer.WriterInterface
|
||||
config config.GinkgoConfigType
|
||||
interrupted bool
|
||||
lock *sync.Mutex
|
||||
}
|
||||
|
||||
func New(description string, beforeSuiteNode leafnodes.SuiteNode, specs *spec.Specs, afterSuiteNode leafnodes.SuiteNode, reporters []reporters.Reporter, writer Writer.WriterInterface, config config.GinkgoConfigType) *SpecRunner {
|
||||
return &SpecRunner{
|
||||
description: description,
|
||||
beforeSuiteNode: beforeSuiteNode,
|
||||
specs: specs,
|
||||
afterSuiteNode: afterSuiteNode,
|
||||
reporters: reporters,
|
||||
writer: writer,
|
||||
config: config,
|
||||
suiteID: randomID(),
|
||||
lock: &sync.Mutex{},
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) Run() bool {
|
||||
if runner.config.DryRun {
|
||||
runner.performDryRun()
|
||||
return true
|
||||
}
|
||||
|
||||
runner.reportSuiteWillBegin()
|
||||
go runner.registerForInterrupts()
|
||||
|
||||
suitePassed := runner.runBeforeSuite()
|
||||
|
||||
if suitePassed {
|
||||
suitePassed = runner.runSpecs()
|
||||
}
|
||||
|
||||
runner.blockForeverIfInterrupted()
|
||||
|
||||
suitePassed = runner.runAfterSuite() && suitePassed
|
||||
|
||||
runner.reportSuiteDidEnd(suitePassed)
|
||||
|
||||
return suitePassed
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) performDryRun() {
|
||||
runner.reportSuiteWillBegin()
|
||||
|
||||
if runner.beforeSuiteNode != nil {
|
||||
summary := runner.beforeSuiteNode.Summary()
|
||||
summary.State = types.SpecStatePassed
|
||||
runner.reportBeforeSuite(summary)
|
||||
}
|
||||
|
||||
for _, spec := range runner.specs.Specs() {
|
||||
summary := spec.Summary(runner.suiteID)
|
||||
runner.reportSpecWillRun(summary)
|
||||
if summary.State == types.SpecStateInvalid {
|
||||
summary.State = types.SpecStatePassed
|
||||
}
|
||||
runner.reportSpecDidComplete(summary, false)
|
||||
}
|
||||
|
||||
if runner.afterSuiteNode != nil {
|
||||
summary := runner.afterSuiteNode.Summary()
|
||||
summary.State = types.SpecStatePassed
|
||||
runner.reportAfterSuite(summary)
|
||||
}
|
||||
|
||||
runner.reportSuiteDidEnd(true)
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) runBeforeSuite() bool {
|
||||
if runner.beforeSuiteNode == nil || runner.wasInterrupted() {
|
||||
return true
|
||||
}
|
||||
|
||||
runner.writer.Truncate()
|
||||
conf := runner.config
|
||||
passed := runner.beforeSuiteNode.Run(conf.ParallelNode, conf.ParallelTotal, conf.SyncHost)
|
||||
if !passed {
|
||||
runner.writer.DumpOut()
|
||||
}
|
||||
runner.reportBeforeSuite(runner.beforeSuiteNode.Summary())
|
||||
return passed
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) runAfterSuite() bool {
|
||||
if runner.afterSuiteNode == nil {
|
||||
return true
|
||||
}
|
||||
|
||||
runner.writer.Truncate()
|
||||
conf := runner.config
|
||||
passed := runner.afterSuiteNode.Run(conf.ParallelNode, conf.ParallelTotal, conf.SyncHost)
|
||||
if !passed {
|
||||
runner.writer.DumpOut()
|
||||
}
|
||||
runner.reportAfterSuite(runner.afterSuiteNode.Summary())
|
||||
return passed
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) runSpecs() bool {
|
||||
suiteFailed := false
|
||||
skipRemainingSpecs := false
|
||||
for _, spec := range runner.specs.Specs() {
|
||||
if runner.wasInterrupted() {
|
||||
return suiteFailed
|
||||
}
|
||||
if skipRemainingSpecs {
|
||||
spec.Skip()
|
||||
}
|
||||
runner.reportSpecWillRun(spec.Summary(runner.suiteID))
|
||||
|
||||
if !spec.Skipped() && !spec.Pending() {
|
||||
runner.runningSpec = spec
|
||||
spec.Run(runner.writer)
|
||||
runner.runningSpec = nil
|
||||
if spec.Failed() {
|
||||
suiteFailed = true
|
||||
}
|
||||
} else if spec.Pending() && runner.config.FailOnPending {
|
||||
suiteFailed = true
|
||||
}
|
||||
|
||||
runner.reportSpecDidComplete(spec.Summary(runner.suiteID), spec.Failed())
|
||||
|
||||
if spec.Failed() && runner.config.FailFast {
|
||||
skipRemainingSpecs = true
|
||||
}
|
||||
}
|
||||
|
||||
return !suiteFailed
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) CurrentSpecSummary() (*types.SpecSummary, bool) {
|
||||
if runner.runningSpec == nil {
|
||||
return nil, false
|
||||
}
|
||||
|
||||
return runner.runningSpec.Summary(runner.suiteID), true
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) registerForInterrupts() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
<-c
|
||||
signal.Stop(c)
|
||||
runner.markInterrupted()
|
||||
go runner.registerForHardInterrupts()
|
||||
runner.writer.DumpOutWithHeader(`
|
||||
Received interrupt. Emitting contents of GinkgoWriter...
|
||||
---------------------------------------------------------
|
||||
`)
|
||||
if runner.afterSuiteNode != nil {
|
||||
fmt.Fprint(os.Stderr, `
|
||||
---------------------------------------------------------
|
||||
Received interrupt. Running AfterSuite...
|
||||
^C again to terminate immediately
|
||||
`)
|
||||
runner.runAfterSuite()
|
||||
}
|
||||
runner.reportSuiteDidEnd(false)
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) registerForHardInterrupts() {
|
||||
c := make(chan os.Signal, 1)
|
||||
signal.Notify(c, os.Interrupt, syscall.SIGTERM)
|
||||
|
||||
<-c
|
||||
fmt.Fprintln(os.Stderr, "\nReceived second interrupt. Shutting down.")
|
||||
os.Exit(1)
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) blockForeverIfInterrupted() {
|
||||
runner.lock.Lock()
|
||||
interrupted := runner.interrupted
|
||||
runner.lock.Unlock()
|
||||
|
||||
if interrupted {
|
||||
select {}
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) markInterrupted() {
|
||||
runner.lock.Lock()
|
||||
defer runner.lock.Unlock()
|
||||
runner.interrupted = true
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) wasInterrupted() bool {
|
||||
runner.lock.Lock()
|
||||
defer runner.lock.Unlock()
|
||||
return runner.interrupted
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) reportSuiteWillBegin() {
|
||||
runner.startTime = time.Now()
|
||||
summary := runner.summary(true)
|
||||
for _, reporter := range runner.reporters {
|
||||
reporter.SpecSuiteWillBegin(runner.config, summary)
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) reportBeforeSuite(summary *types.SetupSummary) {
|
||||
for _, reporter := range runner.reporters {
|
||||
reporter.BeforeSuiteDidRun(summary)
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) reportAfterSuite(summary *types.SetupSummary) {
|
||||
for _, reporter := range runner.reporters {
|
||||
reporter.AfterSuiteDidRun(summary)
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) reportSpecWillRun(summary *types.SpecSummary) {
|
||||
runner.writer.Truncate()
|
||||
|
||||
for _, reporter := range runner.reporters {
|
||||
reporter.SpecWillRun(summary)
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) reportSpecDidComplete(summary *types.SpecSummary, failed bool) {
|
||||
for i := len(runner.reporters) - 1; i >= 1; i-- {
|
||||
runner.reporters[i].SpecDidComplete(summary)
|
||||
}
|
||||
|
||||
if failed {
|
||||
runner.writer.DumpOut()
|
||||
}
|
||||
|
||||
runner.reporters[0].SpecDidComplete(summary)
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) reportSuiteDidEnd(success bool) {
|
||||
summary := runner.summary(success)
|
||||
summary.RunTime = time.Since(runner.startTime)
|
||||
for _, reporter := range runner.reporters {
|
||||
reporter.SpecSuiteDidEnd(summary)
|
||||
}
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) countSpecsSatisfying(filter func(ex *spec.Spec) bool) (count int) {
|
||||
count = 0
|
||||
|
||||
for _, spec := range runner.specs.Specs() {
|
||||
if filter(spec) {
|
||||
count++
|
||||
}
|
||||
}
|
||||
|
||||
return count
|
||||
}
|
||||
|
||||
func (runner *SpecRunner) summary(success bool) *types.SuiteSummary {
|
||||
numberOfSpecsThatWillBeRun := runner.countSpecsSatisfying(func(ex *spec.Spec) bool {
|
||||
return !ex.Skipped() && !ex.Pending()
|
||||
})
|
||||
|
||||
numberOfPendingSpecs := runner.countSpecsSatisfying(func(ex *spec.Spec) bool {
|
||||
return ex.Pending()
|
||||
})
|
||||
|
||||
numberOfSkippedSpecs := runner.countSpecsSatisfying(func(ex *spec.Spec) bool {
|
||||
return ex.Skipped()
|
||||
})
|
||||
|
||||
numberOfPassedSpecs := runner.countSpecsSatisfying(func(ex *spec.Spec) bool {
|
||||
return ex.Passed()
|
||||
})
|
||||
|
||||
numberOfFailedSpecs := runner.countSpecsSatisfying(func(ex *spec.Spec) bool {
|
||||
return ex.Failed()
|
||||
})
|
||||
|
||||
if runner.beforeSuiteNode != nil && !runner.beforeSuiteNode.Passed() && !runner.config.DryRun {
|
||||
numberOfFailedSpecs = numberOfSpecsThatWillBeRun
|
||||
}
|
||||
|
||||
return &types.SuiteSummary{
|
||||
SuiteDescription: runner.description,
|
||||
SuiteSucceeded: success,
|
||||
SuiteID: runner.suiteID,
|
||||
|
||||
NumberOfSpecsBeforeParallelization: runner.specs.NumberOfOriginalSpecs(),
|
||||
NumberOfTotalSpecs: len(runner.specs.Specs()),
|
||||
NumberOfSpecsThatWillBeRun: numberOfSpecsThatWillBeRun,
|
||||
NumberOfPendingSpecs: numberOfPendingSpecs,
|
||||
NumberOfSkippedSpecs: numberOfSkippedSpecs,
|
||||
NumberOfPassedSpecs: numberOfPassedSpecs,
|
||||
NumberOfFailedSpecs: numberOfFailedSpecs,
|
||||
}
|
||||
}
|
13
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner_suite_test.go
generated
vendored
Normal file
13
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner_suite_test.go
generated
vendored
Normal file
@@ -0,0 +1,13 @@
|
||||
package specrunner_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSpecRunner(t *testing.T) {
|
||||
RegisterFailHandler(Fail)
|
||||
RunSpecs(t, "Spec Runner Suite")
|
||||
}
|
623
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go
generated
vendored
Normal file
623
vendor/github.com/onsi/ginkgo/internal/specrunner/spec_runner_test.go
generated
vendored
Normal file
@@ -0,0 +1,623 @@
|
||||
package specrunner_test
|
||||
|
||||
import (
|
||||
. "github.com/onsi/ginkgo"
|
||||
. "github.com/onsi/ginkgo/internal/specrunner"
|
||||
"github.com/onsi/ginkgo/types"
|
||||
. "github.com/onsi/gomega"
|
||||
|
||||
"github.com/onsi/ginkgo/config"
|
||||
"github.com/onsi/ginkgo/internal/codelocation"
|
||||
"github.com/onsi/ginkgo/internal/containernode"
|
||||
Failer "github.com/onsi/ginkgo/internal/failer"
|
||||
"github.com/onsi/ginkgo/internal/leafnodes"
|
||||
"github.com/onsi/ginkgo/internal/spec"
|
||||
Writer "github.com/onsi/ginkgo/internal/writer"
|
||||
"github.com/onsi/ginkgo/reporters"
|
||||
)
|
||||
|
||||
var noneFlag = types.FlagTypeNone
|
||||
var focusedFlag = types.FlagTypeFocused
|
||||
var pendingFlag = types.FlagTypePending
|
||||
|
||||
var _ = Describe("Spec Runner", func() {
|
||||
var (
|
||||
reporter1 *reporters.FakeReporter
|
||||
reporter2 *reporters.FakeReporter
|
||||
failer *Failer.Failer
|
||||
writer *Writer.FakeGinkgoWriter
|
||||
|
||||
thingsThatRan []string
|
||||
|
||||
runner *SpecRunner
|
||||
)
|
||||
|
||||
newBefSuite := func(text string, fail bool) leafnodes.SuiteNode {
|
||||
return leafnodes.NewBeforeSuiteNode(func() {
|
||||
writer.AddEvent(text)
|
||||
thingsThatRan = append(thingsThatRan, text)
|
||||
if fail {
|
||||
failer.Fail(text, codelocation.New(0))
|
||||
}
|
||||
}, codelocation.New(0), 0, failer)
|
||||
}
|
||||
|
||||
newAftSuite := func(text string, fail bool) leafnodes.SuiteNode {
|
||||
return leafnodes.NewAfterSuiteNode(func() {
|
||||
writer.AddEvent(text)
|
||||
thingsThatRan = append(thingsThatRan, text)
|
||||
if fail {
|
||||
failer.Fail(text, codelocation.New(0))
|
||||
}
|
||||
}, codelocation.New(0), 0, failer)
|
||||
}
|
||||
|
||||
newSpec := func(text string, flag types.FlagType, fail bool) *spec.Spec {
|
||||
subject := leafnodes.NewItNode(text, func() {
|
||||
writer.AddEvent(text)
|
||||
thingsThatRan = append(thingsThatRan, text)
|
||||
if fail {
|
||||
failer.Fail(text, codelocation.New(0))
|
||||
}
|
||||
}, flag, codelocation.New(0), 0, failer, 0)
|
||||
|
||||
return spec.New(subject, []*containernode.ContainerNode{}, false)
|
||||
}
|
||||
|
||||
newSpecWithBody := func(text string, body interface{}) *spec.Spec {
|
||||
subject := leafnodes.NewItNode(text, body, noneFlag, codelocation.New(0), 0, failer, 0)
|
||||
|
||||
return spec.New(subject, []*containernode.ContainerNode{}, false)
|
||||
}
|
||||
|
||||
newRunner := func(config config.GinkgoConfigType, beforeSuiteNode leafnodes.SuiteNode, afterSuiteNode leafnodes.SuiteNode, specs ...*spec.Spec) *SpecRunner {
|
||||
return New("description", beforeSuiteNode, spec.NewSpecs(specs), afterSuiteNode, []reporters.Reporter{reporter1, reporter2}, writer, config)
|
||||
}
|
||||
|
||||
BeforeEach(func() {
|
||||
reporter1 = reporters.NewFakeReporter()
|
||||
reporter2 = reporters.NewFakeReporter()
|
||||
writer = Writer.NewFake()
|
||||
failer = Failer.New()
|
||||
|
||||
thingsThatRan = []string{}
|
||||
})
|
||||
|
||||
Describe("Running and Reporting", func() {
|
||||
var specA, pendingSpec, anotherPendingSpec, failedSpec, specB, skippedSpec *spec.Spec
|
||||
var willRunCalls, didCompleteCalls []string
|
||||
var conf config.GinkgoConfigType
|
||||
|
||||
JustBeforeEach(func() {
|
||||
willRunCalls = []string{}
|
||||
didCompleteCalls = []string{}
|
||||
specA = newSpec("spec A", noneFlag, false)
|
||||
pendingSpec = newSpec("pending spec", pendingFlag, false)
|
||||
anotherPendingSpec = newSpec("another pending spec", pendingFlag, false)
|
||||
failedSpec = newSpec("failed spec", noneFlag, true)
|
||||
specB = newSpec("spec B", noneFlag, false)
|
||||
skippedSpec = newSpec("skipped spec", noneFlag, false)
|
||||
skippedSpec.Skip()
|
||||
|
||||
reporter1.SpecWillRunStub = func(specSummary *types.SpecSummary) {
|
||||
willRunCalls = append(willRunCalls, "Reporter1")
|
||||
}
|
||||
reporter2.SpecWillRunStub = func(specSummary *types.SpecSummary) {
|
||||
willRunCalls = append(willRunCalls, "Reporter2")
|
||||
}
|
||||
|
||||
reporter1.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
|
||||
didCompleteCalls = append(didCompleteCalls, "Reporter1")
|
||||
}
|
||||
reporter2.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
|
||||
didCompleteCalls = append(didCompleteCalls, "Reporter2")
|
||||
}
|
||||
|
||||
runner = newRunner(conf, newBefSuite("BefSuite", false), newAftSuite("AftSuite", false), specA, pendingSpec, anotherPendingSpec, failedSpec, specB, skippedSpec)
|
||||
runner.Run()
|
||||
})
|
||||
|
||||
BeforeEach(func() {
|
||||
conf = config.GinkgoConfigType{RandomSeed: 17}
|
||||
})
|
||||
|
||||
It("should skip skipped/pending tests", func() {
|
||||
Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "spec A", "failed spec", "spec B", "AftSuite"}))
|
||||
})
|
||||
|
||||
It("should report to any attached reporters", func() {
|
||||
Ω(reporter1.Config).Should(Equal(reporter2.Config))
|
||||
Ω(reporter1.BeforeSuiteSummary).Should(Equal(reporter2.BeforeSuiteSummary))
|
||||
Ω(reporter1.BeginSummary).Should(Equal(reporter2.BeginSummary))
|
||||
Ω(reporter1.SpecWillRunSummaries).Should(Equal(reporter2.SpecWillRunSummaries))
|
||||
Ω(reporter1.SpecSummaries).Should(Equal(reporter2.SpecSummaries))
|
||||
Ω(reporter1.AfterSuiteSummary).Should(Equal(reporter2.AfterSuiteSummary))
|
||||
Ω(reporter1.EndSummary).Should(Equal(reporter2.EndSummary))
|
||||
})
|
||||
|
||||
It("should report that a spec did end in reverse order", func() {
|
||||
Ω(willRunCalls[0:4]).Should(Equal([]string{"Reporter1", "Reporter2", "Reporter1", "Reporter2"}))
|
||||
Ω(didCompleteCalls[0:4]).Should(Equal([]string{"Reporter2", "Reporter1", "Reporter2", "Reporter1"}))
|
||||
})
|
||||
|
||||
It("should report the passed in config", func() {
|
||||
Ω(reporter1.Config.RandomSeed).Should(BeNumerically("==", 17))
|
||||
})
|
||||
|
||||
It("should report the beginning of the suite", func() {
|
||||
Ω(reporter1.BeginSummary.SuiteDescription).Should(Equal("description"))
|
||||
Ω(reporter1.BeginSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
|
||||
Ω(reporter1.BeginSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
|
||||
Ω(reporter1.BeginSummary.NumberOfTotalSpecs).Should(Equal(6))
|
||||
Ω(reporter1.BeginSummary.NumberOfSpecsThatWillBeRun).Should(Equal(3))
|
||||
Ω(reporter1.BeginSummary.NumberOfPendingSpecs).Should(Equal(2))
|
||||
Ω(reporter1.BeginSummary.NumberOfSkippedSpecs).Should(Equal(1))
|
||||
})
|
||||
|
||||
It("should report the end of the suite", func() {
|
||||
Ω(reporter1.EndSummary.SuiteDescription).Should(Equal("description"))
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
|
||||
Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(6))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(3))
|
||||
Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(2))
|
||||
Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(1))
|
||||
Ω(reporter1.EndSummary.NumberOfPassedSpecs).Should(Equal(2))
|
||||
Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(1))
|
||||
})
|
||||
|
||||
Context("when told to perform a dry run", func() {
|
||||
BeforeEach(func() {
|
||||
conf.DryRun = true
|
||||
})
|
||||
|
||||
It("should report to the reporters", func() {
|
||||
Ω(reporter1.Config).Should(Equal(reporter2.Config))
|
||||
Ω(reporter1.BeforeSuiteSummary).Should(Equal(reporter2.BeforeSuiteSummary))
|
||||
Ω(reporter1.BeginSummary).Should(Equal(reporter2.BeginSummary))
|
||||
Ω(reporter1.SpecWillRunSummaries).Should(Equal(reporter2.SpecWillRunSummaries))
|
||||
Ω(reporter1.SpecSummaries).Should(Equal(reporter2.SpecSummaries))
|
||||
Ω(reporter1.AfterSuiteSummary).Should(Equal(reporter2.AfterSuiteSummary))
|
||||
Ω(reporter1.EndSummary).Should(Equal(reporter2.EndSummary))
|
||||
})
|
||||
|
||||
It("should not actually run anything", func() {
|
||||
Ω(thingsThatRan).Should(BeEmpty())
|
||||
})
|
||||
|
||||
It("report before and after suites as passed", func() {
|
||||
Ω(reporter1.BeforeSuiteSummary.State).Should(Equal(types.SpecStatePassed))
|
||||
Ω(reporter1.AfterSuiteSummary.State).Should(Equal(types.SpecStatePassed))
|
||||
})
|
||||
|
||||
It("should report specs as passed", func() {
|
||||
summaries := reporter1.SpecSummaries
|
||||
Ω(summaries).Should(HaveLen(6))
|
||||
Ω(summaries[0].ComponentTexts).Should(ContainElement("spec A"))
|
||||
Ω(summaries[0].State).Should(Equal(types.SpecStatePassed))
|
||||
Ω(summaries[1].ComponentTexts).Should(ContainElement("pending spec"))
|
||||
Ω(summaries[1].State).Should(Equal(types.SpecStatePending))
|
||||
Ω(summaries[2].ComponentTexts).Should(ContainElement("another pending spec"))
|
||||
Ω(summaries[2].State).Should(Equal(types.SpecStatePending))
|
||||
Ω(summaries[3].ComponentTexts).Should(ContainElement("failed spec"))
|
||||
Ω(summaries[3].State).Should(Equal(types.SpecStatePassed))
|
||||
Ω(summaries[4].ComponentTexts).Should(ContainElement("spec B"))
|
||||
Ω(summaries[4].State).Should(Equal(types.SpecStatePassed))
|
||||
Ω(summaries[5].ComponentTexts).Should(ContainElement("skipped spec"))
|
||||
Ω(summaries[5].State).Should(Equal(types.SpecStateSkipped))
|
||||
})
|
||||
|
||||
It("should report the end of the suite", func() {
|
||||
Ω(reporter1.EndSummary.SuiteDescription).Should(Equal("description"))
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
|
||||
Ω(reporter1.EndSummary.SuiteID).Should(MatchRegexp("[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(6))
|
||||
Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(6))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(3))
|
||||
Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(2))
|
||||
Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(1))
|
||||
Ω(reporter1.EndSummary.NumberOfPassedSpecs).Should(Equal(0))
|
||||
Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("reporting on specs", func() {
|
||||
var proceed chan bool
|
||||
var ready chan bool
|
||||
var finished chan bool
|
||||
BeforeEach(func() {
|
||||
ready = make(chan bool)
|
||||
proceed = make(chan bool)
|
||||
finished = make(chan bool)
|
||||
skippedSpec := newSpec("SKIP", noneFlag, false)
|
||||
skippedSpec.Skip()
|
||||
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
newBefSuite("BefSuite", false),
|
||||
newAftSuite("AftSuite", false),
|
||||
skippedSpec,
|
||||
newSpec("PENDING", pendingFlag, false),
|
||||
newSpecWithBody("RUN", func() {
|
||||
close(ready)
|
||||
<-proceed
|
||||
}),
|
||||
)
|
||||
go func() {
|
||||
runner.Run()
|
||||
close(finished)
|
||||
}()
|
||||
})
|
||||
|
||||
It("should report about pending/skipped specs", func() {
|
||||
<-ready
|
||||
Ω(reporter1.SpecWillRunSummaries).Should(HaveLen(3))
|
||||
|
||||
Ω(reporter1.SpecWillRunSummaries[0].ComponentTexts[0]).Should(Equal("SKIP"))
|
||||
Ω(reporter1.SpecWillRunSummaries[1].ComponentTexts[0]).Should(Equal("PENDING"))
|
||||
Ω(reporter1.SpecWillRunSummaries[2].ComponentTexts[0]).Should(Equal("RUN"))
|
||||
|
||||
Ω(reporter1.SpecSummaries[0].ComponentTexts[0]).Should(Equal("SKIP"))
|
||||
Ω(reporter1.SpecSummaries[1].ComponentTexts[0]).Should(Equal("PENDING"))
|
||||
Ω(reporter1.SpecSummaries).Should(HaveLen(2))
|
||||
|
||||
close(proceed)
|
||||
<-finished
|
||||
|
||||
Ω(reporter1.SpecSummaries).Should(HaveLen(3))
|
||||
Ω(reporter1.SpecSummaries[2].ComponentTexts[0]).Should(Equal("RUN"))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Running BeforeSuite & AfterSuite", func() {
|
||||
var success bool
|
||||
var befSuite leafnodes.SuiteNode
|
||||
var aftSuite leafnodes.SuiteNode
|
||||
Context("with a nil BeforeSuite & AfterSuite", func() {
|
||||
BeforeEach(func() {
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
nil,
|
||||
nil,
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpec("B", noneFlag, false),
|
||||
)
|
||||
success = runner.Run()
|
||||
})
|
||||
|
||||
It("should not report about the BeforeSuite", func() {
|
||||
Ω(reporter1.BeforeSuiteSummary).Should(BeNil())
|
||||
})
|
||||
|
||||
It("should not report about the AfterSuite", func() {
|
||||
Ω(reporter1.AfterSuiteSummary).Should(BeNil())
|
||||
})
|
||||
|
||||
It("should run the specs", func() {
|
||||
Ω(thingsThatRan).Should(Equal([]string{"A", "B"}))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when the BeforeSuite & AfterSuite pass", func() {
|
||||
BeforeEach(func() {
|
||||
befSuite = newBefSuite("BefSuite", false)
|
||||
aftSuite = newBefSuite("AftSuite", false)
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
befSuite,
|
||||
aftSuite,
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpec("B", noneFlag, false),
|
||||
)
|
||||
success = runner.Run()
|
||||
})
|
||||
|
||||
It("should run the BeforeSuite, the AfterSuite and the specs", func() {
|
||||
Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "A", "B", "AftSuite"}))
|
||||
})
|
||||
|
||||
It("should report about the BeforeSuite", func() {
|
||||
Ω(reporter1.BeforeSuiteSummary).Should(Equal(befSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report about the AfterSuite", func() {
|
||||
Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report success", func() {
|
||||
Ω(success).Should(BeTrue())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
|
||||
Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
|
||||
})
|
||||
|
||||
It("should not dump the writer", func() {
|
||||
Ω(writer.EventStream).ShouldNot(ContainElement("DUMP"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when the BeforeSuite fails", func() {
|
||||
BeforeEach(func() {
|
||||
befSuite = newBefSuite("BefSuite", true)
|
||||
aftSuite = newBefSuite("AftSuite", false)
|
||||
|
||||
skipped := newSpec("Skipped", noneFlag, false)
|
||||
skipped.Skip()
|
||||
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
befSuite,
|
||||
aftSuite,
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpec("B", noneFlag, false),
|
||||
newSpec("Pending", pendingFlag, false),
|
||||
skipped,
|
||||
)
|
||||
success = runner.Run()
|
||||
})
|
||||
|
||||
It("should not run the specs, but it should run the AfterSuite", func() {
|
||||
Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "AftSuite"}))
|
||||
})
|
||||
|
||||
It("should report about the BeforeSuite", func() {
|
||||
Ω(reporter1.BeforeSuiteSummary).Should(Equal(befSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report about the AfterSuite", func() {
|
||||
Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report failure", func() {
|
||||
Ω(success).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(2))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(2))
|
||||
})
|
||||
|
||||
It("should dump the writer", func() {
|
||||
Ω(writer.EventStream).Should(ContainElement("DUMP"))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when some other test fails", func() {
|
||||
BeforeEach(func() {
|
||||
aftSuite = newBefSuite("AftSuite", false)
|
||||
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
nil,
|
||||
aftSuite,
|
||||
newSpec("A", noneFlag, true),
|
||||
)
|
||||
success = runner.Run()
|
||||
})
|
||||
|
||||
It("should still run the AfterSuite", func() {
|
||||
Ω(thingsThatRan).Should(Equal([]string{"A", "AftSuite"}))
|
||||
})
|
||||
|
||||
It("should report about the AfterSuite", func() {
|
||||
Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report failure", func() {
|
||||
Ω(success).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(1))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(1))
|
||||
})
|
||||
})
|
||||
|
||||
Context("when the AfterSuite fails", func() {
|
||||
BeforeEach(func() {
|
||||
befSuite = newBefSuite("BefSuite", false)
|
||||
aftSuite = newBefSuite("AftSuite", true)
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
befSuite,
|
||||
aftSuite,
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpec("B", noneFlag, false),
|
||||
)
|
||||
success = runner.Run()
|
||||
})
|
||||
|
||||
It("should run everything", func() {
|
||||
Ω(thingsThatRan).Should(Equal([]string{"BefSuite", "A", "B", "AftSuite"}))
|
||||
})
|
||||
|
||||
It("should report about the BeforeSuite", func() {
|
||||
Ω(reporter1.BeforeSuiteSummary).Should(Equal(befSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report about the AfterSuite", func() {
|
||||
Ω(reporter1.AfterSuiteSummary).Should(Equal(aftSuite.Summary()))
|
||||
})
|
||||
|
||||
It("should report failure", func() {
|
||||
Ω(success).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.NumberOfFailedSpecs).Should(Equal(0))
|
||||
})
|
||||
|
||||
It("should dump the writer", func() {
|
||||
Ω(writer.EventStream).Should(ContainElement("DUMP"))
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("When instructed to fail fast", func() {
|
||||
BeforeEach(func() {
|
||||
conf := config.GinkgoConfigType{
|
||||
FailFast: true,
|
||||
}
|
||||
runner = newRunner(conf, nil, newAftSuite("after-suite", false), newSpec("passing", noneFlag, false), newSpec("failing", noneFlag, true), newSpec("dont-see", noneFlag, true), newSpec("dont-see", noneFlag, true))
|
||||
})
|
||||
|
||||
It("should return false, report failure, and not run anything past the failing test", func() {
|
||||
Ω(runner.Run()).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
Ω(thingsThatRan).Should(Equal([]string{"passing", "failing", "after-suite"}))
|
||||
})
|
||||
|
||||
It("should announce the subsequent specs as skipped", func() {
|
||||
runner.Run()
|
||||
Ω(reporter1.SpecSummaries).Should(HaveLen(4))
|
||||
Ω(reporter1.SpecSummaries[2].State).Should(Equal(types.SpecStateSkipped))
|
||||
Ω(reporter1.SpecSummaries[3].State).Should(Equal(types.SpecStateSkipped))
|
||||
})
|
||||
|
||||
It("should mark all subsequent specs as skipped", func() {
|
||||
runner.Run()
|
||||
Ω(reporter1.EndSummary.NumberOfSkippedSpecs).Should(Equal(2))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Marking failure and success", func() {
|
||||
Context("when all tests pass", func() {
|
||||
BeforeEach(func() {
|
||||
runner = newRunner(config.GinkgoConfigType{}, nil, nil, newSpec("passing", noneFlag, false), newSpec("pending", pendingFlag, false))
|
||||
})
|
||||
|
||||
It("should return true and report success", func() {
|
||||
Ω(runner.Run()).Should(BeTrue())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeTrue())
|
||||
})
|
||||
})
|
||||
|
||||
Context("when a test fails", func() {
|
||||
BeforeEach(func() {
|
||||
runner = newRunner(config.GinkgoConfigType{}, nil, nil, newSpec("failing", noneFlag, true), newSpec("pending", pendingFlag, false))
|
||||
})
|
||||
|
||||
It("should return false and report failure", func() {
|
||||
Ω(runner.Run()).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
Context("when there is a pending test, but pendings count as failures", func() {
|
||||
BeforeEach(func() {
|
||||
runner = newRunner(config.GinkgoConfigType{FailOnPending: true}, nil, nil, newSpec("passing", noneFlag, false), newSpec("pending", pendingFlag, false))
|
||||
})
|
||||
|
||||
It("should return false and report failure", func() {
|
||||
Ω(runner.Run()).Should(BeFalse())
|
||||
Ω(reporter1.EndSummary.SuiteSucceeded).Should(BeFalse())
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
Describe("Managing the writer", func() {
|
||||
BeforeEach(func() {
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
nil,
|
||||
nil,
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpec("B", noneFlag, true),
|
||||
newSpec("C", noneFlag, false),
|
||||
)
|
||||
reporter1.SpecWillRunStub = func(specSummary *types.SpecSummary) {
|
||||
writer.AddEvent("R1.WillRun")
|
||||
}
|
||||
reporter2.SpecWillRunStub = func(specSummary *types.SpecSummary) {
|
||||
writer.AddEvent("R2.WillRun")
|
||||
}
|
||||
reporter1.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
|
||||
writer.AddEvent("R1.DidComplete")
|
||||
}
|
||||
reporter2.SpecDidCompleteStub = func(specSummary *types.SpecSummary) {
|
||||
writer.AddEvent("R2.DidComplete")
|
||||
}
|
||||
runner.Run()
|
||||
})
|
||||
|
||||
It("should truncate between tests, but only dump if a test fails", func() {
|
||||
Ω(writer.EventStream).Should(Equal([]string{
|
||||
"TRUNCATE",
|
||||
"R1.WillRun",
|
||||
"R2.WillRun",
|
||||
"A",
|
||||
"R2.DidComplete",
|
||||
"R1.DidComplete",
|
||||
"TRUNCATE",
|
||||
"R1.WillRun",
|
||||
"R2.WillRun",
|
||||
"B",
|
||||
"R2.DidComplete",
|
||||
"DUMP",
|
||||
"R1.DidComplete",
|
||||
"TRUNCATE",
|
||||
"R1.WillRun",
|
||||
"R2.WillRun",
|
||||
"C",
|
||||
"R2.DidComplete",
|
||||
"R1.DidComplete",
|
||||
}))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("CurrentSpecSummary", func() {
|
||||
It("should return the spec summary for the currently running spec", func() {
|
||||
var summary *types.SpecSummary
|
||||
runner = newRunner(
|
||||
config.GinkgoConfigType{},
|
||||
nil,
|
||||
nil,
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpecWithBody("B", func() {
|
||||
var ok bool
|
||||
summary, ok = runner.CurrentSpecSummary()
|
||||
Ω(ok).Should(BeTrue())
|
||||
}),
|
||||
newSpec("C", noneFlag, false),
|
||||
)
|
||||
runner.Run()
|
||||
|
||||
Ω(summary.ComponentTexts).Should(Equal([]string{"B"}))
|
||||
|
||||
summary, ok := runner.CurrentSpecSummary()
|
||||
Ω(summary).Should(BeNil())
|
||||
Ω(ok).Should(BeFalse())
|
||||
})
|
||||
})
|
||||
|
||||
Context("When running tests in parallel", func() {
|
||||
It("reports the correct number of specs before parallelization", func() {
|
||||
specs := spec.NewSpecs([]*spec.Spec{
|
||||
newSpec("A", noneFlag, false),
|
||||
newSpec("B", pendingFlag, false),
|
||||
newSpec("C", noneFlag, false),
|
||||
})
|
||||
specs.TrimForParallelization(2, 1)
|
||||
runner = New("description", nil, specs, nil, []reporters.Reporter{reporter1, reporter2}, writer, config.GinkgoConfigType{})
|
||||
runner.Run()
|
||||
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsBeforeParallelization).Should(Equal(3))
|
||||
Ω(reporter1.EndSummary.NumberOfTotalSpecs).Should(Equal(2))
|
||||
Ω(reporter1.EndSummary.NumberOfSpecsThatWillBeRun).Should(Equal(1))
|
||||
Ω(reporter1.EndSummary.NumberOfPendingSpecs).Should(Equal(1))
|
||||
})
|
||||
})
|
||||
|
||||
Describe("generating a suite id", func() {
|
||||
It("should generate an id randomly", func() {
|
||||
runnerA := newRunner(config.GinkgoConfigType{}, nil, nil)
|
||||
runnerA.Run()
|
||||
IDA := reporter1.BeginSummary.SuiteID
|
||||
|
||||
runnerB := newRunner(config.GinkgoConfigType{}, nil, nil)
|
||||
runnerB.Run()
|
||||
IDB := reporter1.BeginSummary.SuiteID
|
||||
|
||||
IDRegexp := "[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}"
|
||||
Ω(IDA).Should(MatchRegexp(IDRegexp))
|
||||
Ω(IDB).Should(MatchRegexp(IDRegexp))
|
||||
|
||||
Ω(IDA).ShouldNot(Equal(IDB))
|
||||
})
|
||||
})
|
||||
})
|
Reference in New Issue
Block a user