mirror of
https://github.com/acepanel/panel.git
synced 2026-02-04 13:47:15 +08:00
fix: test
This commit is contained in:
@@ -22,6 +22,9 @@ const (
|
||||
|
||||
// Compress 压缩文件
|
||||
func Compress(dir string, src []string, dst string) error {
|
||||
if !filepath.IsAbs(dir) || !filepath.IsAbs(dst) {
|
||||
return errors.New("dir and dst must be absolute path")
|
||||
}
|
||||
if len(src) == 0 {
|
||||
src = append(src, ".")
|
||||
}
|
||||
@@ -72,6 +75,10 @@ func Compress(dir string, src []string, dst string) error {
|
||||
|
||||
// UnCompress 解压文件
|
||||
func UnCompress(src string, dst string) error {
|
||||
if !filepath.IsAbs(src) || !filepath.IsAbs(dst) {
|
||||
return errors.New("src and dst must be absolute path")
|
||||
}
|
||||
|
||||
var cmd *exec.Cmd
|
||||
|
||||
format, err := formatArchiveByPath(src)
|
||||
|
||||
@@ -53,27 +53,31 @@ func (s *IOTestSuite) TestWriteAppendAppendsToFile() {
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestCompress() {
|
||||
src := []string{"testdata/compress_test1.txt", "testdata/compress_test2.txt"}
|
||||
src := []string{"compress_test1.txt", "compress_test2.txt"}
|
||||
err := Write(src[0], "File 1", 0644)
|
||||
s.NoError(err)
|
||||
err = Write(src[1], "File 2", 0644)
|
||||
s.NoError(err)
|
||||
|
||||
err = Compress("testdata", src, "testdata/compress_test.zip")
|
||||
abs, err := filepath.Abs("testdata")
|
||||
s.NoError(err)
|
||||
err = Compress(abs, src, filepath.Join(abs, "compress_test.zip"))
|
||||
s.NoError(err)
|
||||
}
|
||||
|
||||
func (s *IOTestSuite) TestUnCompress() {
|
||||
src := []string{"testdata/uncompress_test1.txt", "testdata/uncompress_test2.txt"}
|
||||
src := []string{"compress_test1.txt", "compress_test2.txt"}
|
||||
err := Write(src[0], "File 1", 0644)
|
||||
s.NoError(err)
|
||||
err = Write(src[1], "File 2", 0644)
|
||||
s.NoError(err)
|
||||
|
||||
err = Compress("testdata", src, "testdata/uncompress_test.zip")
|
||||
abs, err := filepath.Abs("testdata")
|
||||
s.NoError(err)
|
||||
err = Compress(abs, src, filepath.Join(abs, "compress_test.zip"))
|
||||
s.NoError(err)
|
||||
|
||||
err = UnCompress("testdata/uncompress_test.zip", "testdata/uncompressed")
|
||||
err = UnCompress(filepath.Join(abs, "compress_test.zip"), filepath.Join(abs, "uncompressed"))
|
||||
s.NoError(err)
|
||||
|
||||
data, err := Read("testdata/uncompressed/uncompress_test1.txt")
|
||||
|
||||
Reference in New Issue
Block a user