Documentation ¶
Index ¶
- Constants
- func CleanupConfig(t *testing.T, cfg *config.Config)
- func CleanupHgRepo(t *testing.T, client *hg.HgClient)
- func CleanupRepository(t *testing.T, path string)
- func CommitHg(t *testing.T, client *hg.HgClient, message, author string) string
- func CreateAndAddFilesHg(t *testing.T, repoPath string, client *hg.HgClient, files map[string][]byte)
- func CreateGitBranch(t *testing.T, repo *repositories.GitRepository, rawRepo *git.Repository) *plumbing.Reference
- func CreateGitRepo(t *testing.T, name string) (*repositories.GitRepository, *git.Repository)
- func CreateHgBookmark(t *testing.T, client *hg.HgClient, node, bookmark string)
- func CreateHgRepo(t *testing.T, name string) (*repositories.HgRepository, *hg.HgClient)
- func CreateHgTag(t *testing.T, client *hg.HgClient, node, tag, message, author string) string
- func CreateRequestRecorder(t *testing.T) (*httptest.Server, <-chan RecordedRequest)
- func CreateTestConfig(t *testing.T, repos ...repositories.Repository) config.Config
- func CreateTestHtpasswd(t *testing.T, username, password string, cfg *config.Config)
- func CreateTestWebhookStore(baseUrl string) hooks.WebhookStore
- func GetHgHead(t *testing.T, client *hg.HgClient) string
- func GetRepoFiles() (files map[string][]byte)
- func GetRepoHead(t *testing.T, rawRepo *git.Repository) plumbing.Hash
- func GetRepositoryFileId(t *testing.T, rawRepo *git.Repository, path string) plumbing.Hash
- func SeedGitRepo(t *testing.T, repo *repositories.GitRepository, rawRepo *git.Repository) plumbing.Hash
- func SeedHgBookmark(t *testing.T, repo *repositories.HgRepository, client *hg.HgClient) string
- func SeedHgRepo(t *testing.T, repo *repositories.HgRepository, client *hg.HgClient) string
- func WithEnv(t *testing.T, vars map[string]string, f func())
- func WriteConfig(t *testing.T, path string, cfg *config.Config)
- func WriteTestWebhookStore(t *testing.T, store hooks.WebhookStore, cfg *config.Config)
- type RecordedRequest
Constants ¶
const (
DefaultAuthor = "Author <author@example.com>"
)
Variables ¶
This section is empty.
Functions ¶
func CleanupConfig ¶
Cleanup any and all temp files specified in the configuration.
func CleanupHgRepo ¶
Clean up a created Mercurial repository.
func CreateAndAddFilesHg ¶
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 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 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 ¶
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 GetRepoFiles ¶
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 ¶
Get the object ID of the repository head.
func GetRepositoryFileId ¶
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 ¶
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 WriteTestWebhookStore ¶
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.