To run tests for the jaegertracing/jaeger-lib
project, follow these detailed steps utilizing the provided Makefile and Go testing framework.
Prerequisites
Ensure that you have the necessary dependencies installed. You can install them using the following command:
make install-dep
Running Tests
The primary target for testing in the Makefile is set to test-and-lint
, which will run both tests and linter checks by default. To run the tests you simply need to invoke:
make
Alternatively, you can explicitly run the tests without the linter using:
make test
Test Structure
The tests in this project can be found primarily in files ending with _test.go
. For example:
Writing Tests
When creating tests, use the standard Go testing conventions. For example, here is a simple test function you might find in sample/sample_test.go
:
func TestSayHello(t *testing.T) {
SayHello()
}
Running Coverage
To check the test coverage, you can utilize the cover
target defined in the Makefile:
make cover
For producing an HTML report of the coverage results, use:
make cover-html
Running Tests in CI
For continuous integration environments, you can run the tests using the following command, which will encompass both testing and linting:
make test-ci
Additional Testing Targets
Linting: To run lint tests separately, utilize:
make lint
Testing with Coverage: In Case you run tests and want coverage data, use:
make cover
Creating a CI Environment: For setting up a continuous integration environment, run:
make install-ci
Example Output
When running tests, successful assertions will typically not output anything, while failures will provide feedback similar to:
=== RUN TestInitMetricsFailures
--- FAIL: TestInitMetricsFailures (0.00s)
metrics_test.go:10: Field NoMetricTag is missing a tag 'metric'
This output helps pinpoint issues within the tests, allowing for efficient debugging.
Conclusion
By leveraging the provided Makefile targets and adhering to Go’s testing conventions, you can effectively execute tests in the jaegertracing/jaeger-lib
project. For advanced use cases, consider reviewing individual test implementations for specific functionalities, such as the metrics functionality tested in metrics/metrics_test.go
.
For more details, please see the repository’s README.md and Contributing guidelines.