github.com/mook-as/cf-cli@v7.0.0-beta.28.0.20200120190804-b91c115fae48+incompatible/cf/util/testhelpers/matchers/match_func_name_test.go (about) 1 package matchers_test 2 3 import ( 4 "errors" 5 6 . "code.cloudfoundry.org/cli/cf/util/testhelpers/matchers" 7 . "github.com/onsi/ginkgo" 8 "github.com/onsi/gomega" 9 . "github.com/onsi/gomega" 10 ) 11 12 func dummyFunc() {} 13 func dummyNotMatchFunc() {} 14 15 var _ = Describe("MatchChangeAppFuncsByName", func() { 16 var ( 17 matcher gomega.OmegaMatcher 18 actual interface{} 19 expected interface{} 20 ) 21 22 Describe("Match", func() { 23 var ( 24 success bool 25 executeErr error 26 ) 27 28 BeforeEach(func() { 29 expected = dummyFunc 30 }) 31 32 JustBeforeEach(func() { 33 matcher = MatchFuncsByName(expected) 34 35 success, executeErr = matcher.Match(actual) 36 }) 37 38 When("Expected is not a list of funcs", func() { 39 BeforeEach(func() { 40 expected = "hello" 41 }) 42 43 It("returns an error", func() { 44 Expect(success).To(BeFalse()) 45 Expect(executeErr).To(MatchError(errors.New("MatchChangeAppFuncsByName: Expected must be a slice of functions, got string"))) 46 }) 47 }) 48 49 When("Actual is not a slice", func() { 50 BeforeEach(func() { 51 actual = true 52 }) 53 54 It("returns an error", func() { 55 Expect(success).To(BeFalse()) 56 Expect(executeErr).To(MatchError(errors.New("MatchChangeAppFuncsByName: Actual must be a slice of functions, got bool"))) 57 }) 58 }) 59 60 When("Actual is not a slice of funcs", func() { 61 BeforeEach(func() { 62 actual = []int{5} 63 }) 64 65 It("returns an error", func() { 66 Expect(success).To(BeFalse()) 67 Expect(executeErr).To(MatchError(errors.New("MatchChangeAppFuncsByName: Actual must be a slice of functions, got int"))) 68 }) 69 }) 70 71 When("Actual does not match expected", func() { 72 BeforeEach(func() { 73 actual = []func(){dummyNotMatchFunc} 74 }) 75 76 It("returns an error", func() { 77 Expect(success).To(BeFalse()) 78 Expect(executeErr).To(BeNil()) 79 }) 80 }) 81 82 When("Actual does match expected", func() { 83 BeforeEach(func() { 84 actual = []func(){dummyFunc} 85 }) 86 87 It("returns an error", func() { 88 Expect(success).To(BeTrue()) 89 Expect(executeErr).To(BeNil()) 90 }) 91 }) 92 }) 93 94 Describe("FailureMessage", func() { 95 It("shows expected and actual", func() { 96 matcher = MatchFuncsByName(dummyFunc) 97 matcher.Match([]func(){dummyNotMatchFunc}) 98 Expect(matcher.FailureMessage("does not matter")).To(MatchRegexp("(?s)dummyFunc.*to match actual.*dummyNotMatchFunc")) 99 }) 100 }) 101 102 Describe("NegatedFaileureMessage", func() { 103 It("shows expected and actual", func() { 104 matcher = MatchFuncsByName(dummyFunc) 105 matcher.Match([]func(){dummyNotMatchFunc}) 106 Expect(matcher.NegatedFailureMessage("does not matter")).To(MatchRegexp("(?s)dummyFunc.*not to match actual.*dummyNotMatchFunc")) 107 }) 108 }) 109 })