Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 5cba77d

Browse files
committed
Remove more unused options
1 parent 4e4f3e2 commit 5cba77d

File tree

2 files changed

+1
-43
lines changed

2 files changed

+1
-43
lines changed

expect/console.go

Lines changed: 1 addition & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -45,9 +45,7 @@ type ConsoleOpt func(*ConsoleOpts) error
4545
type ConsoleOpts struct {
4646
Logger *log.Logger
4747
Stdouts []io.Writer
48-
Closers []io.Closer
4948
ExpectObservers []Observer
50-
SendObservers []SendObserver
5149
}
5250

5351
// Observer provides an interface for a function callback that will
@@ -58,13 +56,6 @@ type ConsoleOpts struct {
5856
// err is error that might have occurred. May be nil.
5957
type Observer func(matchers []Matcher, buf string, err error)
6058

61-
// SendObserver provides an interface for a function callback that will
62-
// be called after each Send operation.
63-
// msg is the string that was sent.
64-
// num is the number of bytes actually sent.
65-
// err is the error that might have occurred. May be nil.
66-
type SendObserver func(msg string, num int, err error)
67-
6859
// WithStdout adds writers that Console duplicates writes to, similar to the
6960
// Unix tee(1) command.
7061
//
@@ -79,14 +70,6 @@ func WithStdout(writers ...io.Writer) ConsoleOpt {
7970
}
8071
}
8172

82-
// WithCloser adds closers that are closed in order when Console is closed.
83-
func WithCloser(closer ...io.Closer) ConsoleOpt {
84-
return func(opts *ConsoleOpts) error {
85-
opts.Closers = append(opts.Closers, closer...)
86-
return nil
87-
}
88-
}
89-
9073
// WithLogger adds a logger for Console to log debugging information to. By
9174
// default Console will discard logs.
9275
func WithLogger(logger *log.Logger) ConsoleOpt {
@@ -104,14 +87,6 @@ func WithExpectObserver(observers ...Observer) ConsoleOpt {
10487
}
10588
}
10689

107-
// WithSendObserver adds a SendObserver to allow monitoring Send operations.
108-
func WithSendObserver(observers ...SendObserver) ConsoleOpt {
109-
return func(opts *ConsoleOpts) error {
110-
opts.SendObservers = append(opts.SendObservers, observers...)
111-
return nil
112-
}
113-
}
114-
11590
// NewConsole returns a new Console with the given options.
11691
func NewConsole(opts ...ConsoleOpt) (*Console, error) {
11792
options := ConsoleOpts{
@@ -128,7 +103,7 @@ func NewConsole(opts ...ConsoleOpt) (*Console, error) {
128103
if err != nil {
129104
return nil, err
130105
}
131-
closers := append(options.Closers, consolePty)
106+
closers := []io.Closer{consolePty}
132107
reader := consolePty.Reader()
133108

134109
passthroughPipe, err := NewPassthroughPipe(reader)
@@ -173,9 +148,6 @@ func (c *Console) Close() error {
173148
func (c *Console) Send(s string) (int, error) {
174149
c.Logf("console send: %q", s)
175150
n, err := c.pty.WriteString(s)
176-
for _, observer := range c.opts.SendObservers {
177-
observer(s, n, err)
178-
}
179151
return n, err
180152
}
181153

expect/expect_test.go

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,6 @@ func Prompt(in io.Reader, out io.Writer) error {
7474
func newTestConsole(t *testing.T, opts ...ConsoleOpt) (*Console, error) {
7575
opts = append([]ConsoleOpt{
7676
expectNoError(t),
77-
sendNoError(t),
7877
}, opts...)
7978
return NewTestConsole(t, opts...)
8079
}
@@ -98,19 +97,6 @@ func expectNoError(t *testing.T) ConsoleOpt {
9897
)
9998
}
10099

101-
func sendNoError(t *testing.T) ConsoleOpt {
102-
return WithSendObserver(
103-
func(msg string, n int, err error) {
104-
if err != nil {
105-
t.Fatalf("Failed to send %q: %s\n%s", msg, err, string(debug.Stack()))
106-
}
107-
if len(msg) != n {
108-
t.Fatalf("Only sent %d of %d bytes for %q\n%s", n, len(msg), msg, string(debug.Stack()))
109-
}
110-
},
111-
)
112-
}
113-
114100
func testCloser(t *testing.T, closer io.Closer) {
115101
if err := closer.Close(); err != nil {
116102
t.Errorf("Close failed: %s", err)

0 commit comments

Comments
 (0)