outputBuffer *gbytes.Buffer terminalUI terminal.UI fakeExitHandler *fake_exit_handler.FakeExitHandler fakeVersionManager *fake_version_manager.FakeVersionManager commandFactory *command_factory.VersionCommandFactory ) BeforeEach(func() { config = config_package.New(nil) config.SetTarget("lattice.xip.io") outputBuffer = gbytes.NewBuffer() terminalUI = terminal.NewUI(nil, outputBuffer, nil) fakeExitHandler = &fake_exit_handler.FakeExitHandler{} fakeVersionManager = &fake_version_manager.FakeVersionManager{} fakeVersionManager.LatticeVersionReturns("some-client-lattice-sha") commandFactory = command_factory.NewVersionCommandFactory( config, terminalUI, fakeExitHandler, "darwin", "/fake/ltc", fakeVersionManager) }) Describe("Version Command", func() { var versionCommand cli.Command BeforeEach(func() { versionCommand = commandFactory.MakeVersionCommand() fakeVersionManager.ServerVersionsReturns(version.ServerVersions{
fakeTargetVerifier.VerifyTargetReturns(true, false, errors.New("Unknown Error")) test_helpers.ExecuteCommandWithArgs(targetCommand, []string{"newtarget.com"}) Expect(outputBuffer).To(test_helpers.SayLine("Error verifying target: Unknown Error")) verifyOldTargetStillSet() Expect(fakeExitHandler.ExitCalledWith).To(Equal([]int{exit_codes.BadTarget})) }) }) Context("checking ltc target version", func() { BeforeEach(func() { fakeTargetVerifier.VerifyTargetReturns(true, true, nil) fakeBlobStoreVerifier.VerifyReturns(true, nil) fakeVersionManager.LatticeVersionReturns("some-version") }) It("should print warning and recommend sync if ltc version does not match server", func() { fakeVersionManager.LtcMatchesServerReturns(false, nil) test_helpers.ExecuteCommandWithArgs(targetCommand, []string{"target.com"}) Expect(fakeVersionManager.LtcMatchesServerCallCount()).To(Equal(1)) Expect(fakeVersionManager.LtcMatchesServerArgsForCall(0)).To(Equal("http://receptor.target.com")) Expect(outputBuffer).To(test_helpers.SayLine("WARNING: local ltc version (some-version) does not match target expected version.")) Expect(outputBuffer).To(test_helpers.SayLine("Run `ltc sync` to replace your local ltc command-line tool with your target cluster's expected version.")) }) It("should print warning and NOT recommend sync if ServerVersions endpoint fails", func() {