Skip to content

Commit

Permalink
#1144: SQL export func tests
Browse files Browse the repository at this point in the history
  • Loading branch information
pirog committed Sep 9, 2018
1 parent 09471e5 commit c15ddb2
Show file tree
Hide file tree
Showing 6 changed files with 203 additions and 38 deletions.
5 changes: 0 additions & 5 deletions examples/sql-export/.lando.yml
Expand Up @@ -36,11 +36,6 @@ services:
password: mysql
database: data1

# Optionally load in all the mysql config files in the config directory
# This is relative to the app root
# config:
# confd: config

# Spin up a secondary database for postgres
database2:
type: postgres
Expand Down
60 changes: 48 additions & 12 deletions examples/sql-export/README.md
Expand Up @@ -5,17 +5,41 @@ This example provides a very basic `db-export` example built on Lando php servic

See the `.lando.yml` in this directory for `db-export` configuration options.

Getting Started
---------------
Start the example
-----------------

You should be able to run the following steps to get up and running with this example.
Run the following commands to get up and running with this example.

```bash
# Start up the example
# Boot up a sql-export example
lando start
```

Testing the example
-------------------

```bash
# Verify the databases are up and good
lando ssh database -c "mysql -umysql -pmysql data1 -e\"quit\""
lando ssh database2 -c "psql -U postgres database -c \'\\\dt\'"

# Verify our dynamic commands work
lando psql -h database2 -V
lando mysql -V

# Import the test mysql file against the default database
lando db-import test.sql

# Import the test postgres file to the secondary database
lando db-import -h database2 test2.sql

# Check out other commands you can use with this example
lando
# Verify that we have a 'users' table on both databases
lando ssh database -c "mysql -u mysql -pmysql data1 -e \'show tables;\' | grep users"
lando ssh database2 -c "psql -U postgres -h database2 database -c \'\\\dt\' | grep users"

# Export the contents of the dbs
lando db-export
lando db-export -h database2
```

Helpful Commands
Expand All @@ -34,13 +58,25 @@ lando db-import -h database2 test2.sql
# See export options
lando db-export -- --help

# Verify that we have a 'users' table on both databases
# NOTE: This will only work if you've run `lando db-import test.sql` already
lando mysql data1 -e "show tables;"
# NOTE: This will only work if you've run `lando db-import -h database2 test2.sql` already
lando psql -h database2 database -c "\dt"

# Export the contents of the dbs
lando db-export
lando db-export -h database2

# Verify the expected export dumps are there
cat data1.*.gz
cat database.*.gz
```

Destroying the example
----------------------

Run the following commands to destroy

```bash
# Remove the exported DBs
rm -f data1.*.gz
rm -f database.*.gz

# Blow up the sql-export example
lando destroy -y
```
5 changes: 0 additions & 5 deletions examples/sql-import/.lando.yml
Expand Up @@ -36,11 +36,6 @@ services:
password: mysql
database: data1

# Optionally load in all the mysql config files in the config directory
# This is relative to the app root
# config:
# confd: config

# Spin up a secondary database for postgres
database2:
type: postgres
Expand Down
16 changes: 4 additions & 12 deletions examples/sql-import/README.md
Expand Up @@ -11,9 +11,8 @@ Start the example
Run the following commands to get up and running with this example.

```bash
# Boot up a db-import example
# lando start
true
# Boot up a sql-import example
lando start
```

Testing the example
Expand Down Expand Up @@ -63,12 +62,6 @@ lando db-import test.sql

# Import the test postgres file to the secondary database
lando db-import -h database2 test2.sql

# Verify that we have a 'users' table on both databases
# NOTE: This will only work if you've run `lando db-import test.sql` already
lando mysql data1 -e "show tables;"
# NOTE: This will only work if you've run `lando db-import -h database2 test2.sql` already
lando psql -h database2 database -c "\dt"
```

Destroying the example
Expand All @@ -77,7 +70,6 @@ Destroying the example
Run the following commands to destroy

```bash
# Blow up the db-import example
# lando destroy -y
true
# Blow up the sql-import example
lando destroy -y
```
147 changes: 147 additions & 0 deletions test/func/sql-export.spec.js
@@ -0,0 +1,147 @@
/*
* This file was automatically generated, editing it manually would be foolish
*
* See https://docs.devwithlando.io/dev/testing.html#functional-tests for more
* information on how all this magic works
*
* title: sql-export-example
* src: examples/sql-export
*/
// We need these deps to run our tezts
const chai = require('chai');
const CliTest = require('command-line-test');
const path = require('path');
chai.should();

// eslint-disable max-len

describe('sql-export', () => {
// These are tests we need to run to get the app into a state to test
// @todo: It would be nice to eventually get these into mocha before hooks
// so they run before every test
it('boot up a sql export example', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js start').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

// These tests are the main event
// @todo: It would be nice to eventually get these into mocha after hooks
// so they run after every test
it('verify the databases are up and good', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js ssh database -c "mysql -umysql -pmysql data1 -e\"quit\"" && node ../../bin/lando.js ssh database2 -c "psql -U postgres database -c \'\\\dt\'"').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

it('verify our dynamic commands work', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js psql -h database2 -V && node ../../bin/lando.js mysql -V').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

it('import the test mysql file against the default database', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js db-import test.sql').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

it('import the test postgres file to the secondary database', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js db-import -h database2 test2.sql').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

it('verify that we have a users table on both databases', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js ssh database -c "mysql -u mysql -pmysql data1 -e \'show tables;\' | grep users" && node ../../bin/lando.js ssh database2 -c "psql -U postgres -h database2 database -c \'\\\dt\' | grep users"').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

it('export the contents of the dbs', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js db-export && node ../../bin/lando.js db-export -h database2').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

// These are tests we need to run to get the app into a state to test
// @todo: It would be nice to eventually get these into mocha before hooks
// so they run before every test
it('remove the exported d bs', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('rm -f data1.*.gz && rm -f database.*.gz').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});

// These are tests we need to run to get the app into a state to test
// @todo: It would be nice to eventually get these into mocha before hooks
// so they run before every test
it('blow up the sql export example', done => {
process.chdir('examples/sql-export');
const cli = new CliTest();
cli.exec('node ../../bin/lando.js destroy -y').then(res => {
if (res.error === null) {
done();
} else {
done(res.error);
}
});
process.chdir(path.join('..', '..'));
});
});
8 changes: 4 additions & 4 deletions test/func/sql-import.spec.js
Expand Up @@ -19,10 +19,10 @@ describe('sql-import', () => {
// These are tests we need to run to get the app into a state to test
// @todo: It would be nice to eventually get these into mocha before hooks
// so they run before every test
it('boot up a db import example', done => {
it('boot up a sql import example', done => {
process.chdir('examples/sql-import');
const cli = new CliTest();
cli.exec('true').then(res => {
cli.exec('node ../../bin/lando.js start').then(res => {
if (res.error === null) {
done();
} else {
Expand Down Expand Up @@ -103,10 +103,10 @@ describe('sql-import', () => {
// These are tests we need to run to get the app into a state to test
// @todo: It would be nice to eventually get these into mocha before hooks
// so they run before every test
it('blow up the db import example', done => {
it('blow up the sql import example', done => {
process.chdir('examples/sql-import');
const cli = new CliTest();
cli.exec('true').then(res => {
cli.exec('node ../../bin/lando.js destroy -y').then(res => {
if (res.error === null) {
done();
} else {
Expand Down

0 comments on commit c15ddb2

Please sign in to comment.