testhelper

package
v1.87.0 Latest Latest
Warning

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

Go to latest
Published: Feb 17, 2020 License: MIT Imports: 47 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TestRelativePath    = "gitlab-test.git"
	RepositoryAuthToken = "the-secret-token"
	DefaultStorageName  = "default"
)

TestRelativePath is the path inside its storage of the gitlab-test repo

Variables

View Source
var NewTestLogger = DiscardTestLogger

NewTestLogger creates logger that should be used in the tests.

Functions

func AddWorktree added in v0.90.0

func AddWorktree(t *testing.T, repoPath string, worktreeName string)

AddWorktree creates a worktree in the repository path for tests

func AddWorktreeArgs added in v1.34.0

func AddWorktreeArgs(repoPath, worktreeName string) []string

AddWorktreeArgs returns git command arguments for adding a worktree at the specified repo

func AssertPathNotExists added in v1.63.0

func AssertPathNotExists(t *testing.T, path string)

AssertPathNotExists asserts true if the path doesn't exist, false otherwise

func AuthorsEqual added in v0.15.0

func AuthorsEqual(a *gitalypb.CommitAuthor, b *gitalypb.CommitAuthor) bool

AuthorsEqual tests if two `CommitAuthor`s are equal

func CaptureHookEnv added in v1.13.0

func CaptureHookEnv(t *testing.T) (hookPath string, cleanup func())

CaptureHookEnv creates a bogus 'update' Git hook to sniff out what environment variables get set for hooks.

func CommitBlobWithName added in v1.49.0

func CommitBlobWithName(t *testing.T, testRepoPath, blobID, fileName, commitMessage string) string

CommitBlobWithName will create a commit for the specified blob with the specified name. This enables testing situations where the filepath is not possible due to filesystem constraints (e.g. non-UTF characters). The commit ID is returned.

func ConfigureGitalyHooksBinary added in v1.87.0

func ConfigureGitalyHooksBinary()

ConfigureGitalyHooksBinary builds gitaly-hooks command for tests

func ConfigureGitalySSH added in v0.66.0

func ConfigureGitalySSH()

ConfigureGitalySSH configures the gitaly-ssh command for tests

func ConfigureRuby added in v0.26.0

func ConfigureRuby() error

ConfigureRuby configures Ruby settings for test purposes at run time.

func Context added in v0.40.0

func Context() (context.Context, func())

Context returns a cancellable context.

func CreateCommit added in v0.63.0

func CreateCommit(t *testing.T, repoPath, branchName string, opts *CreateCommitOpts) string

CreateCommit makes a new empty commit and updates the named branch to point to it.

func CreateCommitInAlternateObjectDirectory added in v0.86.0

func CreateCommitInAlternateObjectDirectory(t *testing.T, repoPath, altObjectsDir string, cmd *exec.Cmd) (currentHead []byte)

CreateCommitInAlternateObjectDirectory runs a command such that its created objects will live in an alternate objects directory. It returns the current head after the command is run and the alternate objects directory path

func CreateCommitOnNewBranch added in v1.55.0

func CreateCommitOnNewBranch(t *testing.T, repoPath string) (string, string)

CreateCommitOnNewBranch creates a branch and a commit, returning the commit sha and the branch name respectivelyi

func CreateLooseRef added in v1.34.0

func CreateLooseRef(t *testing.T, repoPath, refName string)

CreateLooseRef creates a ref that points to master

func CreateRemoteBranch added in v0.113.0

func CreateRemoteBranch(t *testing.T, repoPath, remoteName, branchName, ref string)

CreateRemoteBranch creates a new remote branch

func CreateRepo added in v1.26.0

func CreateRepo(t testing.TB, storagePath string) (repo *gitalypb.Repository, repoPath, relativePath string)

CreateRepo creates a temporary directory for a repo, without initializing it

func CreateTag added in v0.93.0

func CreateTag(t *testing.T, repoPath, tagName, targetID string, opts *CreateTagOpts) string

