Skip to content

Commit 8518a5f

Browse files
committed
Add test cases for sql import/export scripts
1 parent 63f32f5 commit 8518a5f

File tree

7 files changed

+143
-0
lines changed

7 files changed

+143
-0
lines changed

.github/workflows/pr-core-tests.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ jobs:
3131
- examples/orchestrator
3232
- examples/plugin-commands
3333
- examples/services
34+
- examples/sql-helpers
3435
- examples/tooling
3536
node-version:
3637
- "18"

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
## Unreleased
22

33
* Updated `sql-export.sh` to use `mariadb-dump` command (if available). [#148](https://github.com/lando/core/pull/148)
4+
* Added `leia` tests for `sql-import.sh` and `sql-export.sh`
45

56
## v3.21.0-beta.18 - [April 29, 2024](https://github.com/lando/core/releases/tag/v3.21.0-beta.18)
67

examples/sql-helpers/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
sqlhelpers
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
name: lando-sqlhelpers
2+
services:
3+
mariadb:
4+
api: 3
5+
type: lando
6+
services:
7+
image: bitnami/mariadb:10.4
8+
command: /opt/bitnami/scripts/mariadb/entrypoint.sh /opt/bitnami/scripts/mariadb/run.sh
9+
environment:
10+
ALLOW_EMPTY_PASSWORD: yes
11+
MARIADB_DATABASE: lando_test
12+
MYSQL_DATABASE: lando_test
13+
MARIADB_USER: test
14+
MARIADB_PASSWORD: test
15+
16+
mysql57:
17+
api: 3
18+
type: lando
19+
services:
20+
image: bitnami/mysql:5.7
21+
command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh
22+
environment:
23+
ALLOW_EMPTY_PASSWORD: yes
24+
MYSQL_AUTHENTICATION_PLUGIN: mysql_native_password
25+
MYSQL_DATABASE: lando_test
26+
MYSQL_PASSWORD: test
27+
MYSQL_USER: test
28+
29+
mysql80:
30+
api: 3
31+
type: lando
32+
services:
33+
image: bitnami/mysql:8.0
34+
command: /opt/bitnami/scripts/mysql/entrypoint.sh /opt/bitnami/scripts/mysql/run.sh
35+
environment:
36+
ALLOW_EMPTY_PASSWORD: yes
37+
MYSQL_AUTHENTICATION_PLUGIN: caching_sha2_password
38+
MYSQL_DATABASE: lando_test
39+
MYSQL_PASSWORD: test
40+
MYSQL_USER: test
41+
42+
postgres16:
43+
api: 3
44+
type: lando
45+
services:
46+
image: bitnami/postgresql:16
47+
command: /opt/bitnami/scripts/postgresql/entrypoint.sh /opt/bitnami/scripts/postgresql/run.sh
48+
environment:
49+
ALLOW_EMPTY_PASSWORD: yes
50+
POSTGRESQL_DATABASE: lando_test
51+
POSTGRES_DB: lando_test
52+
53+
plugins:
54+
"@lando/core": "../../.."

examples/sql-helpers/README.md

Lines changed: 74 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,74 @@
1+
SQL Import/Export Example
2+
============
3+
4+
This example exists primarily to test the `sql-import.sh` and `sql-export.sh` helper scripts.
5+
6+
Start up tests
7+
--------------
8+
9+
```bash
10+
# Should init and start a lando app
11+
rm -rf sqlhelpers && mkdir -p sqlhelpers
12+
cp -rf .lando.sqlhelpers.yml sqlhelpers/.lando.yml
13+
cp -rf testdata1.sql sqlhelpers/testdata1.sql
14+
cp -rf testdata2.sql sqlhelpers/testdata2.sql
15+
cd sqlhelpers && lando start
16+
```
17+
18+
Verification commands
19+
---------------------
20+
21+
Run the following commands to verify things work as expected
22+
23+
```bash
24+
# Should import testdata1.sql into all databases
25+
cd sqlhelpers
26+
lando ssh -s mariadb -c "/helpers/sql-import.sh testdata1.sql"
27+
lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata1.sql"
28+
lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata1.sql"
29+
lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata1.sql"
30+
lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"
31+
lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"
32+
lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep "lando_original"
33+
lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep "lando_original"
34+
35+
# Should export gzipped files from all databases
36+
cd sqlhelpers
37+
lando ssh -s mariadb -c "/helpers/sql-export.sh mariadb_dump.sql" -u root
38+
lando ssh -s mysql57 -c "/helpers/sql-export.sh mysql57_dump.sql" -u root
39+
lando ssh -s mysql80 -c "/helpers/sql-export.sh mysql80_dump.sql" -u root
40+
lando ssh -s postgres16 -c "/helpers/sql-export.sh postgres16_dump.sql" -u root
41+
gzip -d mariadb_dump.sql.gz
42+
gzip -d mysql57_dump.sql.gz
43+
gzip -d mysql80_dump.sql.gz
44+
gzip -d postgres16_dump.sql.gz
45+
46+
# Should have the correct data in the exported files
47+
cd sqlhelpers
48+
grep "lando_original" mariadb_dump.sql
49+
grep "lando_original" mysql57_dump.sql
50+
grep "lando_original" mysql80_dump.sql
51+
grep "lando_original" postgres16_dump.sql
52+
53+
# Should be able to replace data with testdata2.sql
54+
cd sqlhelpers
55+
lando ssh -s mariadb -c "/helpers/sql-import.sh testdata2.sql"
56+
lando ssh -s mariadb -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated"
57+
lando ssh -s mysql57 -c "/helpers/sql-import.sh testdata2.sql"
58+
lando ssh -s mysql57 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated"
59+
lando ssh -s mysql80 -c "/helpers/sql-import.sh testdata2.sql"
60+
lando ssh -s mysql80 -c "mysql -utest -ptest lando_test -e 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated"
61+
lando ssh -s postgres16 -c "/helpers/sql-import.sh testdata2.sql"
62+
lando ssh -s postgres16 -c "psql -U postgres -d lando_test -c 'select * from lando_test'" | grep -v "lando_original" | grep "lando_updated"
63+
```
64+
65+
Destroy tests
66+
-------------
67+
68+
```bash
69+
# Should destroy sqlhelpers successfully
70+
cd sqlhelpers && lando destroy -y
71+
72+
# Should poweroff
73+
lando poweroff
74+
```

examples/sql-helpers/testdata1.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE lando_test (
2+
id SERIAL PRIMARY KEY,
3+
column1 VARCHAR(255) DEFAULT NULL,
4+
column2 VARCHAR(255) DEFAULT NULL
5+
);
6+
INSERT INTO lando_test VALUES (1, 'lando_original', 'lando_original');

examples/sql-helpers/testdata2.sql

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
CREATE TABLE lando_test (
2+
id SERIAL PRIMARY KEY,
3+
column1 VARCHAR(255) DEFAULT NULL,
4+
column2 VARCHAR(255) DEFAULT NULL
5+
);
6+
INSERT INTO lando_test VALUES (1, 'lando_updated', 'lando_updated');

0 commit comments

Comments
 (0)