github.com/willmadison/cli@v6.40.1-0.20181018160101-29d5937903ff+incompatible/cf/requirements/min_api_version_test.go (about)

     1  package requirements_test
     2  
     3  import (
     4  	"code.cloudfoundry.org/cli/cf/configuration/coreconfig"
     5  	"code.cloudfoundry.org/cli/cf/requirements"
     6  	"github.com/blang/semver"
     7  
     8  	testconfig "code.cloudfoundry.org/cli/cf/util/testhelpers/configuration"
     9  
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("MinAPIVersionRequirement", func() {
    15  	var (
    16  		config      coreconfig.Repository
    17  		requirement requirements.MinAPIVersionRequirement
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		config = testconfig.NewRepository()
    22  		requiredVersion, err := semver.Make("1.2.3")
    23  		Expect(err).NotTo(HaveOccurred())
    24  
    25  		requirement = requirements.NewMinAPIVersionRequirement(config, "version-restricted-feature", requiredVersion)
    26  	})
    27  
    28  	Context("Execute", func() {
    29  		Context("when the config's api version is greater than the required version", func() {
    30  			BeforeEach(func() {
    31  				config.SetAPIVersion("1.2.4")
    32  			})
    33  
    34  			It("succeeds", func() {
    35  				err := requirement.Execute()
    36  				Expect(err).NotTo(HaveOccurred())
    37  			})
    38  		})
    39  
    40  		Context("when the config's api version is equal to the required version", func() {
    41  			BeforeEach(func() {
    42  				config.SetAPIVersion("1.2.3")
    43  			})
    44  
    45  			It("succeeds", func() {
    46  				err := requirement.Execute()
    47  				Expect(err).NotTo(HaveOccurred())
    48  			})
    49  		})
    50  
    51  		Context("when the config's api version is less than the required version", func() {
    52  			BeforeEach(func() {
    53  				config.SetAPIVersion("1.2.2")
    54  			})
    55  
    56  			It("errors", func() {
    57  				err := requirement.Execute()
    58  				Expect(err.Error()).To(ContainSubstring("version-restricted-feature requires CF API version 1.2.3 or higher. Your target is 1.2.2."))
    59  			})
    60  		})
    61  
    62  		Context("when the config's api version can not be parsed", func() {
    63  			BeforeEach(func() {
    64  				config.SetAPIVersion("-")
    65  			})
    66  
    67  			It("errors", func() {
    68  				err := requirement.Execute()
    69  				Expect(err.Error()).To(ContainSubstring("Unable to parse CC API Version '-'"))
    70  			})
    71  		})
    72  
    73  		Context("when the config's api version is empty", func() {
    74  			BeforeEach(func() {
    75  				config.SetAPIVersion("")
    76  			})
    77  
    78  			It("errors", func() {
    79  				err := requirement.Execute()
    80  				Expect(err.Error()).To(ContainSubstring("Unable to determine CC API Version. Please log in again."))
    81  			})
    82  		})
    83  	})
    84  })