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