-
Notifications
You must be signed in to change notification settings - Fork 0
/
customer_reader_test.go
77 lines (69 loc) · 1.29 KB
/
customer_reader_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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package email_sender
import (
"io"
"testing"
"github.com/stretchr/testify/require"
)
const customerTestFile = "etc/test/customers.csv"
func TestCustomerReader_Read(t *testing.T) {
t.Parallel()
tests := []struct {
name string
n int
want []*Customer
wantErr error
}{
{
name: "success",
n: 10,
want: []*Customer{
{
Title: "Mr",
FirstName: "John",
LastName: "Smith",
Email: "john.smith@example.com",
},
{
Title: "Mrs",
FirstName: "Michelle",
LastName: "Smith",
Email: "michelle.smith@example.com",
},
{
Title: "Mr",
FirstName: "something",
LastName: "",
Email: "",
},
},
wantErr: io.EOF,
},
{
name: "read_less_than_total",
n: 1,
want: []*Customer{
{
Title: "Mr",
FirstName: "John",
LastName: "Smith",
Email: "john.smith@example.com",
},
},
wantErr: nil,
},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
t.Parallel()
cr, err := NewCustomerReader(customerTestFile)
require.NoError(t, err)
got, err := cr.Read(tt.n)
if tt.wantErr != nil {
require.ErrorIs(t, err, tt.wantErr)
} else {
require.NoError(t, err)
}
require.Equal(t, tt.want, got)
})
}
}