-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathzip_test.go
More file actions
52 lines (47 loc) · 1.45 KB
/
Copy pathzip_test.go
File metadata and controls
52 lines (47 loc) · 1.45 KB
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 mob
import (
"archive/zip"
"fmt"
"github.com/guestin/mob/merrors"
"github.com/guestin/mob/mio"
"os"
"testing"
)
func TestUnZip(t *testing.T) {
err := os.Mkdir("zip_output", 0755)
merrors.AssertError(err, "mkdir zip_output")
defer func() {
_ = os.RemoveAll("zip_output")
}()
err = UnZip("sample.zip", "zip_output")
merrors.AssertError(err, "unzip")
}
func TestZip(t *testing.T) {
wd, err := os.Getwd()
merrors.AssertError(err, "getwd")
fmt.Println("wd=", wd)
file, err := os.OpenFile("output.zip", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
merrors.AssertError(err, "create output")
defer mio.CloseIgnoreErr(file)
err = Zip(file, []*FileGroup{
NewFileGroup(".", "go.mod").SetCustomDirName("c").AddFileItemWithAlias("go.sum", "goSum"),
NewFileGroup(".idea", "misc.xml", "modules.xml", "workspace.xml").SetCustomDirName(".").
AddChildFileGroup(NewFileGroup("inspectionProfiles", "Project_Default.xml").SetCustomDirName("a")),
})
merrors.AssertError(err, "zip failed")
}
func TestZip2(t *testing.T) {
file, err := os.OpenFile("output.zip", os.O_CREATE|os.O_TRUNC|os.O_RDWR, 0644)
merrors.AssertError(err, "create output")
writer := zip.NewWriter(file)
defer func() {
mio.CloseIgnoreErr(writer)
mio.CloseIgnoreErr(file)
}()
_, err = writer.Create("a/")
merrors.AssertError(err, "create a/")
_, err = writer.Create("a/b/")
merrors.AssertError(err, "create a/b/")
_, err = writer.Create("a/")
merrors.AssertError(err, "create a/ again")
}