cloudflare/cloudflared
Publicmirrored fromhttps://github.com/cloudflare/cloudflaredAvailable
component-tests/README.md
51lines · modecode
| 1 | # Requirements |
| 2 | 1. Python 3.10 or later with packages in the given `requirements.txt` |
| 3 | - E.g. with venv: |
| 4 | - `python3 -m venv ./.venv` |
| 5 | - `source ./.venv/bin/activate` |
| 6 | - `python3 -m pip install -r requirements.txt` |
| 7 | |
| 8 | 2. Create a config yaml file, for example: |
| 9 | ``` |
| 10 | cloudflared_binary: "cloudflared" |
| 11 | tunnel: "3d539f97-cd3a-4d8e-c33b-65e9099c7a8d" |
| 12 | credentials_file: "/Users/tunnel/.cloudflared/3d539f97-cd3a-4d8e-c33b-65e9099c7a8d.json" |
| 13 | origincert: "/Users/tunnel/.cloudflared/cert.pem" |
| 14 | ingress: |
| 15 | - hostname: named-tunnel-component-tests.example.com |
| 16 | service: hello_world |
| 17 | - service: http_status:404 |
| 18 | ``` |
| 19 | |
| 20 | 3. Route hostname to the tunnel. For the example config above, we can do that via |
| 21 | ``` |
| 22 | cloudflared tunnel route dns 3d539f97-cd3a-4d8e-c33b-65e9099c7a8d named-tunnel-component-tests.example.com |
| 23 | ``` |
| 24 | |
| 25 | 4. Turn on linter |
| 26 | If you are using Visual Studio, follow https://code.visualstudio.com/docs/python/linting to turn on linter. |
| 27 | |
| 28 | 5. Turn on formatter |
| 29 | If you are using Visual Studio, follow https://code.visualstudio.com/docs/python/editing#_formatting |
| 30 | to turn on formatter and https://marketplace.visualstudio.com/items?itemName=cbrevik.toggle-format-on-save |
| 31 | to turn on format on save. |
| 32 | |
| 33 | 6. If you have cloudflared running as a service on your machine, you can either stop the service or ignore the service tests |
| 34 | via `--ignore test_service.py` |
| 35 | |
| 36 | # How to run |
| 37 | Specify path to config file via env var `COMPONENT_TESTS_CONFIG`. This is required. |
| 38 | ## All tests |
| 39 | Run `pytest` inside this(component-tests) folder |
| 40 | |
| 41 | ## Specific files |
| 42 | Run `pytest <file 1 name>.py <file 2 name>.py` |
| 43 | |
| 44 | ## Specific tests |
| 45 | Run `pytest file.py -k <test 1 name> -k <test 2 name>` |
| 46 | |
| 47 | ## Live Logging |
| 48 | Running with `-o log_cli=true` outputs logging to CLI as the tests are. By default the log level is WARN. |
| 49 | `--log-cli-level` control logging level. |
| 50 | For example, to log at info level, run `pytest -o log_cli=true --log-cli-level=INFO`. |
| 51 | See https://docs.pytest.org/en/latest/logging.html#live-logs for more documentation on logging. |