Skip to content

Commit

Permalink
fix: test
Browse files Browse the repository at this point in the history
  • Loading branch information
devhaozi committed Oct 27, 2024
1 parent 4c5da95 commit 1f10298
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 5 deletions.
7 changes: 7 additions & 0 deletions pkg/io/compress.go
Original file line number Diff line number Diff line change
Expand Up @@ -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, ".")
}
Expand Down Expand Up @@ -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)
Expand Down
14 changes: 9 additions & 5 deletions pkg/io/io_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 1f10298

Please sign in to comment.