github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/command/api_version_warning_test.go (about)

     1  package command_test
     2  
     3  import (
     4  	. "github.com/liamawhite/cli-with-i18n/command"
     5  	"github.com/liamawhite/cli-with-i18n/command/commandfakes"
     6  	"github.com/liamawhite/cli-with-i18n/util/ui"
     7  	"github.com/liamawhite/cli-with-i18n/version"
     8  	. "github.com/onsi/ginkgo"
     9  	. "github.com/onsi/gomega"
    10  	. "github.com/onsi/gomega/gbytes"
    11  )
    12  
    13  var _ = Describe("WarnAPIVersionCheck", func() {
    14  	var (
    15  		testUI        *ui.UI
    16  		fakeConfig    *commandfakes.FakeConfig
    17  		apiVersion    string
    18  		minCLIVersion string
    19  		binaryVersion string
    20  	)
    21  
    22  	BeforeEach(func() {
    23  		testUI = ui.NewTestUI(nil, NewBuffer(), NewBuffer())
    24  		fakeConfig = new(commandfakes.FakeConfig)
    25  
    26  		apiVersion = "1.2.3"
    27  		fakeConfig.APIVersionReturns(apiVersion)
    28  		minCLIVersion = "1.0.0"
    29  		fakeConfig.MinCLIVersionReturns(minCLIVersion)
    30  	})
    31  
    32  	Context("when checking the cloud controller minimum version warning", func() {
    33  		Context("when the CLI version is less than the recommended minimum", func() {
    34  			BeforeEach(func() {
    35  				binaryVersion = "0.0.0"
    36  				fakeConfig.BinaryVersionReturns(binaryVersion)
    37  			})
    38  
    39  			It("displays a recommendation to update the CLI version", func() {
    40  				err := WarnAPIVersionCheck(fakeConfig, testUI)
    41  				Expect(testUI.Err).To(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
    42  				Expect(err).ToNot(HaveOccurred())
    43  			})
    44  		})
    45  	})
    46  
    47  	Context("when the CLI version is greater or equal to the recommended minimum", func() {
    48  		BeforeEach(func() {
    49  			binaryVersion = "1.0.0"
    50  			fakeConfig.BinaryVersionReturns(binaryVersion)
    51  		})
    52  
    53  		It("does not display a recommendation to update the CLI version", func() {
    54  			err := WarnAPIVersionCheck(fakeConfig, testUI)
    55  			Expect(err).ToNot(HaveOccurred())
    56  			Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
    57  		})
    58  	})
    59  
    60  	Context("when an error is encountered while parsing the semver versions", func() {
    61  		BeforeEach(func() {
    62  			fakeConfig.BinaryVersionReturns("&#%")
    63  		})
    64  
    65  		It("does not recommend to update the CLI version", func() {
    66  			err := WarnAPIVersionCheck(fakeConfig, testUI)
    67  			Expect(err).To(HaveOccurred())
    68  			Expect(err.Error()).To(Equal("No Major.Minor.Patch elements found"))
    69  			Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s.", apiVersion, minCLIVersion))
    70  		})
    71  	})
    72  
    73  	Context("version contains string", func() {
    74  		BeforeEach(func() {
    75  			minCLIVersion = "1.0.0"
    76  			fakeConfig.MinCLIVersionReturns(minCLIVersion)
    77  			binaryVersion = "1.0.0-alpha.5"
    78  			fakeConfig.BinaryVersionReturns(binaryVersion)
    79  		})
    80  
    81  		It("does not return an error", func() {
    82  			err := WarnAPIVersionCheck(fakeConfig, testUI)
    83  			Expect(err).ToNot(HaveOccurred())
    84  			Expect(testUI.Err).To(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
    85  		})
    86  	})
    87  
    88  	Context("minimum version is empty", func() {
    89  		BeforeEach(func() {
    90  			minCLIVersion = ""
    91  			fakeConfig.MinCLIVersionReturns(minCLIVersion)
    92  			binaryVersion = "1.0.0"
    93  			fakeConfig.BinaryVersionReturns(binaryVersion)
    94  		})
    95  
    96  		It("does not return an error", func() {
    97  			err := WarnAPIVersionCheck(fakeConfig, testUI)
    98  			Expect(err).ToNot(HaveOccurred())
    99  			Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
   100  		})
   101  	})
   102  
   103  	Context("when comparing the default versions", func() {
   104  		BeforeEach(func() {
   105  			minCLIVersion = "1.2.3"
   106  			fakeConfig.MinCLIVersionReturns(minCLIVersion)
   107  			binaryVersion = version.DefaultVersion
   108  			fakeConfig.BinaryVersionReturns(binaryVersion)
   109  		})
   110  
   111  		It("does not return an error", func() {
   112  			err := WarnAPIVersionCheck(fakeConfig, testUI)
   113  			Expect(err).ToNot(HaveOccurred())
   114  			Expect(testUI.Err).NotTo(Say("Cloud Foundry API version %s requires CLI version %s. You are currently on version %s. To upgrade your CLI, please visit: https://github.com/cloudfoundry/cli#downloads", apiVersion, minCLIVersion, binaryVersion))
   115  		})
   116  	})
   117  })