-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathunzip_test.go
52 lines (41 loc) · 1.14 KB
/
unzip_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
package unzip
import (
"github.com/stretchr/testify/assert"
"testing"
)
const testZipPath = "./test_data/foo.zip"
func TestNew(t *testing.T) {
unzip := New(NewOptions().SetSourceZipFile(testZipPath))
assert.NotNil(t, unzip)
}
func TestUnzip_SafeTraversal(t *testing.T) {
unzip := New(NewOptions().SetSourceZipFile(testZipPath))
assert.NotNil(t, unzip)
err := unzip.SafeTraversal(func(file *File, options *Options) error {
t.Log(file.Name)
return nil
})
assert.Nil(t, err)
}
func TestUnzip_Traversal(t *testing.T) {
unzip := New(NewOptions().SetSourceZipFile(testZipPath))
assert.NotNil(t, unzip)
err := unzip.Traversal(func(file *File, options *Options) error {
t.Log(file.Name)
return nil
})
assert.Nil(t, err)
}
func TestUnzip_Unzip(t *testing.T) {
unzip := New(NewOptions().SetSourceZipFile(testZipPath).SetDestinationDirectory("./test_data/a/"))
assert.NotNil(t, unzip)
err := unzip.Unzip()
assert.Nil(t, err)
}
func TestUnzip_Files(t *testing.T) {
unzip := New(NewOptions().SetSourceZipFile(testZipPath))
assert.NotNil(t, unzip)
fileSlice, err := unzip.Files()
assert.Nil(t, err)
assert.True(t, len(fileSlice) == 2)
}