github.com/loggregator/cli@v6.33.1-0.20180224010324-82334f081791+incompatible/command/minimum_version_check_test.go (about) 1 package command_test 2 3 import ( 4 . "code.cloudfoundry.org/cli/command" 5 "code.cloudfoundry.org/cli/command/translatableerror" 6 "code.cloudfoundry.org/cli/version" 7 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 ) 11 12 var _ = Describe("Minimum Version Check", func() { 13 Describe("MinimumAPIVersionCheck", func() { 14 minimumVersion := "1.0.0" 15 Context("current version is greater than min", func() { 16 It("does not return an error", func() { 17 currentVersion := "1.0.1" 18 err := MinimumAPIVersionCheck(currentVersion, minimumVersion) 19 Expect(err).ToNot(HaveOccurred()) 20 }) 21 }) 22 23 Context("current version is less than min", func() { 24 It("does return an error", func() { 25 currentVersion := "1.0.0-alpha.5" 26 err := MinimumAPIVersionCheck(currentVersion, minimumVersion) 27 Expect(err).To(MatchError(translatableerror.MinimumAPIVersionNotMetError{ 28 CurrentVersion: currentVersion, 29 MinimumVersion: minimumVersion, 30 })) 31 }) 32 33 Context("when a custom command is provided", func() { 34 currentVersion := "1.0.0-alpha.5" 35 It("sets the command on the MinimumAPIVersionNotMetError", func() { 36 err := MinimumAPIVersionCheck(currentVersion, minimumVersion, "some-command") 37 Expect(err).To(MatchError(translatableerror.MinimumAPIVersionNotMetError{ 38 Command: "some-command", 39 CurrentVersion: currentVersion, 40 MinimumVersion: minimumVersion, 41 })) 42 }) 43 }) 44 }) 45 46 Context("current version is the default version", func() { 47 It("does not return an error", func() { 48 err := MinimumAPIVersionCheck(version.DefaultVersion, minimumVersion) 49 Expect(err).ToNot(HaveOccurred()) 50 }) 51 }) 52 53 Context("minimum version is empty", func() { 54 It("does not return an error", func() { 55 err := MinimumAPIVersionCheck("2.0.0", "") 56 Expect(err).ToNot(HaveOccurred()) 57 }) 58 }) 59 }) 60 })