func getAllCfCommands(connection *fakes.FakeCliConnection) (commands []string) {
	commands = []string{}
	for i := 0; i < connection.CliCommandCallCount(); i++ {
		args := connection.CliCommandArgsForCall(i)
		commands = append(commands, strings.Join(args, " "))
	}
	return
}
		cliConn *fakes.FakeCliConnection
		repo    *ApplicationRepo
	)

	BeforeEach(func() {
		cliConn = &fakes.FakeCliConnection{}
		repo = NewApplicationRepo(cliConn)
	})

	Describe("RenameApplication", func() {
		It("renames the application", func() {
			err := repo.RenameApplication("old-name", "new-name")
			Ω(err).ShouldNot(HaveOccurred())

			Ω(cliConn.CliCommandCallCount()).Should(Equal(1))
			args := cliConn.CliCommandArgsForCall(0)
			Ω(args).Should(Equal([]string{"rename", "old-name", "new-name"}))
		})

		It("returns an error if one occurs", func() {
			cliConn.CliCommandReturns([]string{}, errors.New("no app"))

			err := repo.RenameApplication("old-name", "new-name")
			Ω(err).Should(MatchError("no app"))
		})
	})

	Describe("PushApplication", func() {
		It("pushes an application with both a manifest and a path", func() {
			err := repo.PushApplication([]string{"push", "myapp", "-f", "/path/to/a/manifest.yml", "-p", "/path/to/the/app"})
			Ω(err).ShouldNot(HaveOccurred())
Esempio n. 3
0
	var (
		cliConn         *fakes.FakeCliConnection
		autopilotPlugin *AutopilotPlugin
	)

	BeforeEach(func() {
		cliConn = &fakes.FakeCliConnection{}
		autopilotPlugin = &AutopilotPlugin{}
	})

	It("displays push usage when push-zdd called with no arguments", func() {
		autopilotPlugin.Run(cliConn, []string{"push-zdd"})

		Ω(cliConn.CliCommandCallCount()).Should(Equal(1))
		args := cliConn.CliCommandArgsForCall(0)
		Ω(args).Should(Equal([]string{"push", "-h"}))
	})

	Context("when a version of an app already exists", func() {
		var (
			controlAppName          = "myapp"
			controlAppNameVenerable = fmt.Sprintf("%s-venerable", controlAppName)
			controlCallChain        = [][]string{
				[]string{"rename", controlAppName, controlAppNameVenerable},
				[]string{"push", controlAppName},
				[]string{"delete", controlAppNameVenerable, "-f"},
			}
			controlCallCount = len(controlCallChain)
		)
			It("deletes nothing", func() {
				p.DeleteAppVersions(apps)
				Expect(connection.CliCommandCallCount()).To(Equal(0))
			})
		})
	})

	Describe("pushing a new app", func() {
		newApp := Application{Name: "app-name-new"}
		newRoute := Route{Host: newApp.Name, Domain: Domain{Name: "example.com"}}

		It("pushes an app with new appended to its name", func() {
			p.PushNewApp(&newApp, newRoute)

			Expect(strings.Join(connection.CliCommandArgsForCall(0), " ")).
				To(MatchRegexp(`^push app-name-new`))
		})

		It("uses the generated name for the route", func() {
			p.PushNewApp(&newApp, newRoute)

			Expect(strings.Join(connection.CliCommandArgsForCall(0), " ")).
				To(MatchRegexp(`-n app-name-new`))
		})

		It("pushes with the default cf domain", func() {
			p.PushNewApp(&newApp, newRoute)

			Expect(strings.Join(connection.CliCommandArgsForCall(0), " ")).
				To(MatchRegexp(`-d example.com`))
Esempio n. 5
0
var _ = Describe("CallCliCmd", func() {
	Describe(".Run", func() {
		var fakeCliConnection *fakes.FakeCliConnection
		var callCliCommandPlugin *CliCmd

		BeforeEach(func() {
			fakeCliConnection = &fakes.FakeCliConnection{}
			callCliCommandPlugin = &CliCmd{}
		})

		It("calls the cli command that is passed as an argument", func() {
			io_helpers.CaptureOutput(func() {
				callCliCommandPlugin.Run(fakeCliConnection, []string{"cli-command", "plugins", "arg1"})
			})

			Expect(fakeCliConnection.CliCommandArgsForCall(0)[0]).To(Equal("plugins"))
			Expect(fakeCliConnection.CliCommandArgsForCall(0)[1]).To(Equal("arg1"))
		})

		It("ouputs the text returned by the cli command", func() {
			fakeCliConnection.CliCommandReturns([]string{"Hi", "Mom"}, nil)
			output := io_helpers.CaptureOutput(func() {
				callCliCommandPlugin.Run(fakeCliConnection, []string{"cli-command", "plugins", "arg1"})
			})

			Expect(output[1]).To(Equal("---------- Command output from the plugin ----------"))
			Expect(output[2]).To(Equal("# 0  value:  Hi"))
			Expect(output[3]).To(Equal("# 1  value:  Mom"))
			Expect(output[4]).To(Equal("----------              FIN               -----------"))
		})
	})