gittestserver

package module
v0.12.0 Latest Latest
Warning

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

Go to latest
Published: Apr 26, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type GitServer

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

GitServer is a git server for testing purposes. It can serve git repositories over HTTP and SSH.

func NewGitServer

func NewGitServer(docroot string) *GitServer

NewGitServer returns a GitServer with the given repository docroot set.

func NewTempGitServer

func NewTempGitServer() (*GitServer, error)

NewTempGitServer returns a GitServer with a newly created temp dir as repository docroot.

func (*GitServer) AddHTTPMiddlewares added in v0.4.2

func (s *GitServer) AddHTTPMiddlewares(httpMiddlewares ...HTTPMiddleware)

AddHTTPMiddlewares adds http middlewares to the git server.

func (*GitServer) Auth added in v0.2.1

func (s *GitServer) Auth(username, password string) *GitServer

Auth switches authentication on for both HTTP and SSH servers. It's not possible to switch authentication on for just one of them. The username and password provided are _only_ used for HTTP. SSH relies on key authentication, but won't work with libgit2 unless auth is enabled.

func (*GitServer) AutoCreate

func (s *GitServer) AutoCreate() *GitServer

AutoCreate enables the automatic creation of a non-existing Git repository on push.

func (*GitServer) HTTPAddress

func (s *GitServer) HTTPAddress() string

HTTPAddress returns the address of the HTTP git server. This will not include credentials. Use if you have not enable authentication, or if you are specifically testing the use of credentials.

func (*GitServer) HTTPAddressWithCredentials added in v0.2.1

func (s *GitServer) HTTPAddressWithCredentials() string

HTTPAddressWithCredentials returns the address of the HTTP git server, including credentials if authentication has been enabled. Use this if you need to be able to access the git server to set up fixtures etc..

func (*GitServer) InitRepo added in v0.4.0

func (s *GitServer) InitRepo(fixture, branch, repoPath string) error

InitRepo initializes a new repository in the git server with the given fixture at the repoPath.

func (*GitServer) InstallUpdateHook added in v0.3.1

func (s *GitServer) InstallUpdateHook(script string) *GitServer

InstallUpdateHook installs a hook script that will run running _before_ a push is accepted, as described at

https://git-scm.com/book/en/v2/Customizing-Git-Git-Hooks

The provided string is written as an executable script to the hooks directory; start with a hashbang to make sure it'll run, e.g.,

#!/bin/bash

func (*GitServer) KeyDir added in v0.2.0

func (s *GitServer) KeyDir(dir string) *GitServer

KeyDir sets the SSH key directory in the config. Use before calling StartSSH.

func (*GitServer) ListenSSH added in v0.2.0

func (s *GitServer) ListenSSH() error

ListenSSH creates an SSH server and a listener if not already created, but does not handle connections. This returns immediately, unlike StartSSH(), and the server URL is available with SSHAddress() after calling this.

func (*GitServer) PublicKeyLookupFunc added in v0.5.3

func (s *GitServer) PublicKeyLookupFunc(f func(content string) (*gitkit.PublicKey, error))

PublicKeyLookupFunc sets the function to be used for SSH authentication.

func (*GitServer) ReadOnly added in v0.6.0

func (s *GitServer) ReadOnly(readOnly bool) *GitServer

ReadOnly sets the current connection to read-only. This simulates when users don't have write access, and the server ungracefully short-circuit the connection which may lead to EOF/early EOF at the client side.

func (*GitServer) Root

func (s *GitServer) Root() string

Root returns the repositories root directory.

func (*GitServer) SSHAddress

func (s *GitServer) SSHAddress() string

SSHAddress returns the address of the SSH git server as a URL.

func (*GitServer) StartHTTP

func (s *GitServer) StartHTTP() error

StartHTTP starts a new HTTP git server with the current configuration.

func (*GitServer) StartHTTPS added in v0.1.0

func (s *GitServer) StartHTTPS(cert, key, ca []byte, serverName string) error

StartHTTPS starts the TLS HTTPServer with the given TLS configuration.

func (*GitServer) StartSSH

func (s *GitServer) StartSSH() error

StartSSH creates a SSH git server and listener with the current configuration if necessary, and handles connections. Unless it returns an error immediately, this will block until the listener is stopped with `s.StopSSH()`. Usually you will want to use ListenSSH() first, so you can get the URL of the SSH git server before starting it.

func (*GitServer) StopHTTP

func (s *GitServer) StopHTTP()

StopHTTP stops the HTTP git server.

func (*GitServer) StopSSH

func (s *GitServer) StopSSH() error

StopSSH stops the SSH git server.

func (*GitServer) WithSSHConfig added in v0.5.3

func (g *GitServer) WithSSHConfig(cfg *ssh.ServerConfig) *GitServer

WithSSHConfig sets the ssh.ServerConfig for the SSH Server.

type HTTPMiddleware added in v0.4.2

type HTTPMiddleware func(http.Handler) http.Handler

HTTPMiddleware is a git http server middleware.

Jump to

Keyboard shortcuts

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