This commit is contained in:
Jabberwocky238
2026-07-17 05:55:31 -04:00
parent 67c07b3bcf
commit 68cda1972c
19 changed files with 897 additions and 897 deletions
+16 -16
View File
@@ -10,9 +10,9 @@ import (
"time"
)
// expectedHookBody is the exact forwarding body every rendered hook carries,
// with %s = the hook name. Kept here so drift in the generator output fails the
// test loudly.
const expectedHookBody = `#!/bin/sh
# simplegit-managed git hook. Forwards this invocation to the simplegit daemon
# hook bus via ` + "`simplegit hook`" + `. The daemon exports SIMPLEGIT_BIN (absolute
@@ -23,9 +23,9 @@ test -n "$SIMPLEGIT_BIN" || exit 0
exec "$SIMPLEGIT_BIN" hook --root="${SIMPLEGIT_ROOT:-}" %s "$@"
`
// TestTemplateInSync asserts the checked-in template/hooks/ files exactly match
// hooks.hookNames: one real script per hook, no more, no less. If hookNames
// changes, rerun the template generator and commit.
func TestTemplateInSync(t *testing.T) {
entries, err := fs.ReadDir(templateFS, "template/hooks")
if err != nil {
@@ -82,7 +82,7 @@ func TestEnsureTemplate(t *testing.T) {
t.Errorf("hook %s: body mismatch\n got: %q\nwant: %q", name, string(body), want)
}
}
// Idempotent: a second run must not error.
if _, err := EnsureTemplate(root); err != nil {
t.Fatalf("EnsureTemplate second run: %v", err)
}
@@ -97,8 +97,8 @@ func TestStartRoundTrip(t *testing.T) {
t.Fatalf("Start: %v", err)
}
// Give the listener a moment to bind (Bind is synchronous, but the accept
// loop runs in a goroutine; the socket file existing is the ready signal).
deadline := time.Now().Add(2 * time.Second)
for {
if _, err := os.Stat(SockPath(root)); err == nil {
@@ -133,8 +133,8 @@ func TestStartRoundTrip(t *testing.T) {
}
func TestForwardFailOpen(t *testing.T) {
// No listener on this root -> dial fails -> forward must return 0 (fail
// open) rather than blocking or rejecting the push.
root := t.TempDir()
exit := forward(HookEvent{Type: "pre-receive"}, SockPath(root))
if exit != 0 {
@@ -144,15 +144,15 @@ func TestForwardFailOpen(t *testing.T) {
func TestResolveRepo(t *testing.T) {
root := t.TempDir()
// GIT_DIR is the primary signal git sets for the hook (relative "." under
// git http-backend / SSH receive-pack, which chdir into the repo); cwd is
// the fallback when GIT_DIR is unset. Both sides are symlink-resolved.
cases := []struct{ gitDir, cwd, want string }{
{filepath.Join(root, "repos", "acme", "widget.git"), "/somewhere", "acme/widget"},
{filepath.Join(root, "repos", "org", "team", "svc.git"), "/somewhere", "org/team/svc"},
// GIT_DIR unset -> fall back to cwd.
{"", filepath.Join(root, "repos", "acme", "widget.git"), "acme/widget"},
// neither under <root>/repos.
{"", "/tmp/elsewhere.git", ""},
{filepath.Join(root, "repos"), "/somewhere", ""},
}