github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/requirements_test.go (about) 1 package requirements_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/requirements" 5 6 "code.cloudfoundry.org/cli/cf/requirements/requirementsfakes" 7 "errors" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Requirements", func() { 13 Context("When there are multiple requirements", func() { 14 It("executes all the requirements", func() { 15 r1 := new(requirementsfakes.FakeRequirement) 16 r1.ExecuteReturns(nil) 17 r2 := new(requirementsfakes.FakeRequirement) 18 r2.ExecuteReturns(nil) 19 20 // SETUP 21 requirements := Requirements{ 22 r1, 23 r2, 24 } 25 26 // EXECUTE 27 err := requirements.Execute() 28 29 // ASSERT 30 Expect(err).NotTo(HaveOccurred()) 31 Expect(r1.ExecuteCallCount()).To(Equal(1)) 32 Expect(r2.ExecuteCallCount()).To(Equal(1)) 33 }) 34 35 It("returns the first error that occurs", func() { 36 disaster := errors.New("OH NO") 37 otherDisaster := errors.New("WHAT!") 38 39 r1 := new(requirementsfakes.FakeRequirement) 40 r1.ExecuteReturns(disaster) 41 r2 := new(requirementsfakes.FakeRequirement) 42 r2.ExecuteReturns(otherDisaster) 43 44 // SETUP 45 requirements := Requirements{ 46 r1, 47 r2, 48 } 49 50 // EXECUTE 51 err := requirements.Execute() 52 53 // ASSERT 54 Expect(err).To(Equal(disaster)) 55 Expect(err).NotTo(Equal(otherDisaster)) 56 Expect(r1.ExecuteCallCount()).To(Equal(1)) 57 Expect(r2.ExecuteCallCount()).To(Equal(0)) 58 }) 59 }) 60 })