-
Notifications
You must be signed in to change notification settings - Fork 2
/
csv_test.go
60 lines (49 loc) · 1.58 KB
/
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
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
package loader
import (
"reflect"
"testing"
)
func TestGetDataFromCSV(t *testing.T) {
fx := FixtureLoader{}
columns := []string{"id", "name"}
rows := []map[string]string{map[string]string{"id": "1", "name": "エクスカリバー"}, map[string]string{"id": "2", "name": "村正"}}
t.Run("load csv", func(t *testing.T) {
file := "_data/item.csv"
data, err := fx.getDataFromCSV(file, "csv")
if err != nil {
t.Fatalf("[error] get data from csv: %v", err)
}
if !reflect.DeepEqual(data.columns, columns) {
t.Fatalf("[error] get data from csv: expect: %v but %v", columns, data.columns)
}
if !reflect.DeepEqual(data.rows, rows) {
t.Fatalf("[error] get data from csv: expect: %v but %v", data.rows, rows)
}
})
t.Run("load empty csv", func(t *testing.T) {
file := "_data/zero.csv"
data, err := fx.getDataFromCSV(file, "csv")
if err != nil {
t.Fatalf("[error] get data from csv: %v", err)
}
if !reflect.DeepEqual(data.columns, columns) {
t.Fatalf("[error] get data from csv: expect: %v but %v", columns, data.columns)
}
if len(data.rows) != 0 {
t.Fatalf("[error] load data from csv: %v", data.rows)
}
})
t.Run("load tsv", func(t *testing.T) {
file := "_data/item.tsv"
data, err := fx.getDataFromCSV(file, "tsv")
if err != nil {
t.Fatalf("[error] get data from csv: %v", err)
}
if !reflect.DeepEqual(data.columns, columns) {
t.Fatalf("[error] get data from csv: expect: %v but %v", columns, data.columns)
}
if !reflect.DeepEqual(data.rows, rows) {
t.Fatalf("[error] get data from csv: expect: %v but %v", data.rows, rows)
}
})
}