pkg/expect: add SendLine for interactive mode

This commit is contained in:
Gyu-Ho Lee
2016-03-31 11:01:42 -07:00
parent 1d698f093f
commit d898c68f2c
2 changed files with 22 additions and 3 deletions

View File

@@ -17,6 +17,7 @@ package expect
import (
"bufio"
"io"
"os"
"os/exec"
"strings"
@@ -112,3 +113,8 @@ func (ep *ExpectProcess) Close() error {
ep.cmd = nil
return err
}
func (ep *ExpectProcess) SendLine(command string) error {
_, err := io.WriteString(ep.fpty, command+"\r\n")
return err
}

View File

@@ -16,9 +16,7 @@
package expect
import (
"testing"
)
import "testing"
func TestEcho(t *testing.T) {
ep, err := NewExpect("/bin/echo", "hello world")
@@ -40,3 +38,18 @@ func TestEcho(t *testing.T) {
t.Fatalf("expected error on closed expect process")
}
}
func TestSendLine(t *testing.T) {
ep, err := NewExpect("/usr/bin/tr", "a", "b")
if err != nil {
t.Fatal(err)
}
defer ep.Close()
if err := ep.SendLine("a"); err != nil {
t.Fatal(err)
}
_, eerr := ep.Expect("b")
if eerr != nil {
t.Fatal(eerr)
}
}