-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain_test.go
128 lines (118 loc) · 2.85 KB
/
main_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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
package goSirene
import (
"context"
"fmt"
"os"
"testing"
"github.com/cnf/structhash"
)
var geoSireneFile = "test/StockEtablissement_utf8_geo.csv.gz"
var sireneULZIPFile = "test/StockUniteLegale_utf8.zip"
var sireneULPlainFile = "test/StockUniteLegale_utf8.csv"
func Test_GeoSireneReader(t *testing.T) {
t.Log("Test GeoSirene Reader with real data")
file, err := os.Open(geoSireneFile)
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
s := GeoSireneParser(ctx, file)
result := []GeoSirene{}
for sirene := range s {
if sirene.err == nil {
result = append(result, sirene)
} else {
t.Log("Error encountered when reading data: " + sirene.err.Error())
t.Fatal()
}
}
md5 := fmt.Sprintf("%x", structhash.Md5(result, 1))
expected := "6f1ac5ec70776c9607702bfb70f1d2c9"
if md5 != expected {
t.Logf("hash should be %s, is %s", expected, md5)
t.Fail()
}
}
func Test_SireneULZIPReader(t *testing.T) {
ctx := context.Background()
s := SireneULParser(ctx, sireneULZIPFile)
result := []SireneUL{}
for sirene := range s {
if sirene.err == nil {
result = append(result, sirene)
} else {
t.Log("Error encountered when reading data: " + sirene.err.Error())
t.Fatal()
}
}
md5 := fmt.Sprintf("%x", structhash.Md5(result, 1))
expected := "5efa2b5264247e1f5123f601055434e5"
if md5 != expected {
t.Logf("hash should be %s, is %s", expected, md5)
t.Fail()
}
}
func Test_SireneULPlainReader(t *testing.T) {
ctx := context.Background()
s := SireneULParser(ctx, sireneULPlainFile)
result := []SireneUL{}
for sirene := range s {
if sirene.err == nil {
result = append(result, sirene)
} else {
t.Log("Error encountered when reading data: " + sirene.err.Error())
t.Fatal()
}
}
md5 := fmt.Sprintf("%x", structhash.Md5(result, 1))
expected := "5efa2b5264247e1f5123f601055434e5"
if md5 != expected {
t.Logf("hash should be %s, is %s", expected, md5)
t.Fail()
}
}
func Test_GeoSireneReaderCancelContext(t *testing.T) {
t.Log("Test Reader with real data")
file, err := os.Open(geoSireneFile)
if err != nil {
t.Fatal(err)
}
ctx := context.Background()
ctx, fn := context.WithCancel(ctx)
s := GeoSireneParser(ctx, file)
v, ok := <-s
if !ok {
t.Log("Channel doesn't work")
}
if v.err != nil {
t.Log("Error encountered when reading data: " + v.err.Error())
t.Fatal()
}
fn()
_, ok = <-s
if ok {
t.Log("Channel is open but should be closed")
t.Fatal()
}
}
func Test_SireneULReaderCancelContext(t *testing.T) {
t.Log("Test Reader with real data")
ctx := context.Background()
ctx, fn := context.WithCancel(ctx)
s := SireneULParser(ctx, sireneULZIPFile)
v, ok := <-s
if !ok {
t.Log("Channel doesn't work")
t.Fatal()
}
if v.err != nil {
t.Log("Error encountered when reading data: " + v.err.Error())
t.Fatal()
}
fn()
_, ok = <-s
if ok {
t.Log("Channel is open but should be closed")
t.Fatal()
}
}