func hgRevision(path string) *cmdtest.Session { hg := exec.Command("hg", "id", "-i") hg.Dir = path sess, err := cmdtest.Start(hg) Expect(err).ToNot(HaveOccurred()) return sess }
func bzrRevision(path string) *cmdtest.Session { bzr := exec.Command("bzr", "revno", "--tree") bzr.Dir = path sess, err := cmdtest.Start(bzr) Expect(err).ToNot(HaveOccurred()) return sess }
func gitRevision(path, rev string) *cmdtest.Session { git := exec.Command("git", "rev-parse", rev) git.Dir = path sess, err := cmdtest.Start(git) Expect(err).ToNot(HaveOccurred()) return sess }
func Run(executable string, args ...string) *cmdtest.Session { cmd := exec.Command(executable, args...) sess, err := cmdtest.Start(cmd) if err != nil { panic(err) } return sess }
func (runner *CLIRunner) start(command string, timestamp int, message string) *cmdtest.Session { cmd := exec.Command("hm9000", command, fmt.Sprintf("--config=%s", runner.configPath)) cmd.Env = append(os.Environ(), fmt.Sprintf("HM9000_FAKE_TIME=%d", timestamp)) var session *cmdtest.Session var err error if runner.verbose { session, err = cmdtest.StartWrapped(cmd, teeToStdout, teeToStdout) } else { session, err = cmdtest.Start(cmd) } Ω(err).ShouldNot(HaveOccurred()) Ω(session).Should(SayWithTimeout(message, 5*time.Second)) return session }
func (runner *CLIRunner) StartSession(command string, timestamp int, extraArgs ...string) *cmdtest.Session { args := []string{command, fmt.Sprintf("--config=%s", runner.configPath)} args = append(args, extraArgs...) cmd := exec.Command("hm9000", args...) cmd.Env = append(os.Environ(), fmt.Sprintf("HM9000_FAKE_TIME=%d", timestamp)) var session *cmdtest.Session var err error if runner.verbose { session, err = cmdtest.StartWrapped(cmd, teeToStdout, teeToStdout) } else { session, err = cmdtest.Start(cmd) } Ω(err).ShouldNot(HaveOccurred()) return session }
func (runner *NATSRunner) Start() { _, err := exec.LookPath("gnatsd") if err != nil { fmt.Println("You need gnatsd installed!") os.Exit(1) } sess, err := cmdtest.Start(exec.Command("gnatsd", "-p", strconv.Itoa(runner.port))) Ω(err).ShouldNot(HaveOccurred(), "Make sure to have gnatsd on your path") runner.natsSession = sess connectionInfo := &yagnats.ConnectionInfo{ Addr: fmt.Sprintf("127.0.0.1:%d", runner.port), } messageBus := yagnats.NewClient() Eventually(func() error { return messageBus.Connect(connectionInfo) }, 5, 0.1).ShouldNot(HaveOccurred()) runner.MessageBus = messageBus }
package cf_test import ( "os/exec" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/pivotal-cf-experimental/cf-test-helpers/cf" "github.com/pivotal-cf-experimental/cf-test-helpers/runner" "github.com/vito/cmdtest" . "github.com/vito/cmdtest/matchers" ) var _ = Describe("Cf", func() { It("sends the request to current CF target", func() { runner.SessionStarter = func(cmd *exec.Cmd) (*cmdtest.Session, error) { Expect(cmd.Path).To(Equal(exec.Command("gcf").Path)) Expect(cmd.Args).To(Equal([]string{"gcf", "apps"})) return cmdtest.Start(exec.Command("bash", "-c", `exit 42`)) } Expect(Cf("apps")).To(ExitWith(42)) }) })
package cf_test import ( "os/exec" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" . "github.com/peterellisjones/cf-test-helpers/cf" "github.com/peterellisjones/cf-test-helpers/runner" "github.com/vito/cmdtest" ) var _ = Describe("ApiRequest", func() { It("sends the request to current CF target", func() { runner.SessionStarter = func(cmd *exec.Cmd) (*cmdtest.Session, error) { Expect(cmd.Path).To(Equal(exec.Command("gcf").Path)) Expect(cmd.Args).To(Equal([]string{ "gcf", "curl", "/v2/info", "-X", "GET", "-d", "somedata", })) return cmdtest.Start(exec.Command("bash", "-c", `echo \{ \"metadata\": \{ \"guid\": \"abc\" \} \}`)) } var response GenericResource ApiRequest("GET", "/v2/info", &response, "some", "data") Expect(response.Metadata.Guid).To(Equal("abc")) }) })
"os" "os/exec" . "github.com/onsi/ginkgo" . "github.com/onsi/gomega" "github.com/pivotal-cf-experimental/cf-test-helpers/cf" "github.com/vito/cmdtest" ) var _ = Describe("AsUser", func() { var FakeThingsToRunAsUser = func() {} var FakeCfCalls = [][]string{} var FakeCf = func(args ...string) *cmdtest.Session { FakeCfCalls = append(FakeCfCalls, args) var session, _ = cmdtest.Start(exec.Command("echo", "nothing")) return session } var user = cf.NewUserContext("http://FAKE_API.example.com", "FAKE_USERNAME", "FAKE_PASSWORD", "FAKE_ORG", "FAKE_SPACE", "--skip-ssl-validation") BeforeEach(func() { FakeCfCalls = [][]string{} cf.Cf = FakeCf }) It("calls cf api", func() { cf.AsUser(user, FakeThingsToRunAsUser) Expect(FakeCfCalls[0]).To(Equal([]string{"api", "http://FAKE_API.example.com", "--skip-ssl-validation"})) })
"github.com/vito/cmdtest" . "github.com/vito/cmdtest/matchers" ) var _ = Describe("Running spiff", func() { spiff, err := cmdtest.Build(".") if err != nil { panic(err) } Describe("merge", func() { var merge *cmdtest.Session Context("when given a bad file path", func() { BeforeEach(func() { merge, err = cmdtest.Start(spiff, "merge", "foo.yml") Expect(err).NotTo(HaveOccured()) }) It("says file not found", func() { Expect(merge).To(SayError("foo.yml: no such file or directory")) Expect(merge).To(ExitWith(1)) }) }) Context("when given a single file", func() { basicTemplate, err := ioutil.TempFile(os.TempDir(), "basic.yml") if err != nil { panic(err) }
func listing(path string) *cmdtest.Session { sess, err := cmdtest.Start(exec.Command("ls", path)) Expect(err).ToNot(HaveOccurred()) return sess }
"github.com/vito/cmdtest" . "github.com/vito/cmdtest/matchers" ) var _ = Describe("Boosh", func() { var booshPath string BeforeEach(func() { var err error booshPath, err = cmdtest.Build("github.com/vito/boosh") Ω(err).ShouldNot(HaveOccurred()) }) generating := func() *cmdtest.Session { session, err := cmdtest.Start(exec.Command(booshPath, "generate")) Ω(err).ShouldNot(HaveOccurred()) return session } It("generates a correct deployment", func() { session := generating() session.Stdin.Write([]byte(`--- description: MicroBOSH elastic_ips: - name: Micro vpc: