Documentation
¶
Overview ¶
Package integrationtest provides shared code for integrationtests. The package should only be imported by _test.go files.
Index ¶
- func AssertLeakDetector(t *testing.T, want int)
- func GetLogger() logging.Logger
- func NewServer(options *proxyssh.Options, configurations ...proxyssh.Configuration) (testServer *ssh.Server, testLogger logging.Logger, cleanup func())
- func RunComposeTest(config string, files map[string]string, testcode ComposeTestCode) error
- type ComposeTestCode
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AssertLeakDetector ¶
AssertLeakDetector creates a new subtest that ensures that the leak detector succeeded with exactly 'want' subprocesses. When the leak detector is not enabled, the subtest is skipped.
This function is untested.
func GetLogger ¶
GetLogger returns a pointer to a logger that is to be shared amongst all test cases.
This function can safely be called from different test cases, and in different goroutines at once. It will always return the same logger.
func NewServer ¶
func NewServer(options *proxyssh.Options, configurations ...proxyssh.Configuration) (testServer *ssh.Server, testLogger logging.Logger, cleanup func())
NewServer creates a new proxyssh.Server for an integration test. Returns the test server and a cleanup function to be defered.
When options is nil, sets up empty options.
When testServer.Handler remains unset, sets it to respond with "success" on stdout and exit immediatly. When testServer.HostSigners remains unset, generates a single reusable test server key.
This function should be used like:
testServer, cleanup := NewServer(testServer) defer cleanup()
This function is untested.
func RunComposeTest ¶
func RunComposeTest(config string, files map[string]string, testcode ComposeTestCode) error
RunComposeTest runs a docker-compose based test. It first starts the docker-compose configuration contained in the string. Thenm it writes out addtional data files in the provided map and waits for it to become available. Finally, it runs the testcode function.
Calling this function is roughly equivalent to the following bash pseudo-code:
mktmp -d echo $config > tmpdir/docker-compose.yml docker-compose pull docker-compose up -d tmpdir/docker-compose.yml // ... call f() ... docker-compose down -v rm -rf tmpdir
For source code compatibility purposes, all occurences of '\t' in the compose file will be replace with four spaces.
This command depends on the 'docker-compose' executable to be available in path.
This function has two kinds of error conditions, those that occur during setting up the project, and those that occur in the testcode. If an error occurs during setup or teardown, panic() is called. If an error occurs during the testcase, and testcase does not call panic(), the error is returned by this function.
This function is itself untested.
Types ¶
type ComposeTestCode ¶
type ComposeTestCode func(cli client.APIClient, findService func(string) types.Container, stopService func(string)) error
ComposeTestCode is a function that runs tests inside a docker-compose file context. It returns an error if the test cases failed, and nil otherwise. See also RunComposeTest.
This function receives three parameters from the testrunner.
cli is a valid Docker Client that can be used for arbitary interactions with docker.
findService is a function that is provided a name of a service, and returns the container within the current docker-compose context.
stopService and is a function that can be used to stop a particular service in the docker-compose service.