Help us shape the future of Go! Take the 2026 Go Developer Survey

gitlabtest

package
v1.0.0-rc.7 Latest Latest
Warning

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

Go to latest
Published: Oct 23, 2026 License: Apache-2.0 Imports: 11 Imported by: 0

Documentation

Overview

Package gitlabtest is a fake GitLab for tests of code that reaches GitLab through internal/gitlab. It serves the merge request, project and branch endpoints AppTown uses, keeps each merge request's state and the descriptions written to it, and records the merges asked of it. What a merge does to Git is the test's business: it supplies OnMerge.

Index

Constants

View Source
const Token = "test-token"

Token is the only token the fake accepts.

Variables

This section is empty.

Functions

This section is empty.

Types

type Merge

type Merge struct {
	Project  string
	IID      int
	SHA      string
	Message  string
	Squash   bool
	Settings gitlab.MergeSettings
}

Merge is one merge call as the fake received it, with the project settings in force when it arrived.

type Refusal

type Refusal struct {
	Status  int
	Message string
}

Refusal is an answer a hook gives GitLab's way: an HTTP status and message.

func (*Refusal) Error

func (r *Refusal) Error() string

type Server

type Server struct {
	URL string

	// OnRead refreshes a merge request before it is served (a head that
	// follows a real remote, say).
	OnRead func(project string, mr *gitlab.MergeRequest)
	// OnMerge performs a merge. A nil error marks the request merged; a
	// *Refusal is answered as GitLab would, any other error as a 500.
	OnMerge func(m Merge, mr *gitlab.MergeRequest) error
	// OnBranch answers a branch's head commit.
	OnBranch func(project, branch string) (string, error)
	// contains filtered or unexported fields
}

Server is the fake. Its hooks run with its lock held, so they may change the merge request they are handed but must not call the server.

func New

func New(t testing.TB) *Server

New starts a fake GitLab that closes when the test ends. Its projects merge fast-forward, never squash and do not rebase automatically until told otherwise.

func (*Server) Client

func (s *Server) Client() (*gitlab.Client, error)

Client is a provider client for this fake.

func (*Server) Descriptions

func (s *Server) Descriptions(project string, iid int) []string

Descriptions are the descriptions a merge request was given, oldest first: the one it was opened with, then each replacement.

func (*Server) Merges

func (s *Server) Merges() []Merge

Merges are the merge calls received, in order, refused ones included.

func (*Server) Put

func (s *Server) Put(project string, mr gitlab.MergeRequest)

Put records a merge request as GitLab holds it.

func (*Server) RefuseDescriptions

func (s *Server) RefuseDescriptions(r *Refusal)

RefuseDescriptions makes every description update fail with r; nil accepts them again.

func (*Server) Request

func (s *Server) Request(project string, iid int) (gitlab.MergeRequest, bool)

Request is a recorded merge request and whether it exists.

func (*Server) Settings

func (s *Server) Settings(settings gitlab.MergeSettings)

Settings sets how every project merges, as GitLab reports it.

func (*Server) Update

func (s *Server) Update(project string, iid int, change func(*gitlab.MergeRequest))

Update changes a recorded merge request.

Jump to

Keyboard shortcuts

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