forked from gocarina/gocsv
-
Notifications
You must be signed in to change notification settings - Fork 0
/
csv_test.go
34 lines (26 loc) · 849 Bytes
/
csv_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
package gocsv
import (
"errors"
"testing"
)
func TestUnmarshalToCallback_ReaderError(t *testing.T) {
type Dummy struct{}
var reader = &errorReader{}
err := UnmarshalToCallback(reader, func(Dummy) {})
if !errors.Is(err, readerErr) {
t.Error("UnmarshalToCallback should return first reader error")
}
err = UnmarshalDecoderToCallback(newSimpleDecoderFromReader(reader), func(Dummy) {})
if !errors.Is(err, readerErr) {
t.Error("UnmarshalDecoderToCallback should return first reader error")
}
err = UnmarshalToCallbackWithError(reader, func(Dummy) error { return nil })
if !errors.Is(err, readerErr) {
t.Error("UnmarshalToCallbackWithError should return first reader error")
}
}
type errorReader struct{}
func (e *errorReader) Read([]byte) (n int, err error) {
return 0, readerErr
}
var readerErr = errors.New("reader error")