github.com/cloudfoundry/cli@v7.1.0+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("MinimumCFAPIVersionCheck", 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 := MinimumCCAPIVersionCheck(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 := MinimumCCAPIVersionCheck(currentVersion, minimumVersion)
    27  				Expect(err).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{
    28  					CurrentVersion: currentVersion,
    29  					MinimumVersion: minimumVersion,
    30  				}))
    31  			})
    32  
    33  			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 := MinimumCCAPIVersionCheck(currentVersion, minimumVersion, "some-command")
    37  					Expect(err).To(MatchError(translatableerror.MinimumCFAPIVersionNotMetError{
    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 := MinimumCCAPIVersionCheck(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 := MinimumCCAPIVersionCheck("2.0.0", "")
    56  				Expect(err).ToNot(HaveOccurred())
    57  			})
    58  		})
    59  	})
    60  
    61  	Describe("MinimumUAAAPIVersionCheck", func() {
    62  		minimumVersion := "1.0.0"
    63  		Context("current version is greater than min", func() {
    64  			It("does not return an error", func() {
    65  				currentVersion := "1.0.1"
    66  				err := MinimumUAAAPIVersionCheck(currentVersion, minimumVersion)
    67  				Expect(err).ToNot(HaveOccurred())
    68  			})
    69  		})
    70  
    71  		Context("current version is less than min", func() {
    72  			It("does return an error", func() {
    73  				currentVersion := "1.0.0-alpha.5"
    74  				err := MinimumUAAAPIVersionCheck(currentVersion, minimumVersion)
    75  				Expect(err).To(MatchError(translatableerror.MinimumUAAAPIVersionNotMetError{
    76  					MinimumVersion: minimumVersion,
    77  				}))
    78  			})
    79  
    80  			When("a custom command is provided", func() {
    81  				currentVersion := "1.0.0-alpha.5"
    82  				It("sets the command on the MinimumAPIVersionNotMetError", func() {
    83  					err := MinimumUAAAPIVersionCheck(currentVersion, minimumVersion, "some-command")
    84  					Expect(err).To(MatchError(translatableerror.MinimumUAAAPIVersionNotMetError{
    85  						Command:        "some-command",
    86  						MinimumVersion: minimumVersion,
    87  					}))
    88  				})
    89  			})
    90  		})
    91  
    92  		Context("current version is the default version", func() {
    93  			It("does not return an error", func() {
    94  				err := MinimumUAAAPIVersionCheck(version.DefaultVersion, minimumVersion)
    95  				Expect(err).ToNot(HaveOccurred())
    96  			})
    97  		})
    98  
    99  		Context("minimum version is empty", func() {
   100  			It("does not return an error", func() {
   101  				err := MinimumUAAAPIVersionCheck("2.0.0", "")
   102  				Expect(err).ToNot(HaveOccurred())
   103  			})
   104  		})
   105  	})
   106  })