github.com/nimakaviani/cli@v6.37.1-0.20180619223813-e734901a73fa+incompatible/command/api_version_warning_test.go (about) 1 package command_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/command" 5 "code.cloudfoundry.org/cli/command/commandfakes" 6 "code.cloudfoundry.org/cli/util/ui" 7 "code.cloudfoundry.org/cli/version" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/gbytes" 11 ) 12 13 var _ = Describe("WarnCLIVersionCheck", func() { 14 var ( 15 testUI *ui.UI 16 fakeConfig *commandfakes.FakeConfig 17 apiVersion string 18 minCLIVersion string 19 binaryVersion string 20 ) 21 22 BeforeEach(func() { 23 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 24 fakeConfig = new(commandfakes.FakeConfig) 25 26 apiVersion = "100.200.3" 27 fakeConfig.APIVersionReturns(apiVersion) 28 minCLIVersion = "1.0.0" 29 fakeConfig.MinCLIVersionReturns(minCLIVersion) 30 binaryVersion = "1.0.0" 31 fakeConfig.BinaryVersionReturns(binaryVersion) 32 }) 33 34 Context("when checking the cloud controller minimum version warning", func() { 35 Context("when the CLI version is less than the recommended minimum", func() { 36 BeforeEach(func() { 37 binaryVersion = "0.0.0" 38 fakeConfig.BinaryVersionReturns(binaryVersion) 39 }) 40 41 It("displays a recommendation to update the CLI version", func() { 42 err := WarnCLIVersionCheck(fakeConfig, testUI) 43 Expect(testUI.Err).To(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion)) 44 Expect(err).ToNot(HaveOccurred()) 45 }) 46 }) 47 }) 48 49 Context("when the CLI version is greater or equal to the recommended minimum", func() { 50 BeforeEach(func() { 51 binaryVersion = "1.0.0" 52 fakeConfig.BinaryVersionReturns(binaryVersion) 53 }) 54 55 It("does not display a recommendation to update the CLI version", func() { 56 err := WarnCLIVersionCheck(fakeConfig, testUI) 57 Expect(err).ToNot(HaveOccurred()) 58 Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion)) 59 }) 60 }) 61 62 Context("when an error is encountered while parsing the semver versions", func() { 63 BeforeEach(func() { 64 fakeConfig.BinaryVersionReturns("&#%") 65 }) 66 67 It("does not recommend to update the CLI version", func() { 68 err := WarnCLIVersionCheck(fakeConfig, testUI) 69 Expect(err).To(HaveOccurred()) 70 Expect(err.Error()).To(Equal("No Major.Minor.Patch elements found")) 71 Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion)) 72 }) 73 }) 74 75 Context("version contains string", func() { 76 BeforeEach(func() { 77 minCLIVersion = "1.0.0" 78 fakeConfig.MinCLIVersionReturns(minCLIVersion) 79 binaryVersion = "1.0.0-alpha.5" 80 fakeConfig.BinaryVersionReturns(binaryVersion) 81 }) 82 83 It("parses the versions successfully and recommends to update the CLI version", func() { 84 err := WarnCLIVersionCheck(fakeConfig, testUI) 85 Expect(err).ToNot(HaveOccurred()) 86 Expect(testUI.Err).To(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion)) 87 }) 88 }) 89 90 Context("minimum version is empty", func() { 91 BeforeEach(func() { 92 minCLIVersion = "" 93 fakeConfig.MinCLIVersionReturns(minCLIVersion) 94 binaryVersion = "1.0.0" 95 fakeConfig.BinaryVersionReturns(binaryVersion) 96 }) 97 98 It("does not return an error", func() { 99 err := WarnCLIVersionCheck(fakeConfig, testUI) 100 Expect(err).ToNot(HaveOccurred()) 101 }) 102 }) 103 104 Context("when comparing the default versions", func() { 105 BeforeEach(func() { 106 minCLIVersion = "1.2.3" 107 fakeConfig.MinCLIVersionReturns(minCLIVersion) 108 binaryVersion = version.DefaultVersion 109 fakeConfig.BinaryVersionReturns(binaryVersion) 110 }) 111 112 It("does not return an error or print a warning", func() { 113 err := WarnCLIVersionCheck(fakeConfig, testUI) 114 Expect(err).ToNot(HaveOccurred()) 115 }) 116 }) 117 }) 118 119 var _ = Describe("WarnAPIVersionCheck", func() { 120 var ( 121 testUI *ui.UI 122 123 apiVersion string 124 ) 125 126 BeforeEach(func() { 127 testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer()) 128 }) 129 130 Context("when checking the cloud controller minimum version warning", func() { 131 Context("when checking for outdated API version", func() { 132 Context("when the API version is older than the minimum supported API version", func() { 133 BeforeEach(func() { 134 apiVersion = "2.68.0" 135 }) 136 137 It("outputs a warning telling the user to upgrade their CF version", func() { 138 err := WarnAPIVersionCheck(apiVersion, testUI) 139 Expect(err).ToNot(HaveOccurred()) 140 Expect(testUI.Err).To(Say("Your API version is no longer supported. Upgrade to a newer version of the API")) 141 }) 142 }) 143 144 Context("when the API version is newer than the minimum supported API version", func() { 145 BeforeEach(func() { 146 apiVersion = "2.80.0" 147 }) 148 149 It("continues silently", func() { 150 err := WarnAPIVersionCheck(apiVersion, testUI) 151 Expect(err).ToNot(HaveOccurred()) 152 Expect(testUI.Err).NotTo(Say("Your API version is no longer supported. Upgrade to a newer version of the API")) 153 }) 154 }) 155 }) 156 }) 157 })