github.com/DaAlbrecht/cf-cli@v0.0.0-20231128151943-1fe19bb400b9/actor/versioncheck/minimum_version_check_test.go (about) 1 package versioncheck_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/actor/versioncheck" 5 6 . "github.com/onsi/ginkgo" 7 . "github.com/onsi/gomega" 8 ) 9 10 var _ = Describe("IsMinimumAPIVersionMet", func() { 11 12 var ( 13 executeErr error 14 minimumVersion string 15 currentVersion string 16 minAPIVersionMet bool 17 ) 18 19 BeforeEach(func() { 20 currentVersion = "1.0.0" 21 minimumVersion = "1.0.0" 22 }) 23 24 JustBeforeEach(func() { 25 minAPIVersionMet, executeErr = IsMinimumAPIVersionMet(currentVersion, minimumVersion) 26 }) 27 28 Context("if the current version is not a valid semver", func() { 29 BeforeEach(func() { 30 currentVersion = "asfd" 31 }) 32 33 It("raises an error", func() { 34 Expect(executeErr).To(HaveOccurred()) 35 }) 36 }) 37 38 Context("if the minimum version is not a valid semver", func() { 39 BeforeEach(func() { 40 minimumVersion = "asfd" 41 }) 42 43 It("raises an error", func() { 44 Expect(executeErr).To(HaveOccurred()) 45 }) 46 }) 47 48 Context("minimum version is empty", func() { 49 BeforeEach(func() { 50 minimumVersion = "" 51 }) 52 53 It("returns true with no errors", func() { 54 Expect(minAPIVersionMet).To(Equal(true)) 55 Expect(executeErr).ToNot(HaveOccurred()) 56 }) 57 }) 58 59 Context("current version is less than min", func() { 60 BeforeEach(func() { 61 currentVersion = "3.22.0" 62 minimumVersion = "3.25.0" 63 }) 64 65 It("returns true", func() { 66 Expect(minAPIVersionMet).To(Equal(false)) 67 Expect(executeErr).ToNot(HaveOccurred()) 68 }) 69 }) 70 71 Context("current version is greater than or equal to min", func() { 72 BeforeEach(func() { 73 currentVersion = "3.26.0" 74 minimumVersion = "3.25.0" 75 }) 76 77 It("returns true", func() { 78 Expect(minAPIVersionMet).To(Equal(true)) 79 Expect(executeErr).ToNot(HaveOccurred()) 80 }) 81 }) 82 })