示例#1
0
package cf

import (
	"os"
	"strconv"

	"github.com/onsi/ginkgo/config"
	"github.com/peterellisjones/cf-test-helpers/runner"
	"github.com/vito/cmdtest"
)

var Cf = func(args ...string) *cmdtest.Session {
	trace_file := os.Getenv("CF_TRACE_BASENAME")
	if trace_file != "" {
		os.Setenv("CF_TRACE", trace_file+strconv.Itoa(config.GinkgoConfig.ParallelNode)+".txt")
	}

	return runner.Run("gcf", args...)
}
	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
	"github.com/peterellisjones/cf-test-helpers/runner"
	"github.com/vito/cmdtest"
	. "github.com/vito/cmdtest/matchers"
)

var originalStarter = runner.SessionStarter

var _ = AfterEach(func() {
	runner.SessionStarter = originalStarter
})

var _ = Describe("Run", func() {
	It("runs the given command in a cmdtest Session", func() {
		session := runner.Run("bash", "-c", "echo hi out; echo hi err 1>&2; exit 42")

		Expect(session).To(Say("hi out"))
		Expect(session).To(SayError("hi err"))
		Expect(session).To(ExitWith(42))
	})
})

var _ = Describe("Curl", func() {
	It("outputs the body of the given URL", func() {
		session := &cmdtest.Session{}

		runner.SessionStarter = func(cmd *exec.Cmd) (*cmdtest.Session, error) {
			Expect(cmd.Path).To(Equal(exec.Command("curl").Path))

			Expect(cmd.Args).To(Equal([]string{