Exemplo n.º 1
0
func ValidateClient(client concourse.Client, targetName TargetName) error {
	info, err := client.GetInfo()
	if err != nil {
		return err
	}

	if info.Version == version.Version || version.IsDev(version.Version) {
		return nil
	}

	atcMajor, atcMinor, atcPatch, err := version.GetSemver(info.Version)
	if err != nil {
		return err
	}

	flyMajor, flyMinor, flyPatch, err := version.GetSemver(version.Version)
	if err != nil {
		return err
	}

	if ((atcMajor == flyMajor) && (atcMinor != flyMinor)) ||
		(atcMajor != flyMajor) {
		return NewErrVersionMismatch(version.Version, info.Version, targetName)
	}

	if (atcMajor == flyMajor) && (atcMinor == flyMinor) && (atcPatch != flyPatch) {
		fmt.Fprintln(os.Stderr, ui.WarningColor("WARNING:\n"))
		fmt.Fprintln(os.Stderr, ui.WarningColor(NewErrVersionMismatch(version.Version, info.Version, targetName).Error()))
	}

	return nil
}
Exemplo n.º 2
0
	JustBeforeEach(func() {
		flyPath, err := gexec.Build(
			"github.com/concourse/fly",
			"-ldflags", fmt.Sprintf("-X github.com/concourse/fly/version.Version=%s", flyVersion),
		)
		Expect(err).NotTo(HaveOccurred())

		flyCmd := exec.Command(flyPath, "-t", targetName, "containers")

		flySession, err = gexec.Start(flyCmd, GinkgoWriter, GinkgoWriter)
		Expect(err).NotTo(HaveOccurred())
	})

	Describe("when the client and server differ by a patch version", func() {
		BeforeEach(func() {
			major, minor, patch, err := version.GetSemver(atcVersion)
			Expect(err).NotTo(HaveOccurred())

			flyVersion = fmt.Sprintf("%d.%d.%d", major, minor, patch+1)
		})

		It("warns the user that there is a difference", func() {
			Eventually(flySession).Should(gexec.Exit(0))
			Expect(flySession.Err).To(gbytes.Say(`fly version \(%s\) is out of sync with the target \(%s\). to sync up, run the following:`, flyVersion, atcVersion))
			Expect(flySession.Err).To(gbytes.Say(`    fly -t %s sync\n`, targetName))
		})
	})

	// when then match
	Describe("when the client and server are the same version", func() {
		BeforeEach(func() {