Skip to content

Commit

Permalink
Add unit test case
Browse files Browse the repository at this point in the history
  • Loading branch information
xuri committed Mar 31, 2020
1 parent 3ce4b91 commit 7363626
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 1 deletion.
1 change: 0 additions & 1 deletion .travis.yml
Expand Up @@ -4,7 +4,6 @@ install:
- go get -d -t -v ./... && go build -v ./...

go:
- 1.10.x
- 1.11.x
- 1.12.x
- 1.13.x
Expand Down
20 changes: 20 additions & 0 deletions file_test.go
@@ -1,7 +1,12 @@
package excelize

import (
"bufio"
"bytes"
"strings"
"testing"

"github.com/stretchr/testify/assert"
)

func BenchmarkWrite(b *testing.B) {
Expand All @@ -26,3 +31,18 @@ func BenchmarkWrite(b *testing.B) {
}
}
}

func TestWriteTo(t *testing.T) {
f := File{}
buf := bytes.Buffer{}
f.XLSX = make(map[string][]byte, 0)
f.XLSX["/d/"] = []byte("s")
_, err := f.WriteTo(bufio.NewWriter(&buf))
assert.EqualError(t, err, "zip: write to directory")
delete(f.XLSX, "/d/")
// Test file path overflow
const maxUint16 = 1<<16 - 1
f.XLSX[strings.Repeat("s", maxUint16+1)] = nil
_, err = f.WriteTo(bufio.NewWriter(&buf))
assert.EqualError(t, err, "zip: FileHeader.Name too long")
}

0 comments on commit 7363626

Please sign in to comment.