cloudflare/cloudflared
Publicmirrored from https://github.com/cloudflare/cloudflaredAvailable
component-tests/README.md
51lines · modeblame
e5d6f969cthuang5 years ago | 1 | # Requirements |
| 2 | 1. Python 3.7 or later with packages in the given `requirements.txt` | |
| 3 | - E.g. with conda: | |
| 4 | - `conda create -n component-tests python=3.7` | |
| 5 | - `conda activate component-tests` | |
| 6 | - `pip3 install -r requirements.txt` | |
| 7 | | |
a7344435cthuang5 years ago | 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" | |
f23e33c0cthuang5 years ago | 14 | ingress: |
| 15 | - hostname: named-tunnel-component-tests.example.com | |
5431e0caJoão Oliveirinha4 years ago | 16 | service: hello_world |
f23e33c0cthuang5 years ago | 17 | - service: http_status:404 |
a7344435cthuang5 years ago | 18 | ``` |
| 19 | | |
f23e33c0cthuang5 years ago | 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 | | |
9df60276cthuang5 years ago | 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 | | |
e5d6f969cthuang5 years ago | 36 | # How to run |
a7344435cthuang5 years ago | 37 | Specify path to config file via env var `COMPONENT_TESTS_CONFIG`. This is required. |
e5d6f969cthuang5 years ago | 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. |