-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtest_cli_end_to_end.py
61 lines (46 loc) · 1.74 KB
/
test_cli_end_to_end.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
import logging
import time
import httpx
import pytest
from typer.testing import CliRunner
from ptah.cli import app
from ptah.clients import Shell, get
from ptah.models import OperatingSystem
log = logging.getLogger(__name__)
# https://stackoverflow.com/a/38609243
pytestmark = pytest.mark.e2e
# https://stackoverflow.com/a/71264963
if get(OperatingSystem) != OperatingSystem.LINUX:
pytest.skip(reason="unsupported", allow_module_level=True)
@pytest.mark.parametrize("in_project", ["project-with-fastapi"], indirect=True)
def test_build(in_project):
runner = CliRunner()
result = runner.invoke(app, ["build"])
assert result.exit_code == 0
assert "Building 1 Docker image" in result.stdout
assert "Copying 1 manifest" in result.stdout
@pytest.mark.parametrize("in_project", ["project-with-fastapi"], indirect=True)
@pytest.mark.filterwarnings("ignore::pytest.PytestUnraisableExceptionWarning")
def test_deploy(in_project):
runner = CliRunner()
result = runner.invoke(app, ["deploy"])
assert result.exit_code == 0, result.stdout
@pytest.mark.timeout(20)
def test_deployed_service_is_functional():
# Poor man's external liveness probe.
success = False
while not success:
try:
response = httpx.get("http://localhost:8000/probe")
assert response.is_success
assert "headers" in response.json()
success = True
except Exception as e:
log.warning(e)
time.sleep(1)
@pytest.mark.parametrize("in_project", ["project-with-fastapi"], indirect=True)
def test_nuke(in_project):
runner = CliRunner()
result = runner.invoke(app, ["nuke"])
assert result.exit_code == 0, result.stdout
assert not get(Shell).run(["kind", "get", "clusters"])