Documentation ¶
Index ¶
- Variables
- func CopyDir(dst string, src string, dirRenamer Renamer, templatedata TemplateData) error
- func DotRenamer(name string) string
- func FromJSON(t *testing.T, data []byte, thing any)
- func HttpRemote(hostname, owner, repo string) string
- func HttpsRemote(hostname, owner, repo string) string
- func IdentityRenamer(name string) string
- func MakeGitRepoFromTestdata(t *testing.T, testdataDir string, repoURL string, commitSHA string, ...) string
- func MakeTestLog() *slog.Logger
- func MergeStructs[T any](a, b T) T
- func RemoveTime(groups []string, a slog.Attr) slog.Attr
- func SpyHttpServer(request any, reply any, theUrl **url.URL, successCode int) *httptest.Server
- func SshRemote(hostname, owner, repo string) string
- func ToJSON(t *testing.T, thing any) []byte
- type FailingWriter
- type GChatTestCfg
- type GhTestCfg
- type Renamer
- type TemplateData
Constants ¶
This section is empty.
Variables ¶
var FakeTestCfg = GhTestCfg{
Token: "fakeToken",
Owner: "fakeOwner",
Repo: "fakeRepo",
SHA: "0123456789012345678901234567890123456789",
}
FakeTestCfg is a fake test configuration that can be used in some tests that need configuration but don't really use any external service.
Functions ¶
func CopyDir ¶
func CopyDir(dst string, src string, dirRenamer Renamer, templatedata TemplateData) error
CopyDir recursively copies src directory below dst directory, with optional transformations. It performs the following transformations:
- Renames any directory with renamer.
- If templatedata is not empty, will consider each file ending with ".template" as a Go template.
- If a file name contains basic Go template formatting (eg: `foo-{{.bar}}.template`), the file will be renamed accordingly.
It will fail if the dst directory doesn't exist.
For example, if src directory is `foo`:
foo └── dot.git └── config
and dst directory is `bar`, src will be copied as:
bar └── foo └── .git <= dot renamed └── config
func DotRenamer ¶
If name begins with "dot.", replace with ".". Otherwise leave it alone.
func HttpRemote ¶
HttpRemote returns a GitHub HTTP URL
func HttpsRemote ¶
HttpsRemote returns a GitHub HTTPS URL
func IdentityRenamer ¶
func MakeGitRepoFromTestdata ¶
func MakeGitRepoFromTestdata( t *testing.T, testdataDir string, repoURL string, commitSHA string, head string, ) string
MakeGitRepoFromTestdata creates a temporary directory by rendering the templated contents of testdataDir with values from (repoURL, commitSHA, head) and returns the path to the directory.
MakeGitRepoFromTestdata also renames directories of the form 'dot.git' to '.git', thus making said directory a git repository. This allows to supply the 'dot.git' directory as test input, avoiding the problem of having this testdata .git directory a nested repository in the project repository.
The temporary directory is registered for removal via t.Cleanup. If any operation fails, makeGitRepoFromTestdata terminates the test by calling t.Fatal.
func MakeTestLog ¶ added in v0.12.1
MakeTestLog returns a *slog.Logger adapted for tests: it never reports the timestamp and by default it discards all the output. If on the other hand the tests are invoked in verbose mode (go test -v), then the logger will log normally.
func MergeStructs ¶
func MergeStructs[T any](a, b T) T
MergeStructs merges b into a and returns the merged copy. Said in another way, a is the default and b is the override. Used to express succinctly the delta in the test cases. Since it is a test helper, it will panic in case of error.
func RemoveTime ¶ added in v0.12.1
RemoveTime removes the "time" attribute from the output of a slog.Logger.
func SpyHttpServer ¶
SpyHttpServer returns a very basic HTTP test server (spy). The handler will JSON decode the request body into `request` and will set `theUrl` to the request URL. On JSON decode success, the handler will return to the client the HTTP status code `successCode`. On JSON decode failure, the handler will return 418 I am a teapot. If `reply` is not nil, the handler will send it to the client, JSON encoded. To avoid races, call ts.Close() before reading any parameters.
Example:
var ghReq github.AddRequest var URL *url.URL ts := SpyHttpServer(&ghReq, nil, &URL, http.StatusCreated)
Types ¶
type FailingWriter ¶
type FailingWriter struct{}
FailingWriter is an io.Writer that always returns an error.
type GChatTestCfg ¶
type GChatTestCfg struct {
Hook string
}
GChatTestCfg contains the secrets needed to run integration tests against the Google Chat API.
func GoogleChatSecretsOrFail ¶
func GoogleChatSecretsOrFail(t *testing.T) GChatTestCfg
GoogleChatSecretsOrFail returns the secrets needed to run integration tests against the Google Chat API. If the secrets are missing, GoogleChatSecretsOrFail fails the test.
type GhTestCfg ¶
GhTestCfg contains the secrets needed to run integration tests against the GitHub Commit Status API.
func GitHubSecretsOrFail ¶
GitHubSecretsOrFail returns the secrets needed to run integration tests against the GitHub Commit Status API. If the secrets are missing, GitHubSecretsOrFail fails the test.