You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
115 lines
1.9 KiB
Go
115 lines
1.9 KiB
Go
package csv
|
|
|
|
import (
|
|
"context"
|
|
"joybuywork/internal/plugins/export"
|
|
"fmt"
|
|
"path/filepath"
|
|
"runtime"
|
|
"testing"
|
|
)
|
|
|
|
func getData() (export.HeaderField, []export.RowData) {
|
|
header := export.HeaderField{
|
|
{
|
|
Field: "name",
|
|
Title: "姓名",
|
|
},
|
|
{
|
|
Field: "age",
|
|
Title: "年龄",
|
|
},
|
|
{
|
|
Field: "like",
|
|
Title: "喜欢",
|
|
},
|
|
}
|
|
|
|
var data []export.RowData
|
|
for i := 0; i < 1000; i++ {
|
|
row := export.RowData{
|
|
"name": fmt.Sprintf("学生%d", i),
|
|
"age": 15,
|
|
"like": fmt.Sprintf("不知道%d", i),
|
|
}
|
|
data = append(data, row)
|
|
}
|
|
|
|
return header, data
|
|
}
|
|
|
|
func TestExportCsv(t *testing.T) {
|
|
header, data := getData()
|
|
err := NewExport(context.Background(), header, int64(len(data))).ExportFile(data)
|
|
t.Log(err)
|
|
}
|
|
|
|
func TestExportCsvTask(t *testing.T) {
|
|
header, data := getData()
|
|
|
|
ct, err := NewExport(context.Background(), header, int64(len(data))).UpgradeTask(export.UseFinishPart(200, func(spn, nfp float64) {
|
|
t.Log(spn, nfp)
|
|
}))
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
|
|
ct.GetHashMark()
|
|
|
|
err = export.Done(ct)
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
|
|
ct.AppendData(data)
|
|
|
|
reply := <-ct.GetReply()
|
|
|
|
if reply.Error != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
|
|
t.Log(reply.Filename, reply.FilePath, reply.Error)
|
|
}
|
|
|
|
func TestProceed(t *testing.T) {
|
|
header, data := getData()
|
|
_, filename, _, _ := runtime.Caller(0)
|
|
current := filepath.Dir(filename)
|
|
|
|
t.Log(current)
|
|
|
|
return
|
|
|
|
xt, err := NewExport(context.Background(), header, int64(len(data)),
|
|
export.UseFile(
|
|
"ept_c6diaucjmgh6bp15jc1g82921.csv",
|
|
"G:\\Work\\go\\src\\app_service\\pkg\\components\\export\\csv/tmp/export/ept_c6diaucjmgh6bp15jc1g82921.csv",
|
|
),
|
|
).UpgradeTask(export.UserProceed(701, 0))
|
|
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
|
|
err = export.Done(xt)
|
|
if err != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
|
|
xt.AppendData(data)
|
|
|
|
reply := <-xt.GetReply()
|
|
|
|
if reply.Error != nil {
|
|
t.Log(err)
|
|
return
|
|
}
|
|
t.Log(reply.Filename, reply.FilePath, reply.Fr)
|
|
}
|