testgitserver

package
v1.40.4 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: MIT Imports: 12 Imported by: 0

Documentation

Overview

Package testgitserver provides a local Git HTTP server for testing using git-http-backend.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GitCommand

func GitCommand(ctx context.Context, dir string, args ...string) *exec.Cmd

GitCommand creates a git command with standard test environment variables.

Types

type Server

type Server struct {
	// contains filtered or unexported fields
}

Server represents a local Git HTTP server using git http-backend.

func NewServer

func NewServer(repoRoot string) (*Server, error)

NewServer creates a new local Git HTTP server for testing. repoRoot is the directory containing Git repositories. This creates an httptest.Server for use in tests.

func NewServerWithoutHTTP

func NewServerWithoutHTTP(repoRoot string) (*Server, error)

NewServerWithoutHTTP creates a Server without starting an httptest.Server. This is useful when you want to use the handler with your own HTTP server.

func (*Server) Close

func (s *Server) Close()

Close shuts down the server.

func (*Server) Handler

func (s *Server) Handler() http.Handler

Handler returns an HTTP handler that serves Git repositories via git-http-backend.

func (*Server) URL

func (s *Server) URL() string

URL returns the base URL of the Git server.

type TestRepo

type TestRepo struct {
	Path    string
	RepoURL string // URL path (e.g., "/test/repo.git")
	Commits []string
}

TestRepo represents a test Git repository with known commits.

func CreateTestRepo

func CreateTestRepo(t *testing.T, repoRoot, repoPath string, numCommits int) *TestRepo

CreateTestRepo creates a Git repository with a specified number of commits. The repository will be created at repoRoot/repoPath. Returns the commit SHAs in chronological order (oldest first).

func (*TestRepo) MainCommit

func (r *TestRepo) MainCommit() string

MainCommit returns the latest (main) commit SHA.

func (*TestRepo) OlderCommit

func (r *TestRepo) OlderCommit() string

OlderCommit returns an older commit SHA (5th from the end if available).

func (*TestRepo) PrevCommit

func (r *TestRepo) PrevCommit() string

PrevCommit returns the second-to-last commit SHA.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL