gitlabfake

package
v1.5.0 Latest Latest
Warning

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

Go to latest
Published: Dec 3, 2026 License: MIT Imports: 6 Imported by: ? 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 gitlabfake is a fake of the repository files API of GitLab for the tests of the gitlab flag source: the raw files of one branch of one project, served as GitLab serves them (the project and the file path are each one path segment with "/" sent as %2F, a 404 for a file or a project that is not there, a 401 for a wrong token, a 404 for a private project without a token, the PRIVATE-TOKEN header, the rate limit answers with the RateLimit-* headers), and a record of what the relay sent.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Request

type Request struct {
	// Project and File are the slug and the file path, decoded from their segments.
	Project string
	File    string
	// Ref is the ref query of the request.
	Ref string
	// Token is the PRIVATE-TOKEN header.
	Token string
	// URI is the request line target as it was sent, to show the encoding of the segments.
	URI string
}

Request is what one request carried.

type Server

type Server struct {
	*httpfake.Server
	// contains filtered or unexported fields
}

Server is an http.Handler for /<prefix>/api/v4/projects/<slug>/repository/files/<path>/raw?ref=<branch>. The files are served by the embedded httpfake.Server (Put, Delete, Redirect and Counts).

func New

func New(prefix, slug, branch string, validators httpfake.Validators) *Server

New returns a server for the project slug (group/project) and the branch. prefix is the path of GitLab below the host: empty for gitlab.com, for example /gitlab for a self-managed instance. validators is what the files send.

func (*Server) Requests

func (s *Server) Requests() []Request

Requests returns what the requests carried, in order.

func (*Server) RequireToken

func (s *Server) RequireToken(token string)

RequireToken makes the project private: a request without a token is answered 404 and one with another token 401. Empty makes the project public.

func (*Server) ServeHTTP

func (s *Server) ServeHTTP(w http.ResponseWriter, r *http.Request)

ServeHTTP implements http.Handler.

func (*Server) Throttle

func (s *Server) Throttle(reset time.Time, retryAfterSeconds int)

Throttle makes the server answer every request with 429, no request left, resetting at reset, and a Retry-After of that many seconds (none for zero). A zero reset ends the throttling.

Jump to

Keyboard shortcuts

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