hosttest

package
v0.4.0 Latest Latest
Warning

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

Go to latest
Published: Nov 24, 2026 License: Apache-2.0 Imports: 15 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package hosttest fakes the pull request APIs of GitLab (REST v4), Gitea and Forgejo (/api/v1) and Bitbucket Cloud (2.0) for one repository, and optionally serves git over HTTP for it (git http-backend), so tests never call a real host.

h := hosttest.New(t, store.ProviderGitLab, "acme/shop", "Bearer gl-token")
h.ServeGit(t, bareRepoDir, "oauth2", "gl-token")
repo.BaseURL = h.URL

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Host

type Host struct {
	Kind   store.Provider
	Remote string // the repository's path on the host
	Auth   string // the Authorization header the API accepts
	URL    string // the fake's address: the repository's base URL
	// contains filtered or unexported fields
}

Host is the fake. Its API checks the Authorization header.

func New

func New(t *testing.T, kind store.Provider, remote, auth string) *Host

New starts a fake host for one repository.

func (*Host) Add

func (h *Host) Add(p PR)

Add puts a pull request on the host (one someone else opened).

func (*Host) Counts

func (h *Host) Counts() (created, updated int)

Counts is how many pull requests were created and updated.

func (*Host) GitRequests

func (h *Host) GitRequests() []string

GitRequests lists the git requests as "PATH user:pass".

func (*Host) PR

func (h *Host) PR(n int) *PR

PR returns a copy of pull request n, or nil.

func (*Host) PRURL

func (h *Host) PRURL(n int) string

PRURL is the page of pull request n.

func (*Host) Requests

func (h *Host) Requests() []string

Requests lists the API requests as "METHOD PATH".

func (*Host) ServeGit

func (h *Host) ServeGit(t *testing.T, dir, user, pass string)

ServeGit serves the git repository at dir (bare, or a work tree's .git) as REMOTE.git over smart HTTP, for Basic auth user:pass only. It needs the git binary; the test is skipped without one.

func (*Host) ServeHTTP

func (h *Host) ServeHTTP(w http.ResponseWriter, r *http.Request)

func (*Host) SetState

func (h *Host) SetState(n int, state string)

SetState merges or closes pull request n, as a person on the host would.

type PR

type PR struct {
	Number      int
	Head, Base  string
	Title, Body string
	State       string // open, merged, closed
	Draft       bool
	Fork        bool // from another repository
}

PR is a pull request (GitLab: merge request) on the fake host.

Jump to

Keyboard shortcuts

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