Skip to content

Commit b949301

Browse files
committed
More lint fixes
1 parent 7b1f5df commit b949301

9 files changed

+108
-85
lines changed

expect/console.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -46,17 +46,17 @@ type ConsoleOpts struct {
4646
Logger *log.Logger
4747
Stdouts []io.Writer
4848
Closers []io.Closer
49-
ExpectObservers []ExpectObserver
49+
ExpectObservers []Observer
5050
SendObservers []SendObserver
5151
}
5252

53-
// ExpectObserver provides an interface for a function callback that will
53+
// Observer provides an interface for a function callback that will
5454
// be called after each Expect operation.
5555
// matchers will be the list of active matchers when an error occurred,
5656
// or a list of matchers that matched `buf` when err is nil.
5757
// buf is the captured output that was matched against.
5858
// err is error that might have occurred. May be nil.
59-
type ExpectObserver func(matchers []Matcher, buf string, err error)
59+
type Observer func(matchers []Matcher, buf string, err error)
6060

6161
// SendObserver provides an interface for a function callback that will
6262
// be called after each Send operation.
@@ -97,7 +97,7 @@ func WithLogger(logger *log.Logger) ConsoleOpt {
9797
}
9898

9999
// WithExpectObserver adds an ExpectObserver to allow monitoring Expect operations.
100-
func WithExpectObserver(observers ...ExpectObserver) ConsoleOpt {
100+
func WithExpectObserver(observers ...Observer) ConsoleOpt {
101101
return func(opts *ConsoleOpts) error {
102102
opts.ExpectObservers = append(opts.ExpectObservers, observers...)
103103
return nil
@@ -124,12 +124,12 @@ func NewConsole(opts ...ConsoleOpt) (*Console, error) {
124124
}
125125
}
126126

127-
pty, err := pty.New()
127+
consolePty, err := pty.New()
128128
if err != nil {
129129
return nil, err
130130
}
131-
closers := append(options.Closers, pty)
132-
reader := pty.Reader()
131+
closers := append(options.Closers, consolePty)
132+
reader := consolePty.Reader()
133133

134134
passthroughPipe, err := NewPassthroughPipe(reader)
135135
if err != nil {
@@ -139,7 +139,7 @@ func NewConsole(opts ...ConsoleOpt) (*Console, error) {
139139

140140
console := &Console{
141141
opts: options,
142-
pty: pty,
142+
pty: consolePty,
143143
passthroughPipe: passthroughPipe,
144144
runeReader: bufio.NewReaderSize(passthroughPipe, utf8.UTFMax),
145145
closers: closers,

expect/expect.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,8 +46,8 @@ func (c *Console) ExpectEOF() (string, error) {
4646
// expecting input yet, it will be blocked. Sends are queued up in tty's
4747
// internal buffer so that the next Expect will read the remaining bytes (i.e.
4848
// rest of prompt) as well as its conditions.
49-
func (c *Console) Expect(opts ...ExpectOpt) (string, error) {
50-
var options ExpectOpts
49+
func (c *Console) Expect(opts ...Opt) (string, error) {
50+
var options Opts
5151
for _, opt := range opts {
5252
if err := opt(&options); err != nil {
5353
return "", err

expect/expect_opt.go

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ import (
2424
"time"
2525
)
2626

27-
// ExpectOpt allows settings Expect options.
28-
type ExpectOpt func(*ExpectOpts) error
27+
// Opt allows settings Expect options.
28+
type Opt func(*Opts) error
2929

3030
// ConsoleCallback is a callback function to execute if a match is found for
3131
// the chained matcher.
3232
type ConsoleCallback func(buf *bytes.Buffer) error
3333

3434
// Then returns an Expect condition to execute a callback if a match is found
3535
// for the chained matcher.
36-
func (eo ExpectOpt) Then(consoleCallback ConsoleCallback) ExpectOpt {
37-
return func(opts *ExpectOpts) error {
38-
var options ExpectOpts
36+
func (eo Opt) Then(consoleCallback ConsoleCallback) Opt {
37+
return func(opts *Opts) error {
38+
var options Opts
3939
err := eo(&options)
4040
if err != nil {
4141
return err
@@ -51,15 +51,15 @@ func (eo ExpectOpt) Then(consoleCallback ConsoleCallback) ExpectOpt {
5151
}
5252
}
5353

54-
// ExpectOpts provides additional options on Expect.
55-
type ExpectOpts struct {
54+
// Opts provides additional options on Expect.
55+
type Opts struct {
5656
Matchers []Matcher
5757
ReadTimeout *time.Duration
5858
}
5959

6060
// Match sequentially calls Match on all matchers in ExpectOpts and returns the
6161
// first matcher if a match exists, otherwise nil.
62-
func (eo ExpectOpts) Match(v interface{}) Matcher {
62+
func (eo Opts) Match(v interface{}) Matcher {
6363
for _, matcher := range eo.Matchers {
6464
if matcher.Match(v) {
6565
return matcher
@@ -189,7 +189,7 @@ func (rm *regexpMatcher) Criteria() interface{} {
189189
// allMatcher fulfills the Matcher interface to match a group of ExpectOpt
190190
// against any value.
191191
type allMatcher struct {
192-
options ExpectOpts
192+
options Opts
193193
}
194194

195195
func (am *allMatcher) Match(v interface{}) bool {
@@ -215,9 +215,9 @@ func (am *allMatcher) Criteria() interface{} {
215215

216216
// All adds an Expect condition to exit if the content read from Console's tty
217217
// matches all of the provided ExpectOpt, in any order.
218-
func All(expectOpts ...ExpectOpt) ExpectOpt {
219-
return func(opts *ExpectOpts) error {
220-
var options ExpectOpts
218+
func All(expectOpts ...Opt) Opt {
219+
return func(opts *Opts) error {
220+
var options Opts
221221
for _, opt := range expectOpts {
222222
if err := opt(&options); err != nil {
223223
return err
@@ -233,8 +233,8 @@ func All(expectOpts ...ExpectOpt) ExpectOpt {
233233

234234
// String adds an Expect condition to exit if the content read from Console's
235235
// tty contains any of the given strings.
236-
func String(strs ...string) ExpectOpt {
237-
return func(opts *ExpectOpts) error {
236+
func String(strs ...string) Opt {
237+
return func(opts *Opts) error {
238238
for _, str := range strs {
239239
opts.Matchers = append(opts.Matchers, &stringMatcher{
240240
str: str,
@@ -246,8 +246,8 @@ func String(strs ...string) ExpectOpt {
246246

247247
// Regexp adds an Expect condition to exit if the content read from Console's
248248
// tty matches the given Regexp.
249-
func Regexp(res ...*regexp.Regexp) ExpectOpt {
250-
return func(opts *ExpectOpts) error {
249+
func Regexp(res ...*regexp.Regexp) Opt {
250+
return func(opts *Opts) error {
251251
for _, re := range res {
252252
opts.Matchers = append(opts.Matchers, &regexpMatcher{
253253
re: re,
@@ -260,8 +260,8 @@ func Regexp(res ...*regexp.Regexp) ExpectOpt {
260260
// RegexpPattern adds an Expect condition to exit if the content read from
261261
// Console's tty matches the given Regexp patterns. Expect returns an error if
262262
// the patterns were unsuccessful in compiling the Regexp.
263-
func RegexpPattern(ps ...string) ExpectOpt {
264-
return func(opts *ExpectOpts) error {
263+
func RegexpPattern(ps ...string) Opt {
264+
return func(opts *Opts) error {
265265
var res []*regexp.Regexp
266266
for _, p := range ps {
267267
re, err := regexp.Compile(p)
@@ -276,8 +276,8 @@ func RegexpPattern(ps ...string) ExpectOpt {
276276

277277
// Error adds an Expect condition to exit if reading from Console's tty returns
278278
// one of the provided errors.
279-
func Error(errs ...error) ExpectOpt {
280-
return func(opts *ExpectOpts) error {
279+
func Error(errs ...error) Opt {
280+
return func(opts *Opts) error {
281281
for _, err := range errs {
282282
opts.Matchers = append(opts.Matchers, &errorMatcher{
283283
err: err,
@@ -289,7 +289,7 @@ func Error(errs ...error) ExpectOpt {
289289

290290
// EOF adds an Expect condition to exit if io.EOF is returned from reading
291291
// Console's tty.
292-
func EOF(opts *ExpectOpts) error {
292+
func EOF(opts *Opts) error {
293293
return Error(io.EOF)(opts)
294294
}
295295

@@ -298,7 +298,7 @@ func EOF(opts *ExpectOpts) error {
298298
// on Linux while reading from the ptm after the pts is closed.
299299
// Further Reading:
300300
// https://github.com/kr/pty/issues/21#issuecomment-129381749
301-
func PTSClosed(opts *ExpectOpts) error {
301+
func PTSClosed(opts *Opts) error {
302302
opts.Matchers = append(opts.Matchers, &pathErrorMatcher{
303303
pathError: os.PathError{
304304
Op: "read",

expect/expect_opt_test.go

Lines changed: 41 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,11 @@ import (
2727
)
2828

2929
func TestExpectOptString(t *testing.T) {
30+
t.Parallel()
31+
3032
tests := []struct {
3133
title string
32-
opt ExpectOpt
34+
opt Opt
3335
data string
3436
expected bool
3537
}{
@@ -60,8 +62,11 @@ func TestExpectOptString(t *testing.T) {
6062
}
6163

6264
for _, test := range tests {
65+
test := test
6366
t.Run(test.title, func(t *testing.T) {
64-
var options ExpectOpts
67+
t.Parallel()
68+
69+
var options Opts
6570
err := test.opt(&options)
6671
require.Nil(t, err)
6772

@@ -80,9 +85,11 @@ func TestExpectOptString(t *testing.T) {
8085
}
8186

8287
func TestExpectOptRegexp(t *testing.T) {
88+
t.Parallel()
89+
8390
tests := []struct {
8491
title string
85-
opt ExpectOpt
92+
opt Opt
8693
data string
8794
expected bool
8895
}{
@@ -113,8 +120,11 @@ func TestExpectOptRegexp(t *testing.T) {
113120
}
114121

115122
for _, test := range tests {
123+
test := test
116124
t.Run(test.title, func(t *testing.T) {
117-
var options ExpectOpts
125+
t.Parallel()
126+
127+
var options Opts
118128
err := test.opt(&options)
119129
require.Nil(t, err)
120130

@@ -133,9 +143,11 @@ func TestExpectOptRegexp(t *testing.T) {
133143
}
134144

135145
func TestExpectOptRegexpPattern(t *testing.T) {
146+
t.Parallel()
147+
136148
tests := []struct {
137149
title string
138-
opt ExpectOpt
150+
opt Opt
139151
data string
140152
expected bool
141153
}{
@@ -166,8 +178,11 @@ func TestExpectOptRegexpPattern(t *testing.T) {
166178
}
167179

168180
for _, test := range tests {
181+
test := test
169182
t.Run(test.title, func(t *testing.T) {
170-
var options ExpectOpts
183+
t.Parallel()
184+
185+
var options Opts
171186
err := test.opt(&options)
172187
require.Nil(t, err)
173188

@@ -186,9 +201,11 @@ func TestExpectOptRegexpPattern(t *testing.T) {
186201
}
187202

188203
func TestExpectOptError(t *testing.T) {
204+
t.Parallel()
205+
189206
tests := []struct {
190207
title string
191-
opt ExpectOpt
208+
opt Opt
192209
data error
193210
expected bool
194211
}{
@@ -219,8 +236,11 @@ func TestExpectOptError(t *testing.T) {
219236
}
220237

221238
for _, test := range tests {
239+
test := test
222240
t.Run(test.title, func(t *testing.T) {
223-
var options ExpectOpts
241+
t.Parallel()
242+
243+
var options Opts
224244
err := test.opt(&options)
225245
require.Nil(t, err)
226246

@@ -235,14 +255,16 @@ func TestExpectOptError(t *testing.T) {
235255
}
236256

237257
func TestExpectOptThen(t *testing.T) {
258+
t.Parallel()
259+
238260
var (
239261
errFirst = errors.New("first")
240262
errSecond = errors.New("second")
241263
)
242264

243265
tests := []struct {
244266
title string
245-
opt ExpectOpt
267+
opt Opt
246268
data string
247269
match bool
248270
expected error
@@ -290,8 +312,11 @@ func TestExpectOptThen(t *testing.T) {
290312
}
291313

292314
for _, test := range tests {
315+
test := test
293316
t.Run(test.title, func(t *testing.T) {
294-
var options ExpectOpts
317+
t.Parallel()
318+
319+
var options Opts
295320
err := test.opt(&options)
296321
require.Nil(t, err)
297322

@@ -318,9 +343,11 @@ func TestExpectOptThen(t *testing.T) {
318343
}
319344

320345
func TestExpectOptAll(t *testing.T) {
346+
t.Parallel()
347+
321348
tests := []struct {
322349
title string
323-
opt ExpectOpt
350+
opt Opt
324351
data string
325352
expected bool
326353
}{
@@ -387,8 +414,10 @@ func TestExpectOptAll(t *testing.T) {
387414
}
388415

389416
for _, test := range tests {
417+
test := test
390418
t.Run(test.title, func(t *testing.T) {
391-
var options ExpectOpts
419+
t.Parallel()
420+
var options Opts
392421
err := test.opt(&options)
393422
require.Nil(t, err)
394423

0 commit comments

Comments
 (0)