diff options
author | xuri <xuri.me@gmail.com> | 2021-09-18 23:20:24 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2021-09-19 11:06:54 +0800 |
commit | 790c363cceaaa09e91ad579e2d25cb13c1582bba (patch) | |
tree | b5747f30edeac96a7fdadec574f1a5b1d332ca18 /lib_test.go | |
parent | 2add938798cdd1456616869298319528b0c76913 (diff) |
This closes #833, closes #845, and closes #1022, breaking changes
- Close spreadsheet and row's iterator required
- New options `WorksheetUnzipMemLimit` have been added
- Improve streaming reading performance, memory usage decrease about 93.7%
Diffstat (limited to 'lib_test.go')
-rw-r--r-- | lib_test.go | 43 |
1 files changed, 43 insertions, 0 deletions
diff --git a/lib_test.go b/lib_test.go index 556ed91..84a52bb 100644 --- a/lib_test.go +++ b/lib_test.go @@ -1,13 +1,18 @@ package excelize import ( + "archive/zip" + "bytes" "encoding/xml" "fmt" + "os" "strconv" "strings" + "sync" "testing" "github.com/stretchr/testify/assert" + "github.com/stretchr/testify/require" ) var validColumns = []struct { @@ -296,3 +301,41 @@ func TestBstrMarshal(t *testing.T) { assert.Equal(t, expected, bstrMarshal(bstr)) } } + +func TestReadBytes(t *testing.T) { + f := &File{tempFiles: sync.Map{}} + sheet := "xl/worksheets/sheet1.xml" + f.tempFiles.Store(sheet, "/d/") + assert.Equal(t, []byte{}, f.readBytes(sheet)) +} + +func TestUnzipToTemp(t *testing.T) { + os.Setenv("TMPDIR", "test") + defer os.Unsetenv("TMPDIR") + assert.NoError(t, os.Chmod(os.TempDir(), 0444)) + f := NewFile() + data := []byte("PK\x03\x040000000PK\x01\x0200000" + + "0000000000000000000\x00" + + "\x00\x00\x00\x00\x00000000000000PK\x01" + + "\x020000000000000000000" + + "00000\v\x00\x00\x00\x00\x00000000000" + + "00000000000000PK\x01\x0200" + + "00000000000000000000" + + "00\v\x00\x00\x00\x00\x00000000000000" + + "00000000000PK\x01\x020000<" + + "0\x00\x0000000000000000\v\x00\v" + + "\x00\x00\x00\x00\x0000000000\x00\x00\x00\x00000" + + "00000000PK\x01\x0200000000" + + "0000000000000000\v\x00\x00\x00" + + "\x00\x0000PK\x05\x06000000\x05\x000000" + + "\v\x00\x00\x00\x00\x00") + z, err := zip.NewReader(bytes.NewReader(data), int64(len(data))) + assert.NoError(t, err) + + _, err = f.unzipToTemp(z.File[0]) + require.Error(t, err) + assert.NoError(t, os.Chmod(os.TempDir(), 0755)) + + _, err = f.unzipToTemp(z.File[0]) + assert.EqualError(t, err, "EOF") +} |