github.com/sohaha/zlsgo@v1.7.13-0.20240501141223-10dd1a906f76/zfile/compress_test.go (about)

     1  package zfile
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/sohaha/zlsgo"
     7  )
     8  
     9  func TestGz(t *testing.T) {
    10  	tt := zlsgo.NewTest(t)
    11  	err := WriteFile("./tmp_gz/log.txt", []byte("ok\n"))
    12  	tt.EqualNil(err)
    13  	err = WriteFile("./tmp_gz/tmp2/log.txt", []byte("ok\n"))
    14  	tt.EqualNil(err)
    15  	gz := "dd.tar.gz"
    16  	err = GzCompress(".", gz)
    17  	tt.EqualNil(err)
    18  	Rmdir("./tmp_gz")
    19  	err = GzDeCompress(gz, "tmp2")
    20  	tt.EqualNil(err)
    21  	err = GzDeCompress(gz+"1", "tmp2")
    22  	tt.Equal(true, err != nil)
    23  
    24  	ok := Rmdir("tmp2")
    25  	tt.EqualTrue(ok)
    26  	Rmdir(gz)
    27  }
    28  
    29  func TestZip(t *testing.T) {
    30  	tt := zlsgo.NewTest(t)
    31  	zip := "tmp.zip"
    32  	err := WriteFile("./tmp/log.txt", []byte("ok\n"))
    33  	tt.EqualNil(err)
    34  	err = WriteFile("./tmp/tmp2/log.txt", []byte("ok\n"))
    35  	tt.EqualNil(err)
    36  	err = ZipCompress("./", zip)
    37  	tt.EqualNil(err)
    38  	tt.EqualNil(ZipDeCompress(zip, "zip"))
    39  	tt.EqualTrue(FileExist("./zip/tmp/log.txt"))
    40  	Rmdir(zip)
    41  	Rmdir("zip")
    42  	Rmdir("./tmp")
    43  }