Skip to content

Commit 0e8d4b6

Browse files
committed
Remove .Then()
1 parent db4d232 commit 0e8d4b6

File tree

3 files changed

+0
-115
lines changed

3 files changed

+0
-115
lines changed

expect/expect.go

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,6 @@ func (c *Console) ExpectString(s string) (string, error) {
3434
return c.Expect(String(s))
3535
}
3636

37-
// ExpectEOF reads from Console's tty until EOF or an error occurs, and returns
38-
// the buffer read by Console. We also treat the PTSClosed error as an EOF.
39-
func (c *Console) ExpectEOF() (string, error) {
40-
return c.Expect(EOF, PTSClosed)
41-
}
42-
4337
// Expect reads from Console's tty until a condition specified from opts is
4438
// encountered or an error occurs, and returns the buffer read by console.
4539
// No extra bytes are read once a condition is met, so if a program isn't

expect/expect_opt.go

Lines changed: 0 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -32,26 +32,6 @@ type Opt func(*Opts) error
3232
// the chained matcher.
3333
type ConsoleCallback func(buf *bytes.Buffer) error
3434

35-
// Then returns an Expect condition to execute a callback if a match is found
36-
// for the chained matcher.
37-
func (eo Opt) Then(consoleCallback ConsoleCallback) Opt {
38-
return func(opts *Opts) error {
39-
var options Opts
40-
err := eo(&options)
41-
if err != nil {
42-
return err
43-
}
44-
45-
for _, matcher := range options.Matchers {
46-
opts.Matchers = append(opts.Matchers, &callbackMatcher{
47-
f: consoleCallback,
48-
matcher: matcher,
49-
})
50-
}
51-
return nil
52-
}
53-
}
54-
5535
// Opts provides additional options on Expect.
5636
type Opts struct {
5737
Matchers []Matcher

expect/expect_opt_test.go

Lines changed: 0 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import (
2121
"testing"
2222

2323
"github.com/stretchr/testify/require"
24-
"golang.org/x/xerrors"
2524

2625
. "github.com/coder/coder/expect"
2726
)
@@ -254,94 +253,6 @@ func TestExpectOptError(t *testing.T) {
254253
}
255254
}
256255

257-
func TestExpectOptThen(t *testing.T) {
258-
t.Parallel()
259-
260-
var (
261-
errFirst = xerrors.New("first")
262-
errSecond = xerrors.New("second")
263-
)
264-
265-
tests := []struct {
266-
title string
267-
opt Opt
268-
data string
269-
match bool
270-
expected error
271-
}{
272-
{
273-
"Noop",
274-
String("Hello").Then(func(buf *bytes.Buffer) error {
275-
return nil
276-
}),
277-
"Hello world",
278-
true,
279-
nil,
280-
},
281-
{
282-
"Short circuit",
283-
String("Hello").Then(func(buf *bytes.Buffer) error {
284-
return errFirst
285-
}).Then(func(buf *bytes.Buffer) error {
286-
return errSecond
287-
}),
288-
"Hello world",
289-
true,
290-
errFirst,
291-
},
292-
{
293-
"Chain",
294-
String("Hello").Then(func(buf *bytes.Buffer) error {
295-
return nil
296-
}).Then(func(buf *bytes.Buffer) error {
297-
return errSecond
298-
}),
299-
"Hello world",
300-
true,
301-
errSecond,
302-
},
303-
{
304-
"No matches",
305-
String("other").Then(func(buf *bytes.Buffer) error {
306-
return errFirst
307-
}),
308-
"Hello world",
309-
false,
310-
nil,
311-
},
312-
}
313-
314-
for _, test := range tests {
315-
test := test
316-
t.Run(test.title, func(t *testing.T) {
317-
t.Parallel()
318-
319-
var options Opts
320-
err := test.opt(&options)
321-
require.Nil(t, err)
322-
323-
buf := new(bytes.Buffer)
324-
_, err = buf.WriteString(test.data)
325-
require.Nil(t, err)
326-
327-
matcher := options.Match(buf)
328-
if test.match {
329-
require.NotNil(t, matcher)
330-
331-
cb, ok := matcher.(CallbackMatcher)
332-
if ok {
333-
require.True(t, ok)
334-
335-
err = cb.Callback(nil)
336-
require.Equal(t, test.expected, err)
337-
}
338-
} else {
339-
require.Nil(t, matcher)
340-
}
341-
})
342-
}
343-
}
344-
345256
func TestExpectOptAll(t *testing.T) {
346257
t.Parallel()
347258

0 commit comments

Comments
 (0)