aboutsummaryrefslogtreecommitdiff
path: root/vendor/github.com/onsi/ginkgo/internal/failer
diff options
context:
space:
mode:
authorValentin Rothberg <rothberg@redhat.com>2019-02-05 11:51:41 +0100
committerValentin Rothberg <rothberg@redhat.com>2019-02-06 11:14:06 +0100
commit9ac0ebb0791851aea81ecc847802db5a39bfb6e7 (patch)
tree30ad98bcc2c2dd1136f46a48cbc44d422adfa184 /vendor/github.com/onsi/ginkgo/internal/failer
parent51714d5da7aaa19014fd67b48b79dfbd5f69c1f0 (diff)
downloadpodman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.gz
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.tar.bz2
podman-9ac0ebb0791851aea81ecc847802db5a39bfb6e7.zip
Cirrus: add vendor_check_task
* Make sure that all vendored dependencies are in sync with the code and the vendor.conf by running `make vendor` with a follow-up status check of the git tree. * Vendor ginkgo and gomega to include the test dependencies. Signed-off-by: Chris Evic <cevich@redhat.com> Signed-off-by: Valentin Rothberg <rothberg@redhat.com>
Diffstat (limited to 'vendor/github.com/onsi/ginkgo/internal/failer')
-rw-r--r--vendor/github.com/onsi/ginkgo/internal/failer/failer.go92
-rw-r--r--vendor/github.com/onsi/ginkgo/internal/failer/failer_suite_test.go13
-rw-r--r--vendor/github.com/onsi/ginkgo/internal/failer/failer_test.go141
3 files changed, 246 insertions, 0 deletions
diff --git a/vendor/github.com/onsi/ginkgo/internal/failer/failer.go b/vendor/github.com/onsi/ginkgo/internal/failer/failer.go
new file mode 100644
index 000000000..678ea2514
--- /dev/null
+++ b/vendor/github.com/onsi/ginkgo/internal/failer/failer.go
@@ -0,0 +1,92 @@
+package failer
+
+import (
+ "fmt"
+ "sync"
+
+ "github.com/onsi/ginkgo/types"
+)
+
+type Failer struct {
+ lock *sync.Mutex
+ failure types.SpecFailure
+ state types.SpecState
+}
+
+func New() *Failer {
+ return &Failer{
+ lock: &sync.Mutex{},
+ state: types.SpecStatePassed,
+ }
+}
+
+func (f *Failer) Panic(location types.CodeLocation, forwardedPanic interface{}) {
+ f.lock.Lock()
+ defer f.lock.Unlock()
+
+ if f.state == types.SpecStatePassed {
+ f.state = types.SpecStatePanicked
+ f.failure = types.SpecFailure{
+ Message: "Test Panicked",
+ Location: location,
+ ForwardedPanic: fmt.Sprintf("%v", forwardedPanic),
+ }
+ }
+}
+
+func (f *Failer) Timeout(location types.CodeLocation) {
+ f.lock.Lock()
+ defer f.lock.Unlock()
+
+ if f.state == types.SpecStatePassed {
+ f.state = types.SpecStateTimedOut
+ f.failure = types.SpecFailure{
+ Message: "Timed out",
+ Location: location,
+ }
+ }
+}
+
+func (f *Failer) Fail(message string, location types.CodeLocation) {
+ f.lock.Lock()
+ defer f.lock.Unlock()
+
+ if f.state == types.SpecStatePassed {
+ f.state = types.SpecStateFailed
+ f.failure = types.SpecFailure{
+ Message: message,
+ Location: location,
+ }
+ }
+}
+
+func (f *Failer) Drain(componentType types.SpecComponentType, componentIndex int, componentCodeLocation types.CodeLocation) (types.SpecFailure, types.SpecState) {
+ f.lock.Lock()
+ defer f.lock.Unlock()
+
+ failure := f.failure
+ outcome := f.state
+ if outcome != types.SpecStatePassed {
+ failure.ComponentType = componentType
+ failure.ComponentIndex = componentIndex
+ failure.ComponentCodeLocation = componentCodeLocation
+ }
+
+ f.state = types.SpecStatePassed
+ f.failure = types.SpecFailure{}
+
+ return failure, outcome
+}
+
+func (f *Failer) Skip(message string, location types.CodeLocation) {
+ f.lock.Lock()
+ defer f.lock.Unlock()
+
+ if f.state == types.SpecStatePassed {
+ f.state = types.SpecStateSkipped
+ f.failure = types.SpecFailure{
+ Message: message,
+ Location: location,
+ }
+ }
+}
diff --git a/vendor/github.com/onsi/ginkgo/internal/failer/failer_suite_test.go b/vendor/github.com/onsi/ginkgo/internal/failer/failer_suite_test.go
new file mode 100644
index 000000000..8dce7be9a
--- /dev/null
+++ b/vendor/github.com/onsi/ginkgo/internal/failer/failer_suite_test.go
@@ -0,0 +1,13 @@
+package failer_test
+
+import (
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
+
+ "testing"
+)
+
+func TestFailer(t *testing.T) {
+ RegisterFailHandler(Fail)
+ RunSpecs(t, "Failer Suite")
+}
diff --git a/vendor/github.com/onsi/ginkgo/internal/failer/failer_test.go b/vendor/github.com/onsi/ginkgo/internal/failer/failer_test.go
new file mode 100644
index 000000000..65210a40a
--- /dev/null
+++ b/vendor/github.com/onsi/ginkgo/internal/failer/failer_test.go
@@ -0,0 +1,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))
+ })
+ })
+})