Skip to content

Instantly share code, notes, and snippets.

@rm3l
Created April 8, 2022 09:51
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rm3l/c5dd1a61772be3afa440d69e54747dce to your computer and use it in GitHub Desktop.
Save rm3l/c5dd1a61772be3afa440d69e54747dce to your computer and use it in GitHub Desktop.
diff --git a/tests/helper/helper_dev.go b/tests/helper/helper_dev.go
index 00cd1c08c..54aed03cd 100644
--- a/tests/helper/helper_dev.go
+++ b/tests/helper/helper_dev.go
@@ -1,10 +1,16 @@
package helper
import (
+ "fmt"
+ "os/exec"
"regexp"
"time"
+ "path/filepath"
+ . "github.com/onsi/ginkgo"
+ . "github.com/onsi/gomega"
"github.com/onsi/gomega/gexec"
+ "github.com/iwdgo/sigintwindows"
)
// DevSession represents a session running `odo dev`
@@ -106,6 +112,7 @@ import (
const localhostRegexp = "127.0.0.1:[0-9]*"
type DevSession struct {
+ pid int
session *gexec.Session
}
@@ -116,14 +123,25 @@ type DevSession struct {
func StartDevMode(opts ...string) (DevSession, []byte, []byte, []string, error) {
args := []string{"dev", "--random-ports"}
args = append(args, opts...)
- session := CmdRunner("odo", args...)
+ program := "odo"
+ // session := CmdRunner("odo", args...)
+
+ // prefix ginkgo verbose output with program name
+ prefix := fmt.Sprintf("[%s] ", filepath.Base(program))
+ prefixWriter := gexec.NewPrefixedWriter(prefix, GinkgoWriter)
+ command := exec.Command(program, args...)
+ fmt.Fprintln(GinkgoWriter, runningCmd(command))
+ session, err := gexec.Start(command, prefixWriter, prefixWriter)
+ Expect(err).NotTo(HaveOccurred())
+
WaitForOutputToContain("Watching for changes in the current directory", 360, 10, session)
result := DevSession{
+ pid: command.Process.Pid,
session: session,
}
outContents := session.Out.Contents()
errContents := session.Err.Contents()
- err := session.Out.Clear()
+ err = session.Out.Clear()
if err != nil {
return DevSession{}, nil, nil, nil, err
}
@@ -142,7 +160,8 @@ func (o DevSession) Kill() {
// Stop a Dev session cleanly (equivalent as hitting Ctrl-c)
func (o DevSession) Stop() {
- o.session.Interrupt()
+ sigintwindows.SendCtrlBreak(o.pid)
+ // o.session.Interrupt()
}
func (o DevSession) WaitEnd() {
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment