-
Notifications
You must be signed in to change notification settings - Fork 0
/
core_test.go
101 lines (88 loc) · 1.74 KB
/
core_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
package exportlistmapping
import (
"fmt"
"io/ioutil"
"log"
"path/filepath"
"strconv"
"testing"
"github.com/nekonbu72/xemlsx"
"github.com/tealeg/xlsx"
)
const (
dir = "test"
jsonPath = "setting.json"
)
func testPaths() []string {
return dirwalk(dir)
}
func dirwalk(dir string) []string {
files, err := ioutil.ReadDir(dir)
if err != nil {
panic(err)
}
var paths []string
for _, file := range files {
if file.IsDir() {
paths = append(paths, dirwalk(filepath.Join(dir, file.Name()))...)
continue
}
paths = append(paths, filepath.Join(dir, file.Name()))
}
return paths
}
func TestPaths(t *testing.T) {
for _, s := range testPaths() {
fmt.Println(s)
}
}
func testFiles() []*xlsx.File {
var fs []*xlsx.File
for _, p := range testPaths() {
f, err := xlsx.OpenFile(p)
if err != nil {
continue
}
fs = append(fs, f)
}
return fs
}
func TestFiles(t *testing.T) {
fs := testFiles()
if len(fs) != 3 {
t.Errorf("len: %v\n", len(fs))
}
}
func testXLSXStream(done chan interface{}) <-chan *xemlsx.XLSX {
xlsxStream := make(chan *xemlsx.XLSX)
go func() {
defer close(xlsxStream)
for i, f := range testFiles() {
select {
case <-done:
return
case xlsxStream <- &xemlsx.XLSX{
FileName: "File#" + strconv.Itoa(i),
File: f,
}:
}
}
}()
return xlsxStream
}
func TestFetch(t *testing.T) {
setting, err := NewSetting(jsonPath)
if err != nil {
t.Errorf("NewSetting: %v\n", err)
return
}
done := make(chan interface{})
defer close(done)
data, err := Fetch(setting, testXLSXStream(done))
if err != nil {
t.Errorf("Fetch: %v\n", err)
}
for _, d := range data {
log.Println(d)
}
}