调整项目架构,让框架更优化
This commit is contained in:
35
excel/excel_test.go
Normal file
35
excel/excel_test.go
Normal file
@@ -0,0 +1,35 @@
|
||||
package excel
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
type row struct {
|
||||
ID int
|
||||
Name string
|
||||
}
|
||||
|
||||
func TestExportToWriterResetsFile(t *testing.T) {
|
||||
ex := NewExcel()
|
||||
cols := []ExportColumn{
|
||||
{Header: "ID", Field: "ID"},
|
||||
{Header: "Name", Field: "Name"},
|
||||
}
|
||||
data := []row{{ID: 1, Name: "a"}, {ID: 2, Name: "b"}}
|
||||
|
||||
var buf1, buf2 bytes.Buffer
|
||||
if err := ex.ExportToWriter(&buf1, "S1", cols, data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if err := ex.ExportToWriter(&buf2, "S1", cols, data); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
if buf1.Len() == 0 || buf2.Len() == 0 {
|
||||
t.Fatal("expected non-empty xlsx output")
|
||||
}
|
||||
// 导出后不应残留内部文件句柄
|
||||
if ex.file != nil {
|
||||
t.Fatal("internal file should be cleared after ExportToWriter")
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user