Files
simplegit/gitcmd/download_test.go
T
2026-07-15 11:06:48 -04:00

66 lines
1.5 KiB
Go

package gitcmd
import (
"bytes"
"strings"
"testing"
)
func TestPatch(t *testing.T) {
f := newFixture(t)
p, err := f.repo.Patch(f.c3)
if err != nil {
t.Fatal(err)
}
if !strings.HasPrefix(p, "From ") {
t.Errorf("patch missing mailbox 'From ' header:\n%s", p)
}
if !strings.Contains(p, "From: Alice <alice@example.com>") {
t.Errorf("patch missing author header")
}
if !strings.Contains(p, "expand readme") {
t.Errorf("patch missing commit subject 'expand readme'")
}
if !strings.Contains(p, "-line2") || !strings.Contains(p, "+line3") {
t.Errorf("patch missing diff body (-line2/+line3):\n%s", p)
}
}
func TestArchive_Zip(t *testing.T) {
f := newFixture(t)
var buf bytes.Buffer
if err := f.repo.Archive("HEAD", "zip", &buf); err != nil {
t.Fatal(err)
}
if buf.Len() == 0 {
t.Fatal("archive is empty")
}
got := buf.Bytes()
want := []byte{'P', 'K', 0x03, 0x04}
if !bytes.HasPrefix(got, want) {
t.Errorf("archive prefix = % x, want % x (zip signature)", got[:4], want)
}
}
func TestArchive_TarAndDefault(t *testing.T) {
f := newFixture(t)
var buf1 bytes.Buffer
if err := f.repo.Archive(f.c1, "", &buf1); err != nil {
t.Fatal(err)
}
if !bytes.HasPrefix(buf1.Bytes(), []byte{'P', 'K', 0x03, 0x04}) {
t.Errorf("default format should be zip, got % x", buf1.Bytes()[:4])
}
var buf2 bytes.Buffer
if err := f.repo.Archive(f.c1, "tar", &buf2); err != nil {
t.Fatal(err)
}
if buf2.Len() == 0 || bytes.HasPrefix(buf2.Bytes(), []byte{'P', 'K'}) {
t.Errorf("tar archive unexpected: % x", buf2.Bytes()[:4])
}
}