|
| 1 | +// Copyright (c) Jeevanandam M. (https://github.com/jeevatkm) |
| 2 | +// go-aah/essentials source code and usage is governed by a MIT style |
| 3 | +// license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +package ess |
| 6 | + |
| 7 | +import ( |
| 8 | + "io/ioutil" |
| 9 | + "testing" |
| 10 | + |
| 11 | + "aahframework.org/test.v0/assert" |
| 12 | +) |
| 13 | + |
| 14 | +func TestArchiveZip(t *testing.T) { |
| 15 | + // Prepare data for zip file |
| 16 | + testdataPath := getTestdataPath() |
| 17 | + path1 := join(testdataPath, "dirpaths", "level1", "level2", "level3") |
| 18 | + path11 := join(testdataPath, "dirpaths", "level1", "level1-1") |
| 19 | + path12 := join(testdataPath, "dirpaths", "level1", "level1-2") |
| 20 | + path21 := join(testdataPath, "dirpaths", "level1", "level2", "level2-1") |
| 21 | + path22 := join(testdataPath, "dirpaths", "level1", "level2", "level2-2") |
| 22 | + defer DeleteFiles(join(testdataPath, "dirpaths")) |
| 23 | + |
| 24 | + _ = MkDirAll(path1, 0755) |
| 25 | + _ = MkDirAll(path11, 0755) |
| 26 | + _ = MkDirAll(path12, 0755) |
| 27 | + _ = MkDirAll(path21, 0755) |
| 28 | + _ = MkDirAll(path22, 0755) |
| 29 | + |
| 30 | + _ = ioutil.WriteFile(join(path1, "file1.txt"), []byte("file1.txt"), 0600) |
| 31 | + _ = ioutil.WriteFile(join(path11, "file11.txt"), []byte("file11.txt"), 0600) |
| 32 | + _ = ioutil.WriteFile(join(path12, "file12.txt"), []byte("file12.txt"), 0600) |
| 33 | + _ = ioutil.WriteFile(join(path21, "file21.txt"), []byte("file21.txt"), 0600) |
| 34 | + _ = ioutil.WriteFile(join(path22, "file22.txt"), []byte("file22.txt"), 0600) |
| 35 | + |
| 36 | + zipName := join(testdataPath, "testarchive.zip") |
| 37 | + defer DeleteFiles(zipName) |
| 38 | + |
| 39 | + err := Zip(zipName, join(testdataPath, "dirpaths")) |
| 40 | + assert.Nil(t, err) |
| 41 | + assert.True(t, IsFileExists(zipName)) |
| 42 | +} |
0 commit comments