Unit tests
If your test does not require a cluster (e.g you adding a new test to the parser), then the process is the same as any normal golang test.
System tests
Note: all paths mentioned below are relative to the root of the Dgraph repo.
Most tests, however, require a cluster. We use docker and docker-compose to create test clusters.
Tests with default options
The file dgraph/docker-compose.yml
is used to start a cluster with default options. If your test doesn’t require any special setup or options, this is the file you’d use. Simply write the test and the test script will spin the default cluster and run your test. It’s important that there’s no docker-compose.yml
file in the folder where the test is located. Otherwise the test script will think this test requires a custom cluster and use that compose file to create the cluster. One example of this type of tests are the tests in the query
directory.
Tests with custom options.
If your test needs a different setup than the default cluster, the process consists of creating a custom docker-compose.yml
file and writing the test. The compose and test files should be in the same directory. The test script will spin out the cluster and then run the tests.
You can use the tool in the compose
directory to generate an initial docker-compose.yml
file. An example of this type of tests are those in the systest
directory.
Running tests
With the test script
The test script takes care of building and installing Dgraph, removing any leftover containers, spinning a new cluster, and then running the tests.
If your test needs the default cluster:
./test.sh ./path/to/your/test/dir
If your test needs a custom cluster
./test.sh -C ./paht/to/your/test/dir
Manual run
Sometimes, you’d want to run a test manually. Note that in this process you are responsible for building and installing Dgraph (i.e running make install
) and dealing with leftover containers.
In one terminal run.
cd path/to/your/compose/file
docker-compose up
If you are using the default cluster, then this path is ./dgraph
.
In another terminal, run your test using go test
go test ./path/to/your/test/dir