github.com/asifdxtreme/cli@v6.1.3-0.20150123051144-9ead8700b4ae+incompatible/cf/api/strategy/version_test.go (about) 1 package strategy_test 2 3 import ( 4 . "github.com/cloudfoundry/cli/cf/api/strategy" 5 . "github.com/onsi/ginkgo" 6 . "github.com/onsi/gomega" 7 ) 8 9 var _ = Describe("api version", func() { 10 Describe("parsing", func() { 11 It("parses the major, minor and patch numbers", func() { 12 version, err := ParseVersion("1.2.3") 13 Expect(err).NotTo(HaveOccurred()) 14 Expect(version).To(Equal(Version{Major: 1, Minor: 2, Patch: 3})) 15 }) 16 17 It("returns an error when there aren't three numbers", func() { 18 _, err := ParseVersion("1.2") 19 Expect(err).To(HaveOccurred()) 20 21 _, err = ParseVersion("1.2.3.4") 22 Expect(err).To(HaveOccurred()) 23 }) 24 25 It("returns an error when there are non-digits in the version numbers", func() { 26 _, err := ParseVersion("1.2.x") 27 Expect(err).To(HaveOccurred()) 28 29 _, err = ParseVersion("1.x.2") 30 Expect(err).To(HaveOccurred()) 31 32 _, err = ParseVersion("x.2.3") 33 Expect(err).To(HaveOccurred()) 34 }) 35 }) 36 37 Describe("comparisons", func() { 38 It("compares the major version", func() { 39 Expect(Version{Major: 1, Minor: 2, Patch: 3}.LessThan(Version{Major: 2, Minor: 1, Patch: 1})).To(BeTrue()) 40 Expect(Version{Major: 2, Minor: 1, Patch: 1}.LessThan(Version{Major: 1, Minor: 3, Patch: 3})).To(BeFalse()) 41 }) 42 43 It("compares the minor version", func() { 44 Expect(Version{Major: 1, Minor: 2, Patch: 3}.LessThan(Version{Major: 1, Minor: 3, Patch: 1})).To(BeTrue()) 45 Expect(Version{Major: 1, Minor: 3, Patch: 1}.LessThan(Version{Major: 1, Minor: 1, Patch: 100})).To(BeFalse()) 46 }) 47 48 It("compares the patch version", func() { 49 Expect(Version{Major: 1, Minor: 2, Patch: 3}.LessThan(Version{Major: 1, Minor: 2, Patch: 42})).To(BeTrue()) 50 Expect(Version{Major: 1, Minor: 2, Patch: 42}.LessThan(Version{Major: 1, Minor: 2, Patch: 3})).To(BeFalse()) 51 }) 52 }) 53 })