-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserialize_test.go
65 lines (49 loc) · 1.36 KB
/
serialize_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
package excelsior_test
import (
"net/http"
"testing"
"github.com/kakilangit/excelsior"
"github.com/xuri/excelize/v2"
)
type nopResponseWriter struct{}
func (nopResponseWriter) Header() http.Header {
return http.Header{}
}
func (nopResponseWriter) Write([]byte) (int, error) {
return 0, nil
}
func (nopResponseWriter) WriteHeader(int) {}
func TestSerialize(t *testing.T) {
data, err := excelsior.Serialize(func(file *excelize.File, style excelsior.Style) ([]byte, error) {
const sheetName = "not found alphabet"
excelsior.SetDefaultSheetName(file, sheetName)
headers := []any{"alphabet"}
data := nopSheetData{row: excelsior.Row{"a"}}
sheet := excelsior.NewSheet(headers, excelsior.DefaultGetStyleFn, style.Header(), data)
if err := sheet.Generate(file, sheetName); err != nil {
return nil, err
}
return excelsior.Byte(file)
})
if err != nil {
t.Errorf("failed to serialize: %v", err)
}
if len(data) == 0 {
t.Errorf("empty data")
}
}
func TestSetHeader(t *testing.T) {
header := http.Header{}
excelsior.SetHeader(header, "test")
if header.Get("Content-Disposition") != "attachment; filename=test.xlsx" {
t.Errorf("failed to set header")
}
}
func TestWriteByt(t *testing.T) {
data := []byte("test")
rw := nopResponseWriter{}
err := excelsior.WriteByte(data, "test", rw)
if err != nil {
t.Errorf("failed to write byte: %v", err)
}
}