github.com/rakutentech/cli@v6.12.5-0.20151006231303-24468b65536e+incompatible/cf/requirements/cc_api_version_test.go (about) 1 package requirements_test 2 3 import ( 4 "fmt" 5 6 "github.com/cloudfoundry/cli/cf" 7 "github.com/cloudfoundry/cli/cf/configuration/core_config" 8 . "github.com/cloudfoundry/cli/cf/requirements" 9 testconfig "github.com/cloudfoundry/cli/testhelpers/configuration" 10 . "github.com/cloudfoundry/cli/testhelpers/matchers" 11 testterm "github.com/cloudfoundry/cli/testhelpers/terminal" 12 13 . "github.com/onsi/ginkgo" 14 . "github.com/onsi/gomega" 15 ) 16 17 var _ = Describe("CcApiVersion", func() { 18 var ( 19 ui *testterm.FakeUI 20 config core_config.Repository 21 req CCApiVersionRequirement 22 ) 23 24 BeforeEach(func() { 25 ui = new(testterm.FakeUI) 26 config = testconfig.NewRepository() 27 }) 28 29 Describe("success", func() { 30 Describe("when the cc api version has only major version", func() { 31 BeforeEach(func() { 32 config.SetApiVersion("1") 33 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 0, 0) 34 }) 35 36 It("should pass", func() { 37 Expect(req.Execute()).To(BeTrue()) 38 }) 39 }) 40 41 Describe("when the cc api version has only major and minor versions", func() { 42 BeforeEach(func() { 43 config.SetApiVersion("1.1") 44 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 1, 0) 45 }) 46 47 It("should pass", func() { 48 Expect(req.Execute()).To(BeTrue()) 49 }) 50 }) 51 52 Describe("when the cc api version has three dots", func() { 53 BeforeEach(func() { 54 config.SetApiVersion("1.1.1.1") 55 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 1, 1) 56 }) 57 58 It("should pass", func() { 59 Expect(req.Execute()).To(BeTrue()) 60 }) 61 }) 62 63 Describe("when the cc major version is trash", func() { 64 BeforeEach(func() { 65 config.SetApiVersion("garbage.1.1") 66 req = NewCCApiVersionRequirement(ui, config, "command-name", 0, 1, 1) 67 }) 68 69 It("should pass", func() { 70 Expect(req.Execute()).To(BeTrue()) 71 }) 72 }) 73 74 Describe("when the cc minor version is trash", func() { 75 BeforeEach(func() { 76 config.SetApiVersion("1.garbage.1") 77 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 0, 1) 78 }) 79 80 It("should pass", func() { 81 Expect(req.Execute()).To(BeTrue()) 82 }) 83 }) 84 85 Describe("when the cc patch version is trash", func() { 86 BeforeEach(func() { 87 config.SetApiVersion("1.1.garbage") 88 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 1, 0) 89 }) 90 91 It("should pass", func() { 92 Expect(req.Execute()).To(BeTrue()) 93 }) 94 }) 95 96 Describe("when cc major version is greater than the required major version", func() { 97 BeforeEach(func() { 98 config.SetApiVersion("2.0.0") 99 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 0, 0) 100 }) 101 102 It("should pass", func() { 103 Expect(req.Execute()).To(BeTrue()) 104 }) 105 }) 106 107 Describe("when cc minor version is greater than the require minor version", func() { 108 BeforeEach(func() { 109 config.SetApiVersion("2.1.0") 110 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 0, 0) 111 112 }) 113 It("should pass", func() { 114 Expect(req.Execute()).To(BeTrue()) 115 }) 116 }) 117 118 Describe("when cc patch version is greater than the required patch version", func() { 119 BeforeEach(func() { 120 config.SetApiVersion("2.1.1") 121 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 1, 0) 122 }) 123 124 It("should pass", func() { 125 Expect(req.Execute()).To(BeTrue()) 126 }) 127 }) 128 129 Describe("when the cc major, minor, and patch are equal to the required versions", func() { 130 BeforeEach(func() { 131 config.SetApiVersion("2.1.1") 132 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 1, 1) 133 }) 134 135 It("should pass", func() { 136 Expect(req.Execute()).To(BeTrue()) 137 }) 138 }) 139 140 Describe("when the cc major version is not higher than require and the minor and patch are", func() { 141 BeforeEach(func() { 142 config.SetApiVersion("9.2.2") 143 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 9, 9) 144 }) 145 146 It("should pass", func() { 147 Expect(req.Execute()).To(BeTrue()) 148 }) 149 }) 150 151 Describe("when the major and minor versions are higher than required and the patch is not", func() { 152 BeforeEach(func() { 153 config.SetApiVersion("9.9.2") 154 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 2, 9) 155 }) 156 157 It("should pass", func() { 158 Expect(req.Execute()).To(BeTrue()) 159 }) 160 }) 161 }) 162 163 Describe("failure", func() { 164 Describe("when cc major version is less than the required major version", func() { 165 BeforeEach(func() { 166 config.SetApiVersion("1.0.0") 167 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 0, 0) 168 }) 169 170 It("should fail", func() { 171 Expect(req.Execute()).To(BeFalse()) 172 }) 173 }) 174 175 Describe("when cc minor version is less than the required minor version", func() { 176 BeforeEach(func() { 177 config.SetApiVersion("2.0.0") 178 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 1, 0) 179 }) 180 181 It("should fail", func() { 182 Expect(req.Execute()).To(BeFalse()) 183 }) 184 }) 185 186 Describe("when cc patch version is less than the required patch version", func() { 187 BeforeEach(func() { 188 config.SetApiVersion("2.1.0") 189 req = NewCCApiVersionRequirement(ui, config, "command-name", 2, 1, 1) 190 }) 191 192 It("should fail", func() { 193 Expect(req.Execute()).To(BeFalse()) 194 }) 195 }) 196 197 Describe("output", func() { 198 BeforeEach(func() { 199 config.SetApiVersion("1.1.0") 200 req = NewCCApiVersionRequirement(ui, config, "command-name", 1, 1, 1) 201 req.Execute() 202 }) 203 204 It("should write to the ui", func() { 205 Expect(ui.Outputs).To(ContainSubstrings( 206 []string{"FAILED"}, 207 []string{fmt.Sprintf("Current CF CLI version %s", cf.Version)}, 208 []string{"Current CF API version 1.1.0"}, 209 []string{"To use the command-name feature, you need to upgrade the CF API to at least 1.1.1"}, 210 )) 211 }) 212 }) 213 }) 214 })