Mercurial > libervia-backend
annotate tests/e2e/run_e2e.py @ 4316:1795bfcc38e7
cli (message/send): add arguments to send keywords and headers:
rel 451
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 28 Sep 2024 15:57:31 +0200 |
parents | 4cd4922de876 |
children |
rev | line source |
---|---|
3415 | 1 #!/usr/bin/env python3 |
2 | |
3480
7550ae9cfbac
Renamed the project from "Salut à Toi" to "Libervia":
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
3 # Libervia: an XMPP client |
3479 | 4 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
3415 | 5 |
6 # This program is free software: you can redistribute it and/or modify | |
7 # it under the terms of the GNU Affero General Public License as published by | |
8 # the Free Software Foundation, either version 3 of the License, or | |
9 # (at your option) any later version. | |
10 | |
11 # This program is distributed in the hope that it will be useful, | |
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
14 # GNU Affero General Public License for more details. | |
15 | |
16 # You should have received a copy of the GNU Affero General Public License | |
17 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
18 | |
19 """Run end-to-end tests in appropriate Docker environment""" | |
20 | |
3662
0661b2aac167
tests (e2e): print revision used in `run_e2e`
Goffi <goffi@goffi.org>
parents:
3656
diff
changeset
|
21 import sys, os |
3415 | 22 from pathlib import Path |
23 import tempfile | |
24 from textwrap import dedent | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
25 from datetime import datetime |
3415 | 26 import sh |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
27 import io |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
28 import sat_templates |
4227 | 29 from libervia import web |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3702
diff
changeset
|
30 from libervia.backend.core import exceptions |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
3702
diff
changeset
|
31 from libervia.backend.tools.common import regex |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
32 import yaml |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
33 |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
34 try: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
35 from yaml import CLoader as Loader, CDumper as Dumper |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
36 except ImportError: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
37 from yaml import Loader, Dumper |
3415 | 38 |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
39 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
40 OPT_KEEP_CONTAINERS = "--keep-containers" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
41 OPT_KEEP_PROFILES = "--keep-profiles" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
42 OPT_KEEP_VNC = "--keep-vnc" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
43 OPT_KEEP_BROWSER = "--keep-browser" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
44 OPT_VISUAL = "--visual" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
45 OPT_DEV_MODE = "--dev-mode" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
46 |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
47 dev_mode_inst = dedent( |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
48 """\ |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
49 Here is a short script to start working with a logged account: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
50 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
51 from helium import * |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
52 start_firefox() |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
53 go_to("https://libervia-web.test:8443/login") |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
54 write("account1", "login") |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
55 write("test", "password") |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
56 click("log in") |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
57 """ |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
58 ) |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
59 report_buffer = io.StringIO() |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
60 live_out_buf = [] |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
61 live_err_buf = [] |
3415 | 62 |
63 | |
64 def live_out(data): | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
65 if live_out_buf: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
66 # we may get bytes when buffer is reached and we are in the middle of an unicode |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
67 # sequence. In this case we buffer it, and print it when it's complete |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
68 if isinstance(data, str): |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
69 data = b"".join(live_out_buf).decode() + data |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
70 live_out_buf.clear() |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
71 else: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
72 live_out_buf.append(data) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
73 return |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
74 try: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
75 sys.stdout.write(data) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
76 except TypeError: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
77 live_out_buf.append(data) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
78 return |
3415 | 79 sys.stdout.flush() |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
80 report_buffer.write(data) |
3415 | 81 |
82 | |
83 def live_err(data): | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
84 if live_err_buf: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
85 if isinstance(data, str): |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
86 data = b"".join(live_err_buf).decode() + data |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
87 live_err_buf.clear() |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
88 else: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
89 live_err_buf.append(data) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
90 return |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
91 try: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
92 sys.stderr.write(data) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
93 except TypeError: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
94 live_err_buf.append(data) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
95 return |
3415 | 96 sys.stderr.flush() |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
97 report_buffer.write(data) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
98 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
99 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
100 def get_opt(opt_name): |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
101 """Check is an option flag is set, and remove it for sys.argv |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
102 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
103 This allow to have simple flags without interfering with pytest options |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
104 """ |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
105 if opt_name in sys.argv: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
106 sys.argv.remove(opt_name) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
107 return True |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
108 else: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
109 return False |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
110 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
111 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
112 def set_env(override, name, value="1"): |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
113 """Set environement variable""" |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
114 environment = override["services"]["backend"].setdefault("environment", {}) |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
115 environment[name] = value |
3415 | 116 |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
117 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
118 def write_report_log(path, log_raw, with_ansi=False): |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
119 log_raw = str(log_raw) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
120 if with_ansi: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
121 # we save 2 versions: one with ANSI escape codes |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
122 report_ansi = path.with_suffix(".ansi") |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
123 with report_ansi.open("w") as f: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
124 f.write(log_raw) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
125 # and one cleaner, without them |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
126 report_log = path.with_suffix(".log") |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
127 with report_log.open("w") as f: |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
128 f.write(regex.RE_ANSI_REMOVE.sub("", log_raw)) |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
129 else: |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
130 report_log = path.with_suffix(".log") |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
131 with report_log.open("w") as f: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
132 f.write(log_raw) |
3415 | 133 |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
134 |
3415 | 135 def use_e2e_env(): |
3662
0661b2aac167
tests (e2e): print revision used in `run_e2e`
Goffi <goffi@goffi.org>
parents:
3656
diff
changeset
|
136 rev = os.getenv("DOCKER_LIBERVIA_REV", "dev") |
0661b2aac167
tests (e2e): print revision used in `run_e2e`
Goffi <goffi@goffi.org>
parents:
3656
diff
changeset
|
137 print(f"Running tests for Libervia {rev}") |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
138 visual = get_opt(OPT_VISUAL) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
139 keep_containers = get_opt(OPT_KEEP_CONTAINERS) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
140 keep_profiles = get_opt(OPT_KEEP_PROFILES) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
141 keep_vnc = get_opt(OPT_KEEP_VNC) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
142 keep_browser = get_opt(OPT_KEEP_BROWSER) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
143 if keep_browser: |
3415 | 144 keep_containers = True |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
145 keep_vnc = True |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
146 if keep_vnc: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
147 visual = True |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
148 dev_mode = get_opt(OPT_DEV_MODE) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
149 if dev_mode: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
150 keep_containers = keep_profiles = keep_vnc = visual = True |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
151 |
3415 | 152 for p in Path.cwd().parents: |
4227 | 153 package_path = p / "libervia" |
3415 | 154 docker_path = p / "docker" |
155 if package_path.is_dir() and docker_path.is_dir(): | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
156 backend_root_path = p |
3415 | 157 break |
158 else: | |
159 raise exceptions.NotFound( | |
4227 | 160 "Can't find root of Libervia code, are you sure that you are running the " |
161 "test from the backend repository?" | |
3415 | 162 ) |
163 | |
4227 | 164 libervia_web_path = Path(web.__file__).parent.resolve() |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
165 libervia_web_root_path = libervia_web_path.parent |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
166 if (libervia_web_root_path / ".hg").is_dir(): |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
167 libervia_web_source = libervia_web_root_path |
3656
015e13f88960
tests (e2e): fix names in `run_e2e` script, following global name change.
Goffi <goffi@goffi.org>
parents:
3630
diff
changeset
|
168 libervia_web_target = "/src/libervia-web" |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
169 else: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
170 libervia_web_source = libervia_web_path |
4227 | 171 libervia_web_target = "/src/libervia-web/libervia/web" |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
172 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
173 sat_templates_path = Path(sat_templates.__file__).parent.resolve() |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
174 sat_templates_root_path = sat_templates_path.parent |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
175 if (sat_templates_root_path / ".hg").is_dir(): |
4227 | 176 libervia_templates_source = sat_templates_root_path |
177 libervia_templates_target = "/src/libervia-templates" | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
178 else: |
4227 | 179 libervia_templates_source = sat_templates_path |
180 libervia_templates_target = "/src/libervia-templates/sat_templates" | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
181 |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
182 compose_e2e_path = docker_path / "docker-compose-e2e.yml" |
3415 | 183 if not compose_e2e_path.is_file(): |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
184 raise exceptions.NotFound('"docker-compose-e2e.yml" file can\'t be found') |
3415 | 185 |
3630
8ee0140cc8b6
tests (run_e2e): update tmp dir prefix following name change
Goffi <goffi@goffi.org>
parents:
3498
diff
changeset
|
186 with tempfile.TemporaryDirectory(prefix="libervia_test_e2e_") as temp_dir: |
3415 | 187 override_path = Path(temp_dir) / "test_override.yml" |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
188 override = yaml.load( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
189 dedent( |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
190 f"""\ |
3415 | 191 version: "3.6" |
192 services: | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
193 backend: |
3415 | 194 volumes: |
195 - type: bind | |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
196 source: {backend_root_path} |
3656
015e13f88960
tests (e2e): fix names in `run_e2e` script, following global name change.
Goffi <goffi@goffi.org>
parents:
3630
diff
changeset
|
197 target: /src/libervia-backend |
3415 | 198 read_only: true |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
199 web: |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
200 volumes: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
201 - type: bind |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
202 source: {backend_root_path} |
3656
015e13f88960
tests (e2e): fix names in `run_e2e` script, following global name change.
Goffi <goffi@goffi.org>
parents:
3630
diff
changeset
|
203 target: /src/libervia-backend |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
204 read_only: true |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
205 - type: bind |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
206 source: {libervia_web_source} |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
207 target: {libervia_web_target} |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
208 read_only: true |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
209 - type: bind |
4227 | 210 source: {libervia_templates_source} |
211 target: {libervia_templates_target} | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
212 read_only: true |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
213 """ |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
214 ), |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
215 Loader=Loader, |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
216 ) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
217 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
218 if keep_profiles: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
219 set_env(override, "LIBERVIA_TEST_E2E_KEEP_PROFILES") |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
220 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
221 if visual: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
222 set_env(override, "LIBERVIA_TEST_E2E_WEB_NO_HEADLESS") |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
223 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
224 if keep_browser: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
225 set_env(override, "LIBERVIA_TEST_E2E_WEB_KEEP_BROWSER") |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
226 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
227 with override_path.open("w") as f: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
228 yaml.dump(override, f, Dumper=Dumper) |
3415 | 229 |
230 docker_compose = sh.docker_compose.bake( | |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
231 "-f", compose_e2e_path, "-f", override_path |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
232 ) |
3415 | 233 docker_compose.up("-d") |
234 | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
235 p = docker_compose.exec( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
236 "--workdir", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
237 "/src/libervia-backend/tests", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
238 "backend", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
239 "pytest", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
240 "-o", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
241 "cache_dir=/tmp", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
242 *sys.argv[1:], |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
243 color="yes", |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
244 _in=sys.stdin, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
245 _out=live_out, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
246 _out_bufsize=0, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
247 _err=live_err, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
248 _err_bufsize=0, |
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
249 _bg=True, |
3415 | 250 ) |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
251 if visual: |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
252 vnc_port = docker_compose.port("backend", "5900").split(":", 1)[1].strip() |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
253 p_vnc = sh.vncviewer( |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
254 f"localhost:{vnc_port}", |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
255 _bg=True, |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
256 # vncviewer exits with 1 when we send an SIGTERM to it, and it's printed |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
257 # before we can catch it (it's happening in a thread). Thus we set exit |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
258 # code 1 as OK to avoid the backtrace. |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
259 _ok_code=[0, 1], |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
260 ) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
261 else: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
262 p_vnc = None |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
263 |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
264 try: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
265 p.wait() |
3415 | 266 except sh.ErrorReturnCode as e: |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
267 libervia_cont_id = docker_compose.ps("-q", "backend").strip() |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
268 report_dest = Path(f"report_{datetime.now().isoformat()}/") |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
269 # we need to make `report_dest` explicitely local with "./", otherwise |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
270 # docker parse takes it as a container path due to the presence of ":" |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
271 # with `isoformat()`. |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
272 sh.docker.cp(f"{libervia_cont_id}:/reports", f"./{report_dest}") |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
273 write_report_log( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
274 report_dest / "report", report_buffer.getvalue(), with_ansi=True |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
275 ) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
276 write_report_log( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
277 report_dest / "backend", docker_compose.logs("--no-log-prefix", "backend") |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
278 ) |
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
279 write_report_log( |
4305
4cd4922de876
tests: reformat tests using black.
Goffi <goffi@goffi.org>
parents:
4227
diff
changeset
|
280 report_dest / "web", docker_compose.logs("--no-log-prefix", "web") |
3498
d78b5eae912a
tests: update following names change
Goffi <goffi@goffi.org>
parents:
3480
diff
changeset
|
281 ) |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
282 print(f"report saved to {report_dest}") |
3415 | 283 sys.exit(e.exit_code) |
284 finally: | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
285 if p_vnc is not None and p_vnc.is_alive() and not keep_vnc: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
286 p_vnc.terminate() |
3415 | 287 if not keep_containers: |
288 docker_compose.down(volumes=True) | |
3429
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
289 if dev_mode: |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
290 print(dev_mode_inst) |
d4558f3cbf13
tests, docker(e2e): added e2e tests for Libervia:
Goffi <goffi@goffi.org>
parents:
3415
diff
changeset
|
291 |
3415 | 292 |
293 if __name__ == "__main__": | |
294 use_e2e_env() |