mirror of
https://github.com/etcd-io/etcd.git
synced 2024-09-27 06:25:44 +00:00
pkg/expect: add SendLine for interactive mode
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user