1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141
|
package failer_test
import (
. "github.com/onsi/ginkgo"
. "github.com/onsi/ginkgo/internal/failer"
. "github.com/onsi/gomega"
"github.com/onsi/ginkgo/internal/codelocation"
"github.com/onsi/ginkgo/types"
)
var _ = Describe("Failer", func() {
var (
failer *Failer
codeLocationA types.CodeLocation
codeLocationB types.CodeLocation
)
BeforeEach(func() {
codeLocationA = codelocation.New(0)
codeLocationB = codelocation.New(0)
failer = New()
})
Context("with no failures", func() {
It("should return success when drained", func() {
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(BeZero())
Ω(state).Should(Equal(types.SpecStatePassed))
})
})
Describe("Skip", func() {
It("should handle failures", func() {
failer.Skip("something skipped", codeLocationA)
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(Equal(types.SpecFailure{
Message: "something skipped",
Location: codeLocationA,
ForwardedPanic: "",
ComponentType: types.SpecComponentTypeIt,
ComponentIndex: 3,
ComponentCodeLocation: codeLocationB,
}))
Ω(state).Should(Equal(types.SpecStateSkipped))
})
})
Describe("Fail", func() {
It("should handle failures", func() {
failer.Fail("something failed", codeLocationA)
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(Equal(types.SpecFailure{
Message: "something failed",
Location: codeLocationA,
ForwardedPanic: "",
ComponentType: types.SpecComponentTypeIt,
ComponentIndex: 3,
ComponentCodeLocation: codeLocationB,
}))
Ω(state).Should(Equal(types.SpecStateFailed))
})
})
Describe("Panic", func() {
It("should handle panics", func() {
failer.Panic(codeLocationA, "some forwarded panic")
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(Equal(types.SpecFailure{
Message: "Test Panicked",
Location: codeLocationA,
ForwardedPanic: "some forwarded panic",
ComponentType: types.SpecComponentTypeIt,
ComponentIndex: 3,
ComponentCodeLocation: codeLocationB,
}))
Ω(state).Should(Equal(types.SpecStatePanicked))
})
})
Describe("Timeout", func() {
It("should handle timeouts", func() {
failer.Timeout(codeLocationA)
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(Equal(types.SpecFailure{
Message: "Timed out",
Location: codeLocationA,
ForwardedPanic: "",
ComponentType: types.SpecComponentTypeIt,
ComponentIndex: 3,
ComponentCodeLocation: codeLocationB,
}))
Ω(state).Should(Equal(types.SpecStateTimedOut))
})
})
Context("when multiple failures are registered", func() {
BeforeEach(func() {
failer.Fail("something failed", codeLocationA)
failer.Fail("something else failed", codeLocationA)
})
It("should only report the first one when drained", func() {
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(Equal(types.SpecFailure{
Message: "something failed",
Location: codeLocationA,
ForwardedPanic: "",
ComponentType: types.SpecComponentTypeIt,
ComponentIndex: 3,
ComponentCodeLocation: codeLocationB,
}))
Ω(state).Should(Equal(types.SpecStateFailed))
})
It("should report subsequent failures after being drained", func() {
failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
failer.Fail("yet another thing failed", codeLocationA)
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(Equal(types.SpecFailure{
Message: "yet another thing failed",
Location: codeLocationA,
ForwardedPanic: "",
ComponentType: types.SpecComponentTypeIt,
ComponentIndex: 3,
ComponentCodeLocation: codeLocationB,
}))
Ω(state).Should(Equal(types.SpecStateFailed))
})
It("should report sucess on subsequent drains if no errors occur", func() {
failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
failure, state := failer.Drain(types.SpecComponentTypeIt, 3, codeLocationB)
Ω(failure).Should(BeZero())
Ω(state).Should(Equal(types.SpecStatePassed))
})
})
})
|