Commit cdea96c0 authored by Boris Mühmer's avatar Boris Mühmer
Browse files

not working

parent 2f5d1ab6
Loading
Loading
Loading
Loading
+15 −11
Original line number Diff line number Diff line
@@ -19,9 +19,9 @@ const (
type Expect struct {
	// bytes.Buffer
	// mb.MutexBuffer
	stdin       *mb.MutexBuffer
	stdout      *mb.MutexBuffer
	stderr      *mb.MutexBuffer
	stdin       io.Reader
	stdout      io.Writer
	stderr      io.Writer
	matchStream chan struct {
		c Channel
		m Match
@@ -91,9 +91,13 @@ func (x *Expect) Wait(c Channel, match, text string) error {
func (x *Expect) worker(started chan<- bool) {
	var wg sync.WaitGroup

	x.stdin = &mb.MutexBuffer{}
	x.stdout = &mb.MutexBuffer{}
	x.stderr = &mb.MutexBuffer{}
	stdin := &mb.MutexBuffer{}
	stdout := &mb.MutexBuffer{}
	stderr := &mb.MutexBuffer{}

	x.stdin = stdin
	x.stdout = stdout
	x.stderr = stderr

	matchOutStream := make(chan Match)
	startedOutStream := make(chan bool)
@@ -116,7 +120,7 @@ func (x *Expect) worker(started chan<- bool) {
	go func() {
		defer wg.Done()
		process(
			x.stdout, x.stdin,
			stdout,
			startedOutStream,
			matchOutStream,
			stringStream,
@@ -125,7 +129,7 @@ func (x *Expect) worker(started chan<- bool) {
	go func() {
		defer wg.Done()
		process(
			x.stderr, x.stdin,
			stderr,
			startedErrStream,
			matchErrStream,
			stringStream,
@@ -153,9 +157,11 @@ func (x *Expect) worker(started chan<- bool) {
			if !valid {
				continue
			}
			//stdin.Reset()
			stdin.Write([]byte(s))
			//x.stdin.Reset()
			//x.stdin.Write([]byte(s))
			io.WriteString(x.stdin, s)
			//io.WriteString(stdin, s)
			//fmt.Fprintln(x.stdin, s)
		case terminate, valid := <-x.terminateStream:
			if !valid {
@@ -205,7 +211,6 @@ func (x *Expect) worker(started chan<- bool) {

func process(
	in io.Reader,
	out io.Writer,
	startedStream chan<- bool,
	matchStream <-chan Match,
	stringStream chan<- string,
@@ -245,7 +250,6 @@ func process(
				if !strings.Contains(s, m.p) {
					continue
				}
				//io.WriteString(out, m.v)
				go func(s string) {
					stringStream <- s
				}(m.v)