readertest

package
v0.27.0 Latest Latest
Warning

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

Go to latest
Published: Oct 18, 2026 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Overview

Package readertest is the shared test kit of the RepoReader adapters: Git fixtures built with the git binary, the conformance table every adapter must pass, and the comparison of one adapter with another.

Index

Constants

This section is empty.

Variables

View Source
var LargeBudget = Budget{Revs: 4, LogRevs: 2, Dirs: 6, Files: 8, LogPaths: 5, LastTrees: 3}

LargeBudget suits a repository of thousands of commits.

View Source
var SmallBudget = Budget{Revs: 24, LogRevs: 8, Dirs: 10, Files: 10, LogPaths: 6, LastTrees: 6}

SmallBudget suits the fixtures.

Functions

func CommitObjects added in v0.26.0

func CommitObjects(t *testing.T, mk CommitObjectsMaker)

CommitObjects runs the CommitObjectReader contract against the readers mk builds: the raw bytes of unsigned and SSH-signed commits equal `git cat-file commit`; missing ids, trees and blobs are left out; a missing repository is domain.ErrNotFound; too many ids are domain.ErrInvalid.

func Compare

func Compare(t *testing.T, want, got ports.RepoReader, repo domain.RepoName, dir string, b Budget)

Compare asks both readers the same questions about the repository and requires the same answers: the same values, and the same kind of error. want is the oracle (the CLI reader).

func Conformance

func Conformance(t *testing.T, mk Maker)

Conformance runs the RepoReader contract against the readers mk builds: every adapter that serves repositories must pass it, whatever its route.

func GitOut

func GitOut(t testing.TB, dir string, args ...string) string

GitOut runs git in dir and returns its trimmed output.

func MustID

func MustID(t *testing.T, s string) domain.ObjectID

MustID parses an object id.

func ObjectID added in v0.26.0

func ObjectID(t testing.TB, s string) domain.ObjectID

ObjectID parses a full object id.

func RandomBytes

func RandomBytes(n int, seed uint64) []byte

RandomBytes returns n deterministic incompressible bytes.

func RepoName

func RepoName(t testing.TB, s string) domain.RepoName

RepoName parses a repository name.

func Rev

func Rev(t *testing.T, s string) domain.Revision

Rev parses a revision.

func TreePath

func TreePath(t *testing.T, s string) domain.TreePath

TreePath parses a tree path.

Types

type Budget

type Budget struct {
	Revs      int // revisions (refs and commits) for trees and blobs
	LogRevs   int // revisions for history pages
	Dirs      int // directories per revision
	Files     int // files per revision
	LogPaths  int // paths for path-limited history
	LastTrees int // trees listed with last commits
}

Budget bounds how many revisions and paths Compare asks about, so that it stays fast on a large repository.

type Case

type Case struct {
	Name  string
	Build func(t *testing.T, data string) *Fixture
}

Case is a repository the readers are compared on.

func Cases

func Cases() []Case

Cases are the fixtures of the comparison: everything the gitcli tests use, plus merges, tags, deep paths, a large blob, an unborn HEAD, repositories with and without commit-graph (Bloom filters v1 and v2), and one whose graph is stale because commits were pushed after the last maintenance.

type CommitObjectsMaker added in v0.26.0

type CommitObjectsMaker func(t *testing.T) (ports.CommitObjectReader, string)

CommitObjectsMaker builds a CommitObjectReader serving the repositories below data/repos, and returns it with the data directory.

type Fixture

type Fixture struct {
	T    testing.TB
	Name domain.RepoName
	Bare string
	Work string
	When time.Time
}

Fixture builds a repository with real git: a bare repository in the data directory, and a work tree beside it that the helpers edit and commit.

func NewFixture

func NewFixture(t testing.TB, data, repo string) *Fixture

NewFixture creates an empty bare repository repos/<name>.git whose HEAD is refs/heads/main.

func (*Fixture) Checkout

func (f *Fixture) Checkout(branch string)

func (*Fixture) CheckoutNew

func (f *Fixture) CheckoutNew(branch string)

CheckoutNew creates a branch from the current HEAD and switches to it.

func (*Fixture) Chmod

func (f *Fixture) Chmod(p string, mode os.FileMode) *Fixture

func (*Fixture) Commit

func (f *Fixture) Commit(msg string) string

Commit stages everything and commits with the next timestamp; it returns the commit id.

func (*Fixture) Git

func (f *Fixture) Git(args ...string) string

Git runs git against the bare repository and the work tree.

func (*Fixture) Lines

func (f *Fixture) Lines(p, prefix string, n int) *Fixture

Lines writes n lines "<prefix> <i>" to the file.

func (*Fixture) Maintain

func (f *Fixture) Maintain()

Maintain runs what ermite runs after a push: a split commit-graph with changed-path Bloom filters.

func (*Fixture) Merge

func (f *Fixture) Merge(branch string) string

Merge merges the branch with a merge commit.

func (*Fixture) Mv

func (f *Fixture) Mv(from, to string) *Fixture

func (*Fixture) Path

func (f *Fixture) Path(p string) string

Path returns the path of a file of the work tree.

func (*Fixture) Remove

func (f *Fixture) Remove(p string) *Fixture
func (f *Fixture) Symlink(target, p string) *Fixture

func (*Fixture) Write

func (f *Fixture) Write(p, content string) *Fixture

Write creates or replaces a file with the content.

func (*Fixture) WriteBytes

func (f *Fixture) WriteBytes(p string, content []byte) *Fixture

WriteBytes is Write for binary content.

func (*Fixture) WriteObject

func (f *Fixture) WriteObject(typ, content string) string

WriteObject stores a raw object of the given type (commit, tag...) built by hand, for what git itself refuses to write, and returns its id.

type History

type History struct {
	*Fixture
	C1, C2, C3, Side, Merge string
}

History is the repository of the read tests: three commits on main, a branch with a slash, a merge, lightweight and annotated tags.

func NewHistory

func NewHistory(t *testing.T, data string) *History

type Maker

type Maker func(t *testing.T) (ports.RepoReader, string)

Maker builds a RepoReader serving the repositories below data/repos, and returns it with the data directory. The reader is closed when the test ends.

type Queries

type Queries struct {
	Revs     []string // revisions as a client writes them
	LogRevs  []string
	Dirs     []string
	Files    []string
	LogPaths []string
	RefPaths []string
}

Queries are the questions put to both readers about one repository.

func Derive

func Derive(t testing.TB, dir string, b Budget) Queries

Derive builds the questions for the repository in dir with git.

Jump to

Keyboard shortcuts

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