CreateTag creates a new tag.

func CreateTemporaryGitlabShellDir added in v1.87.0

func CreateTemporaryGitlabShellDir(t *testing.T) (string, func())

CreateTemporaryGitlabShellDir creates a temporary gitlab shell directory. It returns the path to the directory and a cleanup function

func DiscardTestEntry added in v1.87.0

func DiscardTestEntry(tb testing.TB) *log.Entry

DiscardTestLogger created a logrus entry that discards everything.

func DiscardTestLogger added in v1.87.0

func DiscardTestLogger(tb testing.TB) *log.Logger

DiscardTestLogger created a logrus hook that discards everything.

func EnableGitProtocolV2Support added in v0.129.1

func EnableGitProtocolV2Support() func()

EnableGitProtocolV2Support replaces the git binary in config with an `env_git` wrapper that allows the protocol to be tested. It returns a function that restores the given settings.

Because we don't know how to get to that wrapper script from the current working directory, callers must create a symbolic link to the `env_git` file in their own `testdata` directories.

func EnvForHooks added in v1.87.0

func EnvForHooks(t *testing.T, glRepo, gitlabShellDir string, key int, gitPushOptions ...string) []string

EnvForHooks generates a set of environment variables for gitaly hooks

func FindLocalBranchCommitAuthorsEqual added in v0.15.0

func FindLocalBranchCommitAuthorsEqual(a *gitalypb.FindLocalBranchCommitAuthor, b *gitalypb.FindLocalBranchCommitAuthor) bool

FindLocalBranchCommitAuthorsEqual tests if two `FindLocalBranchCommitAuthor`s are equal

func FindLocalBranchResponsesEqual added in v0.15.0

func FindLocalBranchResponsesEqual(a *gitalypb.FindLocalBranchResponse, b *gitalypb.FindLocalBranchResponse) bool

FindLocalBranchResponsesEqual tests if two `FindLocalBranchResponse`s are equal

func GetGitEnvData added in v0.125.0

func GetGitEnvData() (string, error)

GetGitEnvData reads and returns the content of testGitEnv

func GetGitObjectDirSize added in v1.79.0

func GetGitObjectDirSize(t *testing.T, repoPath string) int64

GetGitObjectDirSize gets the number of 1k blocks of a git object directory

func GetGitPackfileDirSize added in v1.81.0

func GetGitPackfileDirSize(t *testing.T, repoPath string) int64

GetGitPackfileDirSize gets the number of 1k blocks of a git object directory

func GetLocalhostListener added in v1.76.0

func GetLocalhostListener(t testing.TB) (net.Listener, string)

GetLocalhostListener listens on the next available TCP port and returns the listener and the localhost address (host:port) string.

func GetRepositoryRefs added in v0.66.0

func GetRepositoryRefs(t *testing.T, repoPath string) string

GetRepositoryRefs gives a list of each repository ref as a string

func GetTemporaryGitalySocketFileName added in v0.24.0

func GetTemporaryGitalySocketFileName() string

GetTemporaryGitalySocketFileName will return a unique, useable socket file name

func GitCommitEqual added in v0.53.0

func GitCommitEqual(a, b *gitalypb.GitCommit) error

GitCommitEqual tests if two `GitCommit`s are equal

func GitObjectMustExist added in v1.67.0

func GitObjectMustExist(t testing.TB, repoPath, sha string)

GitObjectMustExist is a test assertion that fails unless the git repo in repoPath contains sha

func GitObjectMustNotExist added in v1.67.0

func GitObjectMustNotExist(t testing.TB, repoPath, sha string)

GitObjectMustNotExist is a test assertion that fails unless the git repo in repoPath contains sha

func GitalyServersMetadata added in v0.56.0

func GitalyServersMetadata(t *testing.T, serverSocketPath string) metadata.MD

GitalyServersMetadata returns a metadata pair for gitaly-servers to be used in inter-gitaly operations.

