excel-export/biz/batch_test.go

37 lines
678 B
Go

package biz
import (
"excel_export/data"
"fmt"
"github.com/stretchr/testify/assert"
"os"
"testing"
"time"
)
func batchBiz() *BatchBiz {
db := data.Conn()
repo := data.NewDirectRepo(db)
historyRepo := data.NewHistoryDirectRepo(db)
return NewBatchBiz(repo, historyRepo, nil)
}
func TestBatchBiz_Export(t *testing.T) {
biz := batchBiz()
begin := time.Date(2021, 10, 1, 0, 0, 0, 0, time.Local)
end := time.Date(2022, 12, 1, 0, 0, 0, 0, time.Local)
err := biz.Export(begin, end)
assert.Nil(t, err)
for i := 0; i <= biz.FileSize(); i++ {
fileName := fmt.Sprintf(biz.FileName(), i)
assert.FileExists(t, fileName)
//清理文件
os.Remove(fileName)
}
}