github.com/sleungcy-sap/cli@v7.1.0+incompatible/cf/requirements/max_api_version_test.go (about) 1 package requirements_test 2 3 import ( 4 "code.cloudfoundry.org/cli/cf/configuration/coreconfig" 5 "code.cloudfoundry.org/cli/cf/requirements" 6 "github.com/blang/semver" 7 8 testconfig "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration" 9 10 . "github.com/onsi/ginkgo" 11 . "github.com/onsi/gomega" 12 ) 13 14 var _ = Describe("MaxAPIVersionRequirement", func() { 15 var ( 16 config coreconfig.Repository 17 requirement requirements.MaxAPIVersionRequirement 18 ) 19 20 BeforeEach(func() { 21 config = testconfig.NewRepository() 22 maximumVersion, err := semver.Make("1.2.3") 23 Expect(err).NotTo(HaveOccurred()) 24 25 requirement = requirements.NewMaxAPIVersionRequirement(config, "version-restricted-feature", maximumVersion) 26 }) 27 28 Context("Execute", func() { 29 Context("when the config's api version is less than the maximum version", func() { 30 BeforeEach(func() { 31 config.SetAPIVersion("1.2.2") 32 }) 33 34 It("succeeds", func() { 35 err := requirement.Execute() 36 Expect(err).NotTo(HaveOccurred()) 37 }) 38 }) 39 40 Context("when the config's api version is equal to the maximum version", func() { 41 BeforeEach(func() { 42 config.SetAPIVersion("1.2.3") 43 }) 44 45 It("succeeds", func() { 46 err := requirement.Execute() 47 Expect(err).NotTo(HaveOccurred()) 48 }) 49 }) 50 51 Context("when the config's api version is greater than the maximum version", func() { 52 BeforeEach(func() { 53 config.SetAPIVersion("1.2.4") 54 }) 55 56 It("returns an error", func() { 57 err := requirement.Execute() 58 Expect(err).To(HaveOccurred()) 59 Expect(err.Error()).To(ContainSubstring("version-restricted-feature only works up to CF API version 1.2.3. Your target is 1.2.4.")) 60 }) 61 }) 62 63 Context("when the config's api version can not be parsed", func() { 64 BeforeEach(func() { 65 config.SetAPIVersion("-") 66 }) 67 68 It("returns an error", func() { 69 err := requirement.Execute() 70 Expect(err).To(HaveOccurred()) 71 Expect(err.Error()).To(ContainSubstring("Unable to parse CC API Version '-'")) 72 }) 73 }) 74 75 Context("when the config's api version is empty", func() { 76 BeforeEach(func() { 77 config.SetAPIVersion("") 78 }) 79 80 It("returns an error", func() { 81 err := requirement.Execute() 82 Expect(err).To(HaveOccurred()) 83 Expect(err.Error()).To(ContainSubstring("Unable to determine CC API Version. Please log in again.")) 84 }) 85 }) 86 }) 87 })