func GitlabTestStoragePath added in v0.8.0

func GitlabTestStoragePath() string

GitlabTestStoragePath returns the storage path to the gitlab-test repo.

func InitBareRepo added in v0.72.0

func InitBareRepo(t *testing.T) (*gitalypb.Repository, string, func())

InitBareRepo creates a new bare repository

func InitRepoWithWorktree added in v0.88.0

func InitRepoWithWorktree(t *testing.T) (*gitalypb.Repository, string, func())

InitRepoWithWorktree creates a new repository with a worktree

func MustHaveNoChildProcess added in v0.38.0

func MustHaveNoChildProcess()

MustHaveNoChildProcess panics if it finds a running or finished child process. It waits for 2 seconds for processes to be cleaned up by other goroutines.

func MustReadFile

func MustReadFile(t *testing.T, filename string) []byte

MustReadFile returns the content of a file or fails at once.

func MustRunCommand added in v0.5.0

func MustRunCommand(t testing.TB, stdin io.Reader, name string, args ...string) []byte

MustRunCommand runs a command with an optional standard input and returns the standard output, or fails.

func NewGitlabTestServer added in v1.87.0

func NewGitlabTestServer(t *testing.T, c GitlabServerConfig) *httptest.Server

NewGitlabTestServer returns a mock gitlab server that responds to the hook api endpoints

func NewServerWithHealth added in v1.87.0

func NewServerWithHealth(t testing.TB, socketName string) (*grpc.Server, *health.Server)

func NewTestGrpcServer added in v0.30.0

func NewTestGrpcServer(tb testing.TB, streamInterceptors []grpc.StreamServerInterceptor, unaryInterceptors []grpc.UnaryServerInterceptor) *grpc.Server

NewTestGrpcServer creates a GRPC Server for testing purposes

func NewTestObjectPoolName added in v1.27.1

func NewTestObjectPoolName(t *testing.T) string

NewTestObjectPoolName returns a random pool repository name.

func NewTestRepo added in v0.56.0

func NewTestRepo(t testing.TB) (repo *gitalypb.Repository, repoPath string, cleanup func())

NewTestRepo creates a bare copy of the test repository.

func NewTestRepoWithWorktree added in v0.56.0

func NewTestRepoWithWorktree(t testing.TB) (repo *gitalypb.Repository, repoPath string, cleanup func())

NewTestRepoWithWorktree creates a copy of the test repository with a worktree. This is allows you to run normal 'non-bare' Git commands.

func ReceiveEOFWithTimeout added in v1.36.0

func ReceiveEOFWithTimeout(errorFunc func() error) error

ReceiveEOFWithTimeout reads to the end of the stream and will throw an error if a deadlock is suspected

func RemoteExists added in v1.31.0

func RemoteExists(t *testing.T, repoPath string, remoteName string) bool

RemoteExists tests if the repository at repoPath has a Git remote named remoteName.

func RequireGrpcError added in v0.106.0

func RequireGrpcError(t *testing.T, err error, expectedCode codes.Code)

RequireGrpcError asserts the passed err is of the same code as expectedCode.

func SetCtxGrpcMethod added in v1.60.0

func SetCtxGrpcMethod(ctx context.Context, method string) context.Context

SetCtxGrpcMethod will set the gRPC context value for the proper key responsible for an RPC full method name. This directly corresponds to the gRPC function responsible for extracting the method: https://godoc.org/google.golang.org/grpc#Method

func TempDir added in v1.49.0

func TempDir(t *testing.T, prefix string) (string, func() error)

TempDir is a wrapper around ioutil.TempDir that provides a cleanup function. The returned temp directory will be created in the directory specified by environment variable TEST_TEMP_DIR_PATH. If that variable is unset, the relative folder "./testdata/tmp" to this source file will be used.

func TestRepository added in v0.12.0

func TestRepository() *gitalypb.Repository

TestRepository returns the `Repository` object for the gitlab-test repo. Tests should be calling this function instead of cloning the repo themselves. Tests that involve modifications to the repo should copy/clone the repo via the `Repository` returned from this function.

func WriteShellSecretFile added in v1.87.0

func WriteShellSecretFile(t *testing.T, dir, secretToken string)

WriteShellSecretFile writes a .gitlab_shell_secret file in the specified directory

func WriteTemporaryGitalyConfigFile added in v1.87.0

func WriteTemporaryGitalyConfigFile(t *testing.T, tempDir string) (string, func())

WriteTemporaryGitalyConfigFile writes a gitaly toml file into a temporary directory. It returns the path to the file as well as a cleanup function

func WriteTemporaryGitlabShellConfigFile added in v1.87.0

func WriteTemporaryGitlabShellConfigFile(t *testing.T, dir string, config GitlabShellConfig) (string, func())

WriteTemporaryGitlabShellConfigFile writes a gitlab shell config.yml in a temporary directory. It returns the path and a cleanup function

Types

type Cleanup added in v1.72.0

type Cleanup func()

Cleanup functions should be called in a defer statement immediately after they are returned from a test helper

type ConfigFile added in v1.36.0

type ConfigFile map[string][]string

ConfigFile allows access to the different sections of a git config file

func ParseConfig added in v1.36.0

func ParseConfig(src io.Reader) (ConfigFile, error)

ParseConfig will attempt to parse a config file into sections

func (ConfigFile) GetValue added in v1.36.0

func (cf ConfigFile) GetValue(section, key string) (string, bool)

GetValue will return the value for a configuration line int the specified section for the provided key

type CreateCommitOpts added in v0.93.0

type CreateCommitOpts struct {
	Message  string
	ParentID string
}

CreateCommitOpts holds extra options for CreateCommit.

type CreateTagOpts added in v0.93.0

type CreateTagOpts struct {
	Message string
	Force   bool
}

CreateTagOpts holds extra options for CreateTag.

type GitlabServerConfig added in v1.87.0

type GitlabServerConfig struct {
	User, Password, SecretToken string
	Key                         int
	GLRepository                string
	Changes                     string
	PostReceiveCounterDecreased bool
	Protocol                    string
	GitPushOptions              []string
}

GitlabServerConfig is a config for a mock gitlab server

type GitlabShellConfig added in v1.87.0

type GitlabShellConfig struct {
	GitlabURL    string       `yaml:"gitlab_url"`
	HTTPSettings HTTPSettings `yaml:"http_settings"`
}

GitlabShellConfig contains a subset of gitlabshell's config.yml

type HTTPSettings added in v1.87.0

type HTTPSettings struct {
	User     string `yaml:"user"`
	Password string `yaml:"password"`
}

HTTPSettings contains fields for http settings

type TestServer added in v1.85.0

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

TestServer wraps a grpc Server and handles automatically putting a praefect in front of a gitaly instance if necessary

func NewServer added in v1.85.0

func NewServer(tb testing.TB, streamInterceptors []grpc.StreamServerInterceptor, unaryInterceptors []grpc.UnaryServerInterceptor) *TestServer

NewServer creates a Server for testing purposes

func NewTestServer added in v1.85.0

func NewTestServer(srv *grpc.Server) *TestServer

NewTestServer instantiates a new TestServer

func (*TestServer) GrpcServer added in v1.85.0

func (p *TestServer) GrpcServer() *grpc.Server

GrpcServer returns the underlying grpc.Server

func (*TestServer) Socket added in v1.85.0

func (p *TestServer) Socket() string

Socket returns the socket file the test server is listening on

func (*TestServer) Start added in v1.85.0

func (p *TestServer) Start() error

Start will start the grpc server as well as spawn a praefect instance if GITALY_TEST_PRAEFECT_BIN is enabled

func (*TestServer) Stop added in v1.85.0

func (p *TestServer) Stop()

Stop will stop both the grpc server as well as the praefect process

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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