clone

a self-hosted multitenant nostr relay with sites, file storage, git hosting, and inbox and outbox delivery

test: seed repository for smart HTTP capabilities

Dami committed 204f6c0
commit
204f6c008c44bae54b5311ee92252416343dd8d4
parent
8511cabfbc945b0eea651b79615bd40d60c8cb09
author
Dami <dami.etoile@gmail.com>
1 file changed, +23 -0
Minternal/gitrelay/gitrelay_test.go23+++++++++++++++++++++++
M internal/gitrelay/gitrelay_test.go +23 -0
@@ -695,6 +695,29 @@ func TestSmartHTTPServesBareRepository(t *testing.T) {
695695 if _, err := os.Stat(filepath.Join(root, "git", owner, "http.git", "HEAD")); err != nil {696696 t.Fatalf("repo: %v", err)697697 }698+ // Git 2.39 does not include upload-pack capabilities in an advertisement699+ // for an empty repository. Seed one valid commit so this exercises the700+ // capability negotiation used by browser clients.701+ repo := g.repoPath(r)702+ treeCmd := exec.Command("git", "--git-dir", repo, "mktree")703+ treeCmd.Stdin = strings.NewReader("")704+ tree, err := treeCmd.Output()705+ if err != nil {706+ t.Fatalf("empty tree: %v", err)707+ }708+ commitCmd := exec.Command("git", "--git-dir", repo, "commit-tree", strings.TrimSpace(string(tree)), "-m", "initial state")709+ commitCmd.Env = append(os.Environ(),710+ "GIT_AUTHOR_NAME=tinyrelay test", "GIT_AUTHOR_EMAIL=test@example.invalid",711+ "GIT_COMMITTER_NAME=tinyrelay test", "GIT_COMMITTER_EMAIL=test@example.invalid",712+ )713+ commit, err := commitCmd.Output()714+ if err != nil {715+ t.Fatalf("initial commit: %v", err)716+ }717+ update := exec.Command("git", "--git-dir", repo, "update-ref", "refs/heads/main", strings.TrimSpace(string(commit)))718+ if out, err := update.CombinedOutput(); err != nil {719+ t.Fatalf("initial ref: %v: %s", err, out)720+ }698721 req := httptest.NewRequest(http.MethodGet, "/npub/npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6/http.git/info/refs?service=git-upload-pack", nil)699722 if got, err := decodeNPub("npub180cvv07tjdrrgpa0j7j7tmnyl2yr6yr7l8j4s3evf6u64th6gkwsyjh6w6"); err != nil {700723 t.Fatalf("known npub: %v", err)