diff options
author | xuri <xuri.me@gmail.com> | 2020-04-01 00:38:12 +0800 |
---|---|---|
committer | xuri <xuri.me@gmail.com> | 2020-04-01 00:46:29 +0800 |
commit | 736362694adff47424726a4e4e2569f8247e7fcf (patch) | |
tree | 7926b4d6a9186a8caaf5c1bc6b4b265fb0668995 | |
parent | 3ce4b91be96589847823b6c1b6c123ba7880310f (diff) |
Add unit test case
-rw-r--r-- | .travis.yml | 1 | ||||
-rw-r--r-- | file_test.go | 20 |
2 files changed, 20 insertions, 1 deletions
diff --git a/.travis.yml b/.travis.yml index d94d5d8..92852cf 100644 --- a/.travis.yml +++ b/.travis.yml @@ -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 diff --git a/file_test.go b/file_test.go index 8c5050c..e27b754 100644 --- a/file_test.go +++ b/file_test.go @@ -1,7 +1,12 @@ package excelize import ( + "bufio" + "bytes" + "strings" "testing" + + "github.com/stretchr/testify/assert" ) func BenchmarkWrite(b *testing.B) { @@ -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") +} |