Skip to content

Commit d7ef2a1

Browse files
committed
Fix ReadLine() EOF handling
1 parent 2b95047 commit d7ef2a1

File tree

3 files changed

+10
-9
lines changed

3 files changed

+10
-9
lines changed

fpmTest/main.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,11 @@ const (
2222

2323
const (
2424
testData1 = "en taro adun en taro tassadar en taro zeratul"
25-
testData2 = "power overwhelming"
25+
testData2 = "power overwhelming\n"
2626
)
2727

2828
func main() {
29-
testFPMExecute()
29+
//testFPMExecute()
3030
testWrapperSocket()
3131
}
3232

pkg/util/line_reader.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func ReadLine(r *bufio.Reader) ([]byte, error) {
3333
skip = true
3434
case io.EOF:
3535
// TODO badly-formed line
36-
return nil, nil
36+
return nil, io.EOF
3737
default:
3838
return nil, err
3939
}

pkg/util/line_reader_test.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,20 @@ import (
66
"bytes"
77

88
"github.com/stretchr/testify/assert"
9+
"io"
910
)
1011

11-
func tf(t *testing.T, in string, out []byte) {
12+
func tf(t *testing.T, in string, out []byte, expectedErr error) {
1213
r := bufio.NewReaderSize(bytes.NewBufferString(in), 16)
1314

1415
line, err := ReadLine(r)
15-
assert.NoError(t, err)
16+
assert.Equal(t, expectedErr, err)
1617
assert.Equal(t, out, line)
1718
}
1819

1920
func TestReadLine(t *testing.T) {
20-
tf(t, "test\n", []byte("test\n"))
21-
tf(t, "test\r\n", []byte("test\n"))
22-
tf(t, "no line end", nil)
23-
tf(t, "test very long long line\n", nil)
21+
tf(t, "test\n", []byte("test\n"), nil)
22+
tf(t, "test\r\n", []byte("test\n"), nil)
23+
tf(t, "no line end", nil, io.EOF)
24+
tf(t, "test very long long line\n", nil, nil)
2425
}

0 commit comments

Comments
 (0)