Skip to content

Commit e6f53b6

Browse files
committed
Add tests for #384 to the CI
1 parent 71d54ac commit e6f53b6

File tree

4 files changed

+123
-13
lines changed

4 files changed

+123
-13
lines changed

.github/workflows/run-tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ jobs:
1515
fail-fast: false
1616
matrix:
1717
database-image: ["mariadb:10.4", "mysql:5.7", "mariadb:latest", "mysql:latest"]
18-
configuration: ["default", "one-host", "different-apache-port"]
18+
configuration: ["default", "one-host", "fs-import-export", "different-apache-port"]
1919

2020
steps:
2121
- uses: actions/checkout@v3

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ testing-%:
2222
docker-compose -p "phpmyadmin_$@" -f ./testing/docker-compose/docker-compose.$@.yml up --build --abort-on-container-exit --exit-code-from=sut
2323
docker-compose -p "phpmyadmin_$@" -f ./testing/docker-compose/docker-compose.$@.yml down
2424

25-
run-tests: testing-default testing-one-host testing-different-apache-port
25+
run-tests: testing-default testing-one-host testing-fs-import-export testing-different-apache-port
2626

2727
logs:
2828
docker-compose -f ./testing/docker-compose/docker-compose.testing-default.yml logs
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
version: "3.1"
2+
3+
services:
4+
db_server:
5+
image: ${DB:-mariadb:10.3}
6+
environment:
7+
MYSQL_ROOT_PASSWORD: "${TESTSUITE_PASSWORD:-my-secret-pw}"
8+
healthcheck:
9+
test: ["CMD", "mysqladmin", "ping", "-uroot", "-p${TESTSUITE_PASSWORD:-my-secret-pw}"]
10+
start_period: 10s
11+
interval: 5s
12+
timeout: 60s
13+
retries: 10
14+
networks:
15+
testing:
16+
aliases:
17+
- phpmyadmin_testing_db
18+
tmpfs:
19+
- /var/lib/mysql:rw,noexec,nosuid,size=300m
20+
21+
phpmyadmin:
22+
build:
23+
context: ../../apache
24+
environment:
25+
PMA_HOST: db_server
26+
UPLOAD_LIMIT: 123M
27+
MAX_EXECUTION_TIME: 125
28+
HIDE_PHP_VERSION: 1
29+
PMA_UPLOADDIR: /etc/phpmyadmin/imports
30+
PMA_SAVEDIR: /etc/phpmyadmin/exports
31+
volumes:
32+
- ../config.user.inc.php:/etc/phpmyadmin/config.user.inc.php:ro
33+
- phpmyadmin-data:/etc/phpmyadmin/imports:ro
34+
- phpmyadmin-data:/etc/phpmyadmin/exports
35+
healthcheck:
36+
test: ["CMD", "curl", "-Ss", "http://localhost/robots.txt"]
37+
start_period: 5s
38+
interval: 3s
39+
timeout: 60s
40+
retries: 10
41+
networks:
42+
testing:
43+
aliases:
44+
- phpmyadmin_testing_apache
45+
depends_on:
46+
db_server:
47+
condition: service_healthy
48+
49+
sut:
50+
depends_on:
51+
phpmyadmin:
52+
condition: service_healthy
53+
db_server:
54+
condition: service_healthy
55+
build:
56+
context: ../
57+
command: "/tests/testing/test-docker.sh"
58+
networks:
59+
testing:
60+
environment:
61+
TESTSUITE_HOSTNAME: phpmyadmin_testing_apache
62+
TESTSUITE_PORT: 80
63+
TESTSUITE_PASSWORD: "${TESTSUITE_PASSWORD:-my-secret-pw}"
64+
PMA_HOST: phpmyadmin_testing_db
65+
PMA_PORT: 3306
66+
PMA_UPLOADDIR: /etc/phpmyadmin/imports
67+
PMA_SAVEDIR: /etc/phpmyadmin/exports
68+
volumes:
69+
- ../../:/tests:ro
70+
- /var/run/docker.sock:/var/run/docker.sock
71+
- phpmyadmin-data:/etc/phpmyadmin/imports
72+
- phpmyadmin-data:/etc/phpmyadmin/exports
73+
working_dir: /tests
74+
75+
networks:
76+
testing:
77+
driver: bridge
78+
79+
volumes:
80+
phpmyadmin-data:

testing/phpmyadmin_test.py

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,18 @@ def do_login(br, url, username, password, server):
3131
response = br.submit()
3232
return response
3333

34+
def get_world_sql_path():
35+
if os.path.exists('/world.sql'):
36+
return '/world.sql'
37+
elif os.path.exists('./world.sql'):
38+
return './world.sql'
39+
else:
40+
path = os.path.dirname(os.path.realpath(__file__))
41+
return path + '/world.sql'
42+
3443
def test_import(url, username, password, server, sqlfile):
3544
if sqlfile is None:
36-
if os.path.exists('/world.sql'):
37-
sqlfile = '/world.sql'
38-
elif os.path.exists('./world.sql'):
39-
sqlfile = './world.sql'
40-
else:
41-
path = os.path.dirname(os.path.realpath(__file__))
42-
sqlfile = path + '/world.sql'
45+
sqlfile = get_world_sql_path()
4346

4447
br = create_browser()
4548

@@ -115,6 +118,10 @@ def test_import_from_folder(url, username, password, server, sqlfile):
115118
if not upload_dir:
116119
pytest.skip("Missing PMA_UPLOADDIR ENV", allow_module_level=True)
117120

121+
# Copy file into the volume
122+
with open(get_world_sql_path(), 'rb') as src, open(upload_dir + '/world-data.sql', 'wb') as dst:
123+
dst.write(src.read())
124+
118125
br = create_browser()
119126

120127
response = do_login(br, url, username, password, server)
@@ -123,14 +130,26 @@ def test_import_from_folder(url, username, password, server, sqlfile):
123130

124131
# Open server import
125132
response = br.follow_link(text_regex=re.compile('Import'))
126-
assert(b'Browse your computer:' in response.read())
127-
assert(upload_dir in response.read())
133+
response = response.read()
134+
135+
assert(b'Browse your computer:' in response)
136+
assert(upload_dir.encode() in response)
137+
assert(b'world-data.sql' in response)
128138

129139
def test_export_to_folder(url, username, password, server, sqlfile):
130140
save_dir = os.environ.get('PMA_SAVEDIR');
131141
if not save_dir:
132142
pytest.skip("Missing PMA_SAVEDIR ENV", allow_module_level=True)
133143

144+
# Delete file from previous runs
145+
if os.path.exists(save_dir + "/db_server.sql"):
146+
os.remove(save_dir + "/db_server.sql")
147+
148+
assert os.path.exists(save_dir + "/db_server.sql") == False
149+
150+
# Avoid: "The web server does not have permission to save the file"
151+
os.chmod(save_dir , 0o777)
152+
134153
br = create_browser()
135154

136155
response = do_login(br, url, username, password, server)
@@ -139,5 +158,16 @@ def test_export_to_folder(url, username, password, server, sqlfile):
139158

140159
# Open server export
141160
response = br.follow_link(text_regex=re.compile('Export'))
142-
assert(b'Save on server in the directory' in response.read())
143-
assert(save_dir in response.read())
161+
response = response.read()
162+
assert(b'Save on server in the directory' in response)
163+
assert(save_dir.encode() in response)
164+
165+
br.select_form('dump')
166+
br.find_control("quick_export_onserver").items[0].selected=True
167+
168+
response = br.submit()
169+
response = response.read()
170+
171+
assert(b'Dump has been saved to file' in response)
172+
assert(b'Dump has been saved to file /etc/phpmyadmin/exports/db_server.sql' in response)
173+
assert os.path.exists(save_dir + "/db_server.sql") == True

0 commit comments

Comments
 (0)