initial commit
[govpp.git] / vendor / github.com / onsi / gomega / matchers / have_occurred_matcher_test.go
1 package matchers_test
2
3 import (
4         "errors"
5         . "github.com/onsi/ginkgo"
6         . "github.com/onsi/gomega"
7         . "github.com/onsi/gomega/matchers"
8 )
9
10 type CustomErr struct {
11         msg string
12 }
13
14 func (e *CustomErr) Error() string {
15         return e.msg
16 }
17
18 var _ = Describe("HaveOccurred", func() {
19         It("should succeed if matching an error", func() {
20                 Ω(errors.New("Foo")).Should(HaveOccurred())
21         })
22
23         It("should not succeed with nil", func() {
24                 Ω(nil).ShouldNot(HaveOccurred())
25         })
26
27         It("should only support errors and nil", func() {
28                 success, err := (&HaveOccurredMatcher{}).Match("foo")
29                 Ω(success).Should(BeFalse())
30                 Ω(err).Should(HaveOccurred())
31
32                 success, err = (&HaveOccurredMatcher{}).Match("")
33                 Ω(success).Should(BeFalse())
34                 Ω(err).Should(HaveOccurred())
35         })
36
37         It("doesn't support non-error type", func() {
38                 success, err := (&HaveOccurredMatcher{}).Match(AnyType{})
39                 Ω(success).Should(BeFalse())
40                 Ω(err).Should(MatchError("Expected an error-type.  Got:\n    <matchers_test.AnyType>: {}"))
41         })
42
43         It("doesn't support non-error pointer type", func() {
44                 success, err := (&HaveOccurredMatcher{}).Match(&AnyType{})
45                 Ω(success).Should(BeFalse())
46                 Ω(err).Should(MatchError(MatchRegexp(`Expected an error-type.  Got:\n    <*matchers_test.AnyType | 0x[[:xdigit:]]+>: {}`)))
47         })
48
49         It("should succeed with pointer types that conform to error interface", func() {
50                 err := &CustomErr{"ohai"}
51                 Ω(err).Should(HaveOccurred())
52         })
53
54         It("should not succeed with nil pointers to types that conform to error interface", func() {
55                 var err *CustomErr = nil
56                 Ω(err).ShouldNot(HaveOccurred())
57         })
58 })