tests: add end-to-end SSH transport coverage · Entire
tests: add end-to-end SSH transport coverage
66b928d→main·
Soph·2mo ago·3 files·+163 added/-3 removed
Sessions
f9da8767b8dbView transcript
Changes
3
internal
gitproto
Mssh.go+55/-1
Mssh_test.go+2/-2
package gitproto
import (
"bufio"
"bytes"
"context"
"errors"
)
func discardSSHAdvertisement(stdout io.ReadCloser) (io.ReadCloser, error) {
buffered := bufio.NewReader(stdout)
header, err := buffered.Peek(4)
if err != nil {
if errors.Is(err, io.EOF) {
return &bufferedReadCloser{Reader: buffered, Closer: stdout}, nil
}
return nil, err
}
if !looksLikePktlineHeader(header) {
return &bufferedReadCloser{Reader: buffered, Closer: stdout}, nil
}
reader := NewPacketReader(buffered)
for {
kind, _, err := reader.ReadPacket()
if err != nil {
return nil, err
}
if kind == PacketFlush {
break
}
}
return &bufferedReadCloser{Reader: reader.BufReader(), Closer: stdout}, nil
}
Integration Test: Sync Over SSH Shim
package syncer
import (
"context"
"os"
"path/filepath"
"strings"
"testing"
"entire.io/entire/git-sync/internal/gitproto"
"github.com/go-git/go-git/v6/plumbing"
)
func TestRun_IntegrationSyncOverSSHShimV2(t *testing.T) {
root := t.TempDir()
sourceBare := filepath.Join(root, "source.git")
targetBare := filepath.Join(root, "target.git")
worktree := filepath.Join(root, "worktree")
logFile := filepath.Join(root, "ssh.log")
shim := filepath.Join(root, "ssh-shim.sh")
runGit(t, root, "init", "--bare", sourceBare)
runGit(t, root, "init", "--bare", targetBare)
runGit(t, root, "init", worktree)
runGit(t, worktree, "config", "user.name", "test")
runGit(t, worktree, "config", "user.email", "test@example.com")
writeFile(t, filepath.Join(worktree, "tracked.txt"), "hello over ssh\n")
runGit(t, worktree, "add", "tracked.txt")
runGit(t, worktree, "commit", "-m", "initial")
runGit(t, worktree, "remote", "add", "origin", sourceBare)
runGit(t, worktree, "push", "origin", "HEAD:refs/heads/"+testBranch)
shimBody := strings.Join([]string{
"#!/bin/sh",
"if [ \"$1\" = \"-o\" ]; then",
" shift 2",
"fi",
"if [ \"$1\" = \"-p\" ]; then",
" shift 2",
"fi",
"dest=\"$1\"",
"remote=\"$2\"",
"printf '%s\t%s\n' \"$dest\" \"$remote\" >>" + shSingleQuote(logFile),
"exec sh -c \"$remote\"",
}, "\n")
if err := os.WriteFile(shim, []byte(shimBody), 0o755); err != nil {
t.Fatalf("write ssh shim: %v", err)
}
// Tests continued...
}
This document covers changes and tests related to SSH transport in the Git sync process.