You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
104 lines
2.2 KiB
104 lines
2.2 KiB
2 months ago
|
package gzip
|
||
|
|
||
|
import (
|
||
|
"encoding/json"
|
||
|
"fmt"
|
||
|
"log"
|
||
|
"reflect"
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
// TestGzip
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param t
|
||
|
func TestGzip(t *testing.T) {
|
||
|
var strList = []string{"hello", "world", "0123", "456", "789"}
|
||
|
data, err := json.Marshal(strList)
|
||
|
if err != nil {
|
||
|
print(err)
|
||
|
}
|
||
|
|
||
|
// define original data
|
||
|
fmt.Println("original data:", data)
|
||
|
fmt.Println("original data len:", len(data))
|
||
|
|
||
|
// 压缩数据信息
|
||
|
compressedData, err := GZipData(data)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
fmt.Println("compressed data:", compressedData)
|
||
|
fmt.Println("compressed data len:", len(compressedData))
|
||
|
|
||
|
// 解压数据信息
|
||
|
uncompressedData, err := GUnzipData(compressedData)
|
||
|
if err != nil {
|
||
|
log.Fatal(err)
|
||
|
}
|
||
|
|
||
|
fmt.Println("uncompressed data:", string(uncompressedData))
|
||
|
fmt.Println("uncompressed data len:", len(uncompressedData))
|
||
|
}
|
||
|
|
||
|
// TestGUnzipData 测试解压数据
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param t
|
||
|
func TestGUnzipData(t *testing.T) {
|
||
|
type args struct {
|
||
|
data []byte
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
wantResData []byte
|
||
|
wantErr bool
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
gotResData, err := GUnzipData(tt.args.data)
|
||
|
if (err != nil) != tt.wantErr {
|
||
|
t.Errorf("GUnzipData() error = %v, wantErr %v", err, tt.wantErr)
|
||
|
return
|
||
|
}
|
||
|
if !reflect.DeepEqual(gotResData, tt.wantResData) {
|
||
|
t.Errorf("GUnzipData() gotResData = %v, want %v", gotResData, tt.wantResData)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// TestGZipData 测试压缩数据
|
||
|
//
|
||
|
// @Description:
|
||
|
// @param t
|
||
|
func TestGZipData(t *testing.T) {
|
||
|
type args struct {
|
||
|
data []byte
|
||
|
}
|
||
|
tests := []struct {
|
||
|
name string
|
||
|
args args
|
||
|
wantCompressedData []byte
|
||
|
wantErr bool
|
||
|
}{
|
||
|
// TODO: Add test cases.
|
||
|
}
|
||
|
for _, tt := range tests {
|
||
|
t.Run(tt.name, func(t *testing.T) {
|
||
|
gotCompressedData, err := GZipData(tt.args.data)
|
||
|
if (err != nil) != tt.wantErr {
|
||
|
t.Errorf("GZipData() error = %v, wantErr %v", err, tt.wantErr)
|
||
|
return
|
||
|
}
|
||
|
if !reflect.DeepEqual(gotCompressedData, tt.wantCompressedData) {
|
||
|
t.Errorf("GZipData() gotCompressedData = %v, want %v", gotCompressedData, tt.wantCompressedData)
|
||
|
}
|
||
|
})
|
||
|
}
|
||
|
}
|