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