31 lines
806 B
Go
31 lines
806 B
Go
package handler
|
|
|
|
import (
|
|
"path/filepath"
|
|
"testing"
|
|
)
|
|
|
|
func TestZipWriteRoundTrip(t *testing.T) {
|
|
zp := filepath.Join(t.TempDir(), ".zddc.zip")
|
|
if err := writeZipAtomic(zp, map[string][]byte{"a.txt": []byte("v1")}, []string{"a.txt"}); err != nil {
|
|
t.Fatalf("seed: %v", err)
|
|
}
|
|
m, ord, err := readZipMembers(zp)
|
|
if err != nil {
|
|
t.Fatalf("read1: %v", err)
|
|
}
|
|
addMember(m, &ord, "*/.zddc", []byte("hello-wildcard"))
|
|
if err := writeZipAtomic(zp, m, ord); err != nil {
|
|
t.Fatalf("write2: %v", err)
|
|
}
|
|
m2, _, err := readZipMembers(zp)
|
|
if err != nil {
|
|
t.Fatalf("read2: %v", err)
|
|
}
|
|
if got := string(m2["*/.zddc"]); got != "hello-wildcard" {
|
|
t.Errorf("wildcard member = %q, want hello-wildcard", got)
|
|
}
|
|
if got := string(m2["a.txt"]); got != "v1" {
|
|
t.Errorf("a.txt = %q, want v1", got)
|
|
}
|
|
}
|