goProject/trunk/goutil/fileUtil/gzip_test.go

55 lines
1.3 KiB
Go
Raw Permalink Normal View History

2025-01-06 16:01:02 +08:00
package fileUtil
import (
"fmt"
"testing"
)
func TestGzip(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt")
if err := WriteFile(path, "test.txt", true, "first line\nHello world"); err != nil {
t.Errorf("there should be no error, but now it is:%s", err)
}
if err := Gzip(fileName, ""); err != nil {
// if err := Gzip(fileName, path); err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
}
if fileList, err := GetFileList(path); err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
} else {
for _, item := range fileList {
fmt.Printf("item:%s\n", item)
}
}
DeleteFile(fileName)
}
func TestUnGzip(t *testing.T) {
path := GetCurrentPath()
fmt.Printf("CurrPath:%s\n", path)
fileName := fmt.Sprintf("%s/%s", path, "test.txt.gz")
if err := UnGzip(fileName, ""); err != nil {
// if err := UnGzip(fileName, path); err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
}
content, err := ReadFileContent(fmt.Sprintf("%s/%s", path, "test.txt"))
if err != nil {
t.Errorf("There should be no error, but now it has:%s", err)
} else {
fmt.Printf("content:%s\n", content)
}
DeleteFile(fileName)
fileName = fmt.Sprintf("%s/%s", path, "test.txt")
DeleteFile(fileName)
}