Fix tests ui with linux
This commit is contained in:
parent
601f0fde62
commit
57374ecc2f
|
@ -98,19 +98,18 @@ jobs:
|
|||
sudo chmod 777 /etc/bunkerweb/variables.env /etc/bunkerweb/ui.env
|
||||
- name: Run tests
|
||||
run: |
|
||||
sudo systemctl start bunkerweb-ui
|
||||
cd ./tests/ui
|
||||
MAKEFLAGS="-j $(nproc)" find . -name "requirements.txt" -exec pip install -r {} \;
|
||||
touch test.txt
|
||||
zip test.zip test.txt
|
||||
rm test.txt
|
||||
echo '{ \
|
||||
"id": "discord", \
|
||||
"name": "Discord", \
|
||||
"description": "Send alerts to a Discord channel (using webhooks).", \
|
||||
"version": "0.1", \
|
||||
"stream": "no", \
|
||||
"settings": {} \
|
||||
echo '{
|
||||
"id": "discord",
|
||||
"name": "Discord",
|
||||
"description": "Send alerts to a Discord channel (using webhooks).",
|
||||
"version": "0.1",
|
||||
"stream": "no",
|
||||
"settings": {}
|
||||
}' | tee plugin.json
|
||||
zip discord.zip plugin.json
|
||||
rm plugin.json
|
||||
|
|
|
@ -94,9 +94,17 @@ class Instance:
|
|||
|
||||
def restart(self) -> bool:
|
||||
if self._type == "local":
|
||||
proc = run(
|
||||
["sudo", join(sep, "usr", "sbin", "nginx"), "-s", "stop"],
|
||||
stdin=DEVNULL,
|
||||
stderr=STDOUT,
|
||||
check=False,
|
||||
)
|
||||
if proc.returncode != 0:
|
||||
return False
|
||||
return (
|
||||
run(
|
||||
["sudo", join(sep, "usr", "sbin", "nginx"), "-s", "restart"],
|
||||
["sudo", join(sep, "usr", "sbin", "nginx")],
|
||||
stdin=DEVNULL,
|
||||
stderr=STDOUT,
|
||||
check=False,
|
||||
|
|
Binary file not shown.
|
@ -49,6 +49,7 @@ services:
|
|||
bw-ui:
|
||||
image: bunkerity/bunkerweb-ui:1.5.2
|
||||
pull_policy: never
|
||||
command: python3 -m flask --app main:app run --host=0.0.0.0 --port=7000
|
||||
depends_on:
|
||||
- bw
|
||||
- bw-docker-proxy
|
||||
|
|
Binary file not shown.
227
tests/ui/main.py
227
tests/ui/main.py
|
@ -1,8 +1,10 @@
|
|||
from contextlib import suppress
|
||||
from datetime import datetime, timedelta
|
||||
from os import listdir
|
||||
from functools import partial
|
||||
from os import getenv, listdir
|
||||
from os.path import join
|
||||
from pathlib import Path
|
||||
from subprocess import PIPE, run
|
||||
from time import sleep
|
||||
from traceback import format_exc
|
||||
from typing import List, Union
|
||||
|
@ -43,6 +45,8 @@ while not ready:
|
|||
|
||||
print("UI is ready, starting tests ...", flush=True)
|
||||
|
||||
TEST_TYPE = getenv("TEST_TYPE", "docker")
|
||||
|
||||
firefox_options = Options()
|
||||
if "geckodriver" not in listdir(Path.cwd()):
|
||||
firefox_options.add_argument("--headless")
|
||||
|
@ -161,14 +165,21 @@ def access_page(
|
|||
)
|
||||
|
||||
|
||||
with webdriver.Firefox(
|
||||
service=Service(
|
||||
executable_path="./geckodriver"
|
||||
if "geckodriver" in listdir(Path.cwd())
|
||||
else "/usr/local/bin/geckodriver"
|
||||
),
|
||||
options=firefox_options,
|
||||
) as driver:
|
||||
driver_func = partial(webdriver.Firefox, options=firefox_options)
|
||||
if TEST_TYPE == "dev":
|
||||
driver_func = partial(
|
||||
webdriver.Firefox,
|
||||
service=Service(
|
||||
Service(
|
||||
executable_path="./geckodriver"
|
||||
if "geckodriver" in listdir(Path.cwd())
|
||||
else "/usr/local/bin/geckodriver"
|
||||
)
|
||||
),
|
||||
options=firefox_options,
|
||||
)
|
||||
|
||||
with webdriver.Firefox(options=firefox_options) as driver:
|
||||
try:
|
||||
driver.delete_all_cookies()
|
||||
driver.maximize_window()
|
||||
|
@ -268,8 +279,9 @@ with webdriver.Firefox(
|
|||
|
||||
no_errors = True
|
||||
retries = 0
|
||||
action = "reload" if TEST_TYPE == "docker" else "restart"
|
||||
while no_errors:
|
||||
print("Trying to reload BunkerWeb instance ...", flush=True)
|
||||
print(f"Trying to {action} BunkerWeb instance ...", flush=True)
|
||||
|
||||
try:
|
||||
form = WebDriverWait(driver, 2).until(
|
||||
|
@ -285,17 +297,17 @@ with webdriver.Firefox(
|
|||
access_page(
|
||||
driver,
|
||||
driver_wait,
|
||||
"//form[starts-with(@id, 'form-instance-')]//button[@value='reload']",
|
||||
f"//form[starts-with(@id, 'form-instance-')]//button[@value='{action}']",
|
||||
"instances",
|
||||
False,
|
||||
)
|
||||
|
||||
print(
|
||||
"Instance was reloaded successfully, checking the message ...",
|
||||
f"Instance was {action}ed successfully, checking the message ...",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
assert_alert_message(driver, "has been reloaded")
|
||||
assert_alert_message(driver, f"has been {action}ed")
|
||||
|
||||
no_errors = False
|
||||
except:
|
||||
|
@ -307,6 +319,24 @@ with webdriver.Firefox(
|
|||
"WARNING: message list doesn't contain the expected message or is empty, retrying..."
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
print("Trying global config page ...")
|
||||
|
||||
access_page(
|
||||
|
@ -409,6 +439,24 @@ with webdriver.Firefox(
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
input_worker = safe_get_element(driver, By.ID, "WORKER_RLIMIT_NOFILE")
|
||||
|
||||
if input_worker.get_attribute("value") != "4096":
|
||||
|
@ -563,6 +611,24 @@ with webdriver.Firefox(
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
print(
|
||||
"The page reloaded successfully, checking if the setting has been updated ...",
|
||||
flush=True,
|
||||
|
@ -613,24 +679,25 @@ with webdriver.Firefox(
|
|||
|
||||
assert_button_click(driver, "//button[@data-services-action='new']")
|
||||
|
||||
server_name_input: WebElement = safe_get_element(driver, By.ID, "SERVER_NAME")
|
||||
server_name_input: WebElement = safe_get_element(driver, By.ID, "SERVER_NAME") # type: ignore
|
||||
server_name_input.clear()
|
||||
server_name_input.send_keys("app1.example.com")
|
||||
|
||||
assert_button_click(driver, "//button[@data-tab-handler='reverseproxy']")
|
||||
if TEST_TYPE == "docker":
|
||||
assert_button_click(driver, "//button[@data-tab-handler='reverseproxy']")
|
||||
|
||||
assert_button_click(
|
||||
driver, safe_get_element(driver, By.ID, "USE_REVERSE_PROXY")
|
||||
)
|
||||
assert_button_click(
|
||||
driver, safe_get_element(driver, By.ID, "USE_REVERSE_PROXY")
|
||||
)
|
||||
|
||||
assert_button_click(
|
||||
driver, "//button[@data-services-multiple-add='reverse-proxy']"
|
||||
)
|
||||
assert_button_click(
|
||||
driver, "//button[@data-services-multiple-add='reverse-proxy']"
|
||||
)
|
||||
|
||||
safe_get_element(driver, By.ID, "REVERSE_PROXY_HOST").send_keys(
|
||||
"http://app1:8080"
|
||||
)
|
||||
safe_get_element(driver, By.ID, "REVERSE_PROXY_URL").send_keys("/")
|
||||
safe_get_element(driver, By.ID, "REVERSE_PROXY_HOST").send_keys(
|
||||
"http://app1:8080"
|
||||
)
|
||||
safe_get_element(driver, By.ID, "REVERSE_PROXY_URL").send_keys("/")
|
||||
|
||||
access_page(
|
||||
driver,
|
||||
|
@ -640,6 +707,24 @@ with webdriver.Firefox(
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
try:
|
||||
services = safe_get_element(
|
||||
driver,
|
||||
|
@ -741,6 +826,24 @@ with webdriver.Firefox(
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
assert_alert_message(driver, "has been deleted.")
|
||||
|
||||
print(
|
||||
|
@ -810,6 +913,24 @@ location /hello {
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
assert_alert_message(driver, "was successfully created")
|
||||
|
||||
sleep(30)
|
||||
|
@ -832,7 +953,7 @@ location /hello {
|
|||
exit(1)
|
||||
|
||||
print(
|
||||
"The config has been created and is working, trying to edit it ...",
|
||||
"The config has been created and is working, trying to delete it ...",
|
||||
flush=True,
|
||||
)
|
||||
|
||||
|
@ -857,6 +978,24 @@ location /hello {
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
assert_alert_message(driver, "was successfully deleted")
|
||||
|
||||
print("The config has been deleted, trying plugins page ...", flush=True)
|
||||
|
@ -929,6 +1068,24 @@ location /hello {
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
external_plugins = safe_get_element(
|
||||
driver,
|
||||
By.XPATH,
|
||||
|
@ -955,6 +1112,24 @@ location /hello {
|
|||
False,
|
||||
)
|
||||
|
||||
if TEST_TYPE == "linux":
|
||||
retries = 0
|
||||
while (
|
||||
not b"BunkerWeb is ready"
|
||||
in run(
|
||||
["sudo", "tail", "-n", "1", "/var/log/bunkerweb/error.log"],
|
||||
stdout=PIPE,
|
||||
check=True,
|
||||
).stdout
|
||||
) and retries < 10:
|
||||
retries += 1
|
||||
print("Waiting for BunkerWeb to be ready, retrying in 5s ...")
|
||||
sleep(5)
|
||||
|
||||
if retries >= 10:
|
||||
print("BunkerWeb took too long to be ready, exiting ...", flush=True)
|
||||
exit(1)
|
||||
|
||||
with suppress(TimeoutException):
|
||||
title = WebDriverWait(driver, 2).until(
|
||||
EC.presence_of_element_located(
|
||||
|
|
|
@ -1,9 +0,0 @@
|
|||
{
|
||||
"id": "discord",
|
||||
"order": 999,
|
||||
"name": "Discord",
|
||||
"description": "Send alerts to a Discord channel (using webhooks).",
|
||||
"version": "0.1",
|
||||
"stream": "no",
|
||||
"settings": {}
|
||||
}
|
Binary file not shown.
|
@ -34,6 +34,11 @@ if [ "$integration" = "docker" ] ; then
|
|||
exit 1
|
||||
fi
|
||||
fi
|
||||
else
|
||||
sudo systemctl stop bunkerweb bunkerweb-ui
|
||||
sudo mkdir /var/www/html/app1.example.com
|
||||
sudo touch /var/www/html/app1.example.com/index.html
|
||||
export TEST_TYPE="linux"
|
||||
fi
|
||||
|
||||
i=0
|
||||
|
@ -61,6 +66,7 @@ if [ "$integration" == "docker" ] ; then
|
|||
exit 1
|
||||
fi
|
||||
else
|
||||
sudo systemctl start bunkerweb bunkerweb-ui
|
||||
while [ $i -lt 120 ] ; do
|
||||
check="$(sudo cat /var/log/bunkerweb/error.log | grep "BunkerWeb is ready")"
|
||||
if ! [ -z "$check" ] ; then
|
||||
|
@ -111,4 +117,4 @@ if [ $? -ne 0 ] ; then
|
|||
fi
|
||||
|
||||
# Exit
|
||||
exit 0
|
||||
exit 0
|
||||
|
|
Loading…
Reference in New Issue