github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/usage_requirement_test.go (about) 1 package requirements_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/cf/requirements" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 ) 8 9 var _ = Describe("UsageRequirement", func() { 10 It("doesn't return an error when the predicate returns false", func() { 11 err := NewUsageRequirement(nil, "Some error message", func() bool { return false }).Execute() 12 Expect(err).NotTo(HaveOccurred()) 13 }) 14 15 It("errors when the predicate returns true", func() { 16 usableCmd := usableFunc(func() string { return "Usage text!" }) 17 18 err := NewUsageRequirement(usableCmd, "Some error message", func() bool { return true }).Execute() 19 20 Expect(err).To(HaveOccurred()) 21 Expect(err.Error()).To(ContainSubstring("Some error message")) 22 23 Expect(err.Error()).To(ContainSubstring("Usage text!")) 24 }) 25 }) 26 27 type usableFunc func() string 28 29 func (u usableFunc) Usage() string { return u() }