github.com/pf-qiu/concourse/v6@v6.7.3-0.20201207032516-1f455d73275f/fly/integration/version_test.go (about)

     1  package integration_test
     2  
     3  import (
     4  	"fmt"
     5  	"net/http"
     6  	"os"
     7  	"os/exec"
     8  
     9  	"github.com/pf-qiu/concourse/v6/atc"
    10  
    11  	"github.com/pf-qiu/concourse/v6/fly/version"
    12  	. "github.com/onsi/ginkgo"
    13  	. "github.com/onsi/gomega"
    14  
    15  	"github.com/onsi/gomega/gbytes"
    16  	"github.com/onsi/gomega/gexec"
    17  	"github.com/onsi/gomega/ghttp"
    18  )
    19  
    20  var _ = Describe("Version Checks", func() {
    21  	// patch version
    22  	var (
    23  		flyVersion       string
    24  		customAtcVersion string
    25  		flySession       *gexec.Session
    26  	)
    27  
    28  	BeforeEach(func() {
    29  		flyVersion = atcVersion
    30  
    31  		atcServer.AppendHandlers(
    32  			ghttp.CombineHandlers(
    33  				ghttp.VerifyRequest("GET", "/api/v1/teams/main/containers"),
    34  				ghttp.RespondWith(http.StatusOK, "[]"),
    35  			),
    36  		)
    37  	})
    38  
    39  	JustBeforeEach(func() {
    40  		atcServer.SetHandler(3,
    41  			ghttp.CombineHandlers(
    42  				ghttp.VerifyRequest("GET", "/api/v1/info"),
    43  				ghttp.RespondWithJSONEncoded(200, atc.Info{Version: customAtcVersion, WorkerVersion: workerVersion}),
    44  			),
    45  		)
    46  
    47  		flyCmd := exec.Command(flyPath, "-t", targetName, "containers")
    48  		flyCmd.Env = append(os.Environ(), "FAKE_FLY_VERSION="+flyVersion)
    49  
    50  		var err error
    51  		flySession, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
    52  		Expect(err).NotTo(HaveOccurred())
    53  	})
    54  
    55  	Describe("when the client and server differ by a patch version", func() {
    56  		BeforeEach(func() {
    57  			major, minor, patch, err := version.GetSemver(atcVersion)
    58  			Expect(err).NotTo(HaveOccurred())
    59  
    60  			customAtcVersion = fmt.Sprintf("%d.%d.%d", major, minor, patch+1)
    61  		})
    62  
    63  		It("warns the user that there is a difference", func() {
    64  			Eventually(flySession).Should(gexec.Exit(0))
    65  			Expect(flySession.Err).To(gbytes.Say(`fly version \(%s\) is out of sync with the target \(%s\). to sync up, run the following:\n\n    `, flyVersion, customAtcVersion))
    66  			Expect(flySession.Err).To(gbytes.Say(`fly.* -t %s sync\n`, targetName))
    67  		})
    68  	})
    69  
    70  	// when then match
    71  	Describe("when the client and server are the same version", func() {
    72  		BeforeEach(func() {
    73  			customAtcVersion = atcVersion
    74  		})
    75  
    76  		It("it doesn't give any warning message", func() {
    77  			Eventually(flySession).Should(gexec.Exit(0))
    78  			Expect(flySession.Err).ShouldNot(gbytes.Say("version"))
    79  		})
    80  	})
    81  
    82  	// minor version
    83  	Describe("when the client and server differ by a minor version", func() {
    84  		BeforeEach(func() {
    85  			major, minor, patch, err := version.GetSemver(atcVersion)
    86  			Expect(err).NotTo(HaveOccurred())
    87  
    88  			customAtcVersion = fmt.Sprintf("%d.%d.%d", major, minor+1, patch)
    89  		})
    90  
    91  		It("error and tell the user to sync", func() {
    92  			Eventually(flySession).Should(gexec.Exit(1))
    93  			Expect(flySession.Err).To(gbytes.Say(`fly version \(%s\) is out of sync with the target \(%s\). to sync up, run the following:\n\n    `, flyVersion, customAtcVersion))
    94  			Expect(flySession.Err).To(gbytes.Say(`fly.* -t %s sync\n`, targetName))
    95  			Expect(flySession.Err).To(gbytes.Say("cowardly refusing to run due to significant version discrepancy"))
    96  		})
    97  	})
    98  
    99  	// major version (same as minor)
   100  	Describe("when the client and server differ by a major version", func() {
   101  		BeforeEach(func() {
   102  			major, minor, patch, err := version.GetSemver(atcVersion)
   103  			Expect(err).NotTo(HaveOccurred())
   104  
   105  			customAtcVersion = fmt.Sprintf("%d.%d.%d", major+1, minor, patch)
   106  		})
   107  
   108  		It("error and tell the user to sync", func() {
   109  			Eventually(flySession).Should(gexec.Exit(1))
   110  			Expect(flySession.Err).To(gbytes.Say(`fly version \(%s\) is out of sync with the target \(%s\). to sync up, run the following:\n\n    `, flyVersion, customAtcVersion))
   111  			Expect(flySession.Err).To(gbytes.Say(`fly.* -t %s sync\n`, targetName))
   112  			Expect(flySession.Err).To(gbytes.Say("cowardly refusing to run due to significant version discrepancy"))
   113  		})
   114  	})
   115  
   116  	// dev version
   117  	Describe("when the client is a development version", func() {
   118  		BeforeEach(func() {
   119  			flyVersion = "0.0.0-dev"
   120  		})
   121  
   122  		It("never complains", func() {
   123  			Eventually(flySession).Should(gexec.Exit(0))
   124  			Expect(flySession.Err).ShouldNot(gbytes.Say("version"))
   125  		})
   126  	})
   127  })