- Ensure that Go is installed on your system.
- Docker Compose v2 must also be installed.
It's recommended to launch e2e tests by using make run-e2e-tests
command.
Executing the command will perform the following actions:
- Create configuration files, specifically
./test/.env.test
and./test/.env2.test
. - Build the
pmm-dump
binary. - Launch the e2e tests.
End-to-end tests are executed concurrently. The maximum number of tests that can run simultaneously is determined by the PMM_DUMP_MAX_PARALLEL_TESTS
environment variable. By default, this is set to 4. To modify this value, assign your desired number to this environment variable as shown below:
export PMM_DUMP_MAX_PARALLEL_TESTS="2"
make run-e2e-tests
This example sets the maximum number of concurrent tests to 2. Adjust the value as needed for your testing environment.
- Ensure that Go is installed on your system.
- Docker must also be installed.
- Perform an initial setup by executing the
./test/init-test-configs.sh
script. This script creates configuration files:./test/.env.test
and./test/.env2.test
. - Build a
pmm-dump
binary using themake build
command.
To execute a single e2e test, specify the e2e
build tag to the go test
command as follows:
go test -v -tags e2e -run ^TestExportImport$
To execute multiple e2e tests, use the following command:
go test -v -tags e2e ./...
For troubleshooting, some e2e tests store dump files in the ./test/pmm/tmp
directory. These files can be used to investigate any issues that may arise during testing.
Upon initiation of the end-to-end (e2e) tests, the following sequence of actions will occur:
- Any pre-existing e2e test deployments will be removed
- The testing framework will automatically pull the required Docker images
- The e2e tests will be launched. If they pass, we'll delete the test deployments. But if a test fails, we'll keep those deployments
-
Tag your test file with
//go:build e2e
. This allows users to run basic tests using thego test ./...
command without the need for Docker or additional configuration files. -
Creating a PMM test deployment:
- Create a deployment controller using
deployment.NewController(t *testing.T)
function. - Use the
(*deployment.Controller) NewPMM(name, configFile string) *deployment.PMM
method to create adeployment.PMM
object. Thename
parameter should be the test name. It is necessary for differentiating test deployments from others. ThedotEnvFilename
should be either.env.test
or.env2.test
, as these files are created by the./test/init-test-configs.sh
script. - Deploy the PMM using the
(*deployment.PMM) Deploy(ctx context.Context)
method.
Example:
c := deployment.NewController(t) pmm := c.NewPMM("test-name", ".env.test") pmm.Deploy(ctx)
- Create a deployment controller using
-
Launching the binary:
- Create an
util.Binary
structure. - Use the
(*util.Binary) Run(...string) (string, string, error)
method to launchpmm-dump
.
- Create an
//go:build e2e
package e2e
...
func TestExample(t *testing.T) {
ctx := context.Background()
c := deployment.NewController(t)
pmm := c.NewPMM("test-name", ".env.test")
pmm.Deploy(ctx)
b := new(util.Binary)
testDir := t.TempDir()
args := []string{"-d", filepath.Join(testDir, "dump.tar.gz"), "--pmm-url", pmm.PMMURL(), "--dump-qan", "--click-house-url", pmm.ClickhouseURL()}
pmm.Log("Exporting data to", filepath.Join(testDir, "dump.tar.gz"))
stdout, stderr, err := b.Run(append([]string{"export", "--ignore-load"}, args...)...)
if err != nil {
t.Fatal("failed to export", err, stdout, stderr)
}
}