This page covers the project’s testing approach, how to run tests locally, and how to add new test cases.Documentation Index
Fetch the complete documentation index at: https://mintlify.com/ragnarok22/telegram-bot-api-docker/llms.txt
Use this file to discover all available pages before exploring further.
Test Suite Overview
The project uses shell-based tests to validate the entrypoint script behavior. Tests use a mock binary approach to avoid requiring Docker or actual Telegram credentials. Test location:tests/run.sh
What tests validate:
- Required environment variable validation
- Default argument construction
- Custom configuration handling
--localflag behavior- Extra arguments passthrough
- Command execution passthrough
Running Tests Locally
Tests run entirely in userspace without Docker. They use a mock
telegram-bot-api binary that echoes arguments instead of starting the actual server.Test Coverage
The test suite validates these scenarios:1. Missing API ID
Test:test_missing_api_id
Validates: Script exits with error when TELEGRAM_API_ID is not set.
2. Missing API Hash
Test:test_missing_api_hash
Validates: Script exits with error when TELEGRAM_API_HASH is not set.
3. Default Arguments
Test:test_builds_expected_args_defaults
Validates: Entrypoint constructs correct default arguments:
--http-port 8081--http-stat-port 8082--dir /data--temp-dir /tmp--log /data/logs/telegram-bot-api.log
4. Custom Configuration
Test:test_custom_args_and_local
Validates: Custom environment variables override defaults:
5. Local Mode Flag
Test:test_local_with_numeric_flag
Validates: Both TELEGRAM_LOCAL=true and TELEGRAM_LOCAL=1 enable the --local flag.
6. Extra Arguments
Test:test_extra_args_passthrough
Validates: TELEGRAM_EXTRA_ARGS are passed verbatim to the binary:
7. Command Passthrough
Test:test_exec_passthrough_when_args_present
Validates: Entrypoint executes alternative commands when positional arguments are provided:
Test Structure
The test framework (tests/run.sh) provides these helper functions:
run_test(name, function)
Executes a test function and tracks pass/fail status:
setup_sandbox()
Creates an isolated temporary directory with:
- A copy of
entrypoint.sh - A mock
telegram-bot-apibinary
Automatic Cleanup
The test script uses a trap to remove temporary directories:Adding New Tests
To add a new test case:Example: Testing a New Environment Variable
Suppose you add support forTELEGRAM_VERBOSITY:
Mock Binary Approach
The test suite uses a mock binary instead of the realtelegram-bot-api executable:
Advantages:
- No Docker build required
- Fast execution (< 1 second)
- No network or Telegram credentials needed
- Easy to validate exact arguments passed
tests/run.sh:34-42):
- Handles
--versionflag for version checks - Echoes all arguments for validation
- Always exits successfully
CI Test Execution
GitHub Actions runs the test suite automatically on:- Every push to
main - Every pull request targeting
main
.github/workflows/test.yml
bash tests/run.sh command you use locally, ensuring consistent behavior.
Debugging Test Failures
If a test fails:Best Practices
Keep tests isolated
Each test should use its own sandbox and not depend on other tests.
Test one thing
Each test function should validate a single behavior or scenario.
Use descriptive names
Test names should clearly describe what’s being validated.
Clean up resources
Always use the sandbox pattern to ensure proper cleanup.