helpers

package
v0.0.0-...-64f7ebe Latest Latest
Warning

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

Go to latest
Published: Sep 19, 2020 License: MIT Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const (
	DefaultAuthor = "Author <author@example.com>"
)

Variables

This section is empty.

Functions

func CleanupConfig

func CleanupConfig(t *testing.T, cfg *config.Config)

Cleanup any and all temp files specified in the configuration.

func CleanupHgRepo

func CleanupHgRepo(t *testing.T, client *hg.HgClient)

Clean up a created Mercurial repository.

func CleanupRepository

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

Clean up a testing repository.

This deletes the temporary files from disk.

func CommitHg

func CommitHg(t *testing.T, client *hg.HgClient, message, author string) string

func CreateAndAddFilesHg

func CreateAndAddFilesHg(t *testing.T, repoPath string, client *hg.HgClient, files map[string][]byte)

func CreateGitBranch

func CreateGitBranch(t *testing.T, repo *repositories.GitRepository, rawRepo *git.Repository) *plumbing.Reference

Create a new branch with some test files, returning the commit ID.

Callers can compare committed file contents with the result of `helpers.GetRepoFiles`.

func CreateGitRepo

func CreateGitRepo(t *testing.T, name string) (*repositories.GitRepository, *git.Repository)

Create a Git Repository for testing.

The caller is responsible for cleaning up the filesystem afterwards.

Example:

```go

func Test(t *testing.T) {
    repo, rawRepo := testing.CreateGitRepo(t)
    defer testing.CleanupRepository(t, repo.Path)

    // ...
}

```

func CreateHgBookmark

func CreateHgBookmark(t *testing.T, client *hg.HgClient, node, bookmark string)

func CreateHgRepo

func CreateHgRepo(t *testing.T, name string) (*repositories.HgRepository, *hg.HgClient)

Create a Mercurial repository for testing.

The caller is responsible for cleaning up the client and filesystem afterwards.

Example:

```go

func Test(t *testing.T) {
    repo, hgClient := testing.CreateHgtRepo(t, "repo-name")
    defer testing.CleanupHgRepo(t, hgClient)

    // ...
}

```

func CreateHgTag

func CreateHgTag(t *testing.T, client *hg.HgClient, node, tag, message, author string) string

func CreateRequestRecorder

func CreateRequestRecorder(t *testing.T) (*httptest.Server, <-chan RecordedRequest)

Create a request recorded.

The caller is responsible for shutting down the server.

Due to channels being bounded, there is a maximum of 100 recorded requests before the server will start blocking requests.

```go

func Test(t *testing.T) {
    assert := assert.New(t)

    server, reqs := helpers.CreateRequestRecorder(t)
    defer server.Close()

    // Make a request against the server.
    rsp, err := http.Get(server.URL + "/test-url")
    assert.Nil(t, err)

    Retrieve the recorded request.
    recorded := <- reqs
    assert.Equal([]byte("Hello, world!"), recorded.Body)
}

```

func CreateTestConfig

func CreateTestConfig(t *testing.T, repos ...repositories.Repository) config.Config

func CreateTestHtpasswd

func CreateTestHtpasswd(t *testing.T, username, password string, cfg *config.Config)

Create an htpasswd file and store its path in the given Config instance.

func CreateTestWebhookStore

func CreateTestWebhookStore(baseUrl string) hooks.WebhookStore

Create a hooks.WebhookStore for testing.

The target URLs will all be based off the given `baseUrl`.

func GetHgHead

func GetHgHead(t *testing.T, client *hg.HgClient) string

func GetRepoFiles

func GetRepoFiles() (files map[string][]byte)

Get the files contained in the repository.

This returns a copy of the original data structure, so it may be mutated by callers.

func GetRepoHead

func GetRepoHead(t *testing.T, rawRepo *git.Repository) plumbing.Hash

Get the object ID of the repository head.

func GetRepositoryFileId

func GetRepositoryFileId(t *testing.T, rawRepo *git.Repository, path string) plumbing.Hash

Return the object ID of the given file.

func SeedGitRepo

func SeedGitRepo(t *testing.T, repo *repositories.GitRepository, rawRepo *git.Repository) plumbing.Hash

Add files to a repository and commit them, returning the commit ID.

Callers can compare committed file contents with the result of `helpers.GetRepoFiles`.

func SeedHgBookmark

func SeedHgBookmark(t *testing.T, repo *repositories.HgRepository, client *hg.HgClient) string

Create a new bookmark with some test files, returning the commit ID.

Callers can compare committed file contents with the result of `helpers.GetRepoFiles`.

func SeedHgRepo

func SeedHgRepo(t *testing.T, repo *repositories.HgRepository, client *hg.HgClient) string

Create a new commit with some files, returning the commit ID.

Callers can compare committed file contents with the result of `helpers.GetRepoFiles`.

func WithEnv

func WithEnv(t *testing.T, vars map[string]string, f func())

Execute the funtion `f` with the given environment variables set.

This helper method temporarily merges the variables in `vars` into the current environment, executes `f`, and restores the original state of the environment.

func WriteConfig

func WriteConfig(t *testing.T, path string, cfg *config.Config)

func WriteTestWebhookStore

func WriteTestWebhookStore(t *testing.T, store hooks.WebhookStore, cfg *config.Config)

Write the given webhook store and save the path in the given config.

Types

type RecordedRequest

type RecordedRequest struct {
	// The recorded request.
	Request *http.Request

	// The recorded request body.
	//
	// The server will call `Close()` on the body when it has finished
	// processing the request, so it will no longer be readable on the request
	// itself.
	Body []byte
}

A request recorded from `CreateRequestRecorder`.

func AssertNumRequests

func AssertNumRequests(t *testing.T, num int, recv <-chan RecordedRequest) []RecordedRequest

Require that the channel has at least `num` requests recorded.

There is a 5 second timeout before the function will fail.

Jump to

Keyboard shortcuts

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