To run tests for the Thanos project, follow the detailed step-by-step guide below, ensuring you have the required dependencies and understand the various testing structures available within the project.
Prerequisites
Ensure you have the following installed on your system:
- Go (version matching the project requirements)
- npm (for React tests)
- Docker (if you plan to run Docker-related tests)
Step 1: Clone the Repository
Start by cloning the Thanos repository:
git clone https://github.com/thanos-io/thanos.git
cd thanos
Step 2: Install Dependencies
To install necessary tool dependencies, run the following command:
make install-tool-deps
Step 3: Build the Thanos Image (optional for Docker tests)
If you are planning to run tests that involve Docker, you need to build the Thanos image first:
make docker
Step 4: Running Unit Tests
Go Tests
The majority of the core functionalities are tested using Go. You can run the tests using:
go test ./... -test.timeout=9999m
Important Note: The project has specific build constraints when testing certain files. Make sure to account for these constraints by avoiding files defined with the tags !linux
and !stringlabels
.
For example, running the following command allows you to exclude tests with those constraints:
go test -tags '!linux,!stringlabels' ./...
Additionally, you can run specific tests contained within a package:
go test -run TestFunctionName ./pkg/query
Example:
To test a specific function testStartTime
defined in pkg/query/test_test.go
:
go test -run testStartTime ./pkg/query
Interactive Tests
The project provides interactive testing capabilities. To run these tests locally:
Navigate to the
examples/interactive
directory:cd examples/interactive
Comment out a specified line in the
interactive_test.go
file, as instructed in the README, and execute:go test interactive_test.go -test.timeout=9999m
The above commands will generate example data stored in the data
directory for subsequent reference.
Step 5: Running React Tests
The React components within the project are tested using Jest. To run these tests, perform the following:
npm test
To generate a comprehensive HTML-based test coverage report:
CI=true npm test --coverage
After executing the above command, an HTML report will be created in coverage/lcov-report/index.html
, which can be viewed in your web browser.
Step 6: Running End-to-End Tests
Thanos may also include end-to-end tests that are executed in a Docker environment:
make test-e2e
You can also run them locally with:
make test-e2e-local
Step 7: Linting and Formatting
Before running tests, it is a good practice to ensure that your code adheres to the defined style guidelines. Utilize the following commands to lint and format your code:
make lint
make go-format
make jsonnet-lint
make shell-lint
Step 8: Cleaning Up
To clean up any generated artifacts or ensure you have a fresh state, you can execute:
make clean
Conclusion
Following the steps outlined above will help you effectively run tests in the Thanos project. Always refer to other development-related commands in the Makefile
for additional functionality and testing requirements that may arise.
Source: Makefile and related repository documentation.