func (r *Runner) Run(sigChan <-chan os.Signal, ready chan<- struct{}) error { defer ginkgo.GinkgoRecover() allOutput := gbytes.NewBuffer() debugWriter := gexec.NewPrefixedWriter( fmt.Sprintf("\x1b[32m[d]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name), ginkgo.GinkgoWriter, ) session, err := gexec.Start( r.Command, gexec.NewPrefixedWriter( fmt.Sprintf("\x1b[32m[o]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name), io.MultiWriter(allOutput, ginkgo.GinkgoWriter), ), gexec.NewPrefixedWriter( fmt.Sprintf("\x1b[91m[e]\x1b[%s[%s]\x1b[0m ", r.AnsiColorCode, r.Name), io.MultiWriter(allOutput, ginkgo.GinkgoWriter), ), ) Ω(err).ShouldNot(HaveOccurred()) fmt.Fprintf(debugWriter, "spawned %s (pid: %d)\n", r.Command.Path, r.Command.Process.Pid) r.session = session if r.sessionReady != nil { close(r.sessionReady) } startCheckDuration := r.StartCheckTimeout if startCheckDuration == 0 { startCheckDuration = 5 * time.Second } var startCheckTimeout <-chan time.Time if r.StartCheck != "" { startCheckTimeout = time.After(startCheckDuration) } detectStartCheck := allOutput.Detect(r.StartCheck) for { select { case <-detectStartCheck: // works even with empty string allOutput.CancelDetects() startCheckTimeout = nil detectStartCheck = nil close(ready) case <-startCheckTimeout: // clean up hanging process session.Kill().Wait() // fail to start return fmt.Errorf( "did not see %s in command's output within %s. full output:\n\n%s", r.StartCheck, startCheckDuration, string(allOutput.Contents()), ) case signal := <-sigChan: session.Signal(signal) case <-session.Exited: if r.Cleanup != nil { r.Cleanup() } if session.ExitCode() == 0 { return nil } return fmt.Errorf("exit status %d", session.ExitCode()) } } }
} newContainer := func(text string, flag types.FlagType, setupNodes ...leafnodes.BasicNode) *containernode.ContainerNode { c := containernode.New(text, flag, codeLocation) for _, node := range setupNodes { c.PushSetupNode(node) } return c } containers := func(containers ...*containernode.ContainerNode) []*containernode.ContainerNode { return containers } BeforeEach(func() { buffer = gbytes.NewBuffer() failer = Failer.New() codeLocation = codelocation.New(0) nodesThatRan = []string{} }) Describe("marking specs focused and pending", func() { It("should satisfy various caes", func() { cases := []struct { ContainerFlags []types.FlagType SubjectFlag types.FlagType Pending bool Focused bool }{ {[]types.FlagType{}, noneFlag, false, false}, {[]types.FlagType{}, focusedFlag, false, true},
package writer_test import ( "github.com/cloudfoundry-incubator/docker_app_lifecycle/Godeps/_workspace/src/github.com/onsi/gomega/gbytes" . "github.com/cloudfoundry-incubator/docker_app_lifecycle/Godeps/_workspace/src/github.com/onsi/ginkgo" . "github.com/cloudfoundry-incubator/docker_app_lifecycle/Godeps/_workspace/src/github.com/onsi/ginkgo/internal/writer" . "github.com/cloudfoundry-incubator/docker_app_lifecycle/Godeps/_workspace/src/github.com/onsi/gomega" ) var _ = Describe("Writer", func() { var writer *Writer var out *gbytes.Buffer BeforeEach(func() { out = gbytes.NewBuffer() writer = New(out) }) It("should stream directly to the outbuffer by default", func() { writer.Write([]byte("foo")) Ω(out).Should(gbytes.Say("foo")) }) It("should not emit the header when asked to DumpOutWitHeader", func() { writer.Write([]byte("foo")) writer.DumpOutWithHeader("my header") Ω(out).ShouldNot(gbytes.Say("my header")) Ω(out).Should(gbytes.Say("foo")) })