mirror of
https://github.com/pldubouilh/gossa.git
synced 2026-08-28 04:46:58 -04:00
better zip
This commit is contained in:
committed by
Pierre Dubouilh
parent
688be87923
commit
2f73fd9df8
+12
-6
@@ -1,8 +1,8 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"archive/zip"
|
||||
"bytes"
|
||||
"crypto/sha256"
|
||||
"fmt"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
@@ -30,6 +30,13 @@ func getRaw(t *testing.T, url string) []byte {
|
||||
return body
|
||||
}
|
||||
|
||||
func getZip(t *testing.T, dest string) []*zip.File {
|
||||
b := getRaw(t, dest)
|
||||
archive, err := zip.NewReader(bytes.NewReader(b), int64(len(b)))
|
||||
dieMaybe(t, err)
|
||||
return archive.File
|
||||
}
|
||||
|
||||
func get(t *testing.T, url string) string {
|
||||
body := getRaw(t, url)
|
||||
return trimSpaces(string(body))
|
||||
@@ -119,11 +126,10 @@ func doTestRegular(t *testing.T, url string, testExtra bool) {
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
fmt.Println("\r\n~~~~~~~~~~ test zip")
|
||||
bodyRaw := getRaw(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
||||
hashStr := fmt.Sprintf("%x", sha256.Sum256(bodyRaw))
|
||||
if hashStr != "b02436a76b149e6c4458bbbe622ab7c5e789bb0d26b87f604cf0f989cfaf669f" {
|
||||
t.Fatal("invalid zip checksum", hashStr)
|
||||
fmt.Println("\r\n~~~~~~~~~~ test zipping of folder 中文")
|
||||
files := getZip(t, url+"zip?zipPath=%2F%E4%B8%AD%E6%96%87%2F&zipName=%E4%B8%AD%E6%96%87")
|
||||
if len(files) != 1 || files[0].Name != "檔案.html" {
|
||||
t.Fatal("invalid zip generated")
|
||||
}
|
||||
|
||||
// ~~~~~~~~~~~~~~~~~
|
||||
|
||||
Reference in New Issue
Block a user