Skip to content

Commit

Permalink
Updated docs about seeding demo and test databases.
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexSkrypnyk committed Dec 3, 2024
1 parent bb3f7f9 commit 26b2f2e
Show file tree
Hide file tree
Showing 4 changed files with 154 additions and 30 deletions.
164 changes: 144 additions & 20 deletions .vortex/docs/content/contributing/maintenance/tests.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -38,35 +38,159 @@ bats --no-tempdir-cleanup .vortex/tests/bats/*.bats

## Updating test assets

Some tests use test fixtures such as Drupal database snapshots.
There are *demo* and *test* database dumps captured as *files* and *container images*.

### Updating demo database file dump
- Demo database dump file - *demonstration* of the database import capabilities from a *file* during a normal workflow.
- Demo database container image - *demonstration* of the database import capabilities from a *container image* during a normal workflow.
- Test database dump file - *test* of the database import capabilities from a *file* during the normal workflow.
- Test database container image - *test* of the database import capabilities from a *container image* during the normal workflow.

### Updating *demo* database dump *file*

1. Run fresh build of **Vortex** locally:
```bash
echo "DRUPAL_PROFILE=standard">>.env.local
echo "VORTEX_PROVISION_USE_PROFILE=1">>.env.local
rm .data/db.sql
AHOY_CONFIRM_RESPONSE=1 ahoy build
rm .data/db.sql || true
VORTEX_PROVISION_USE_PROFILE=1 AHOY_CONFIRM_RESPONSE=1 ahoy build
```
2. Update content and config:
```bash
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the demo site!',
'body' => [
'value' => '<p>This demo page is sourced from the Vortex database dump file to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

```
2. Add a new `Basic page` node with title `Welcome to the demo site!` and content
3. Export DB:
```bash
ahoy export-db db.demo.sql
```
Welcome to the demo site!
4. Upload `db.demo.sql` to the latest release as an asset and name it `db_d11.demo.sql`.

### Updating *demo* database *container image*

This example page is sourced from the Vortex example database dump file to demonstrate database importing capabilities.
1. Run fresh build of **Vortex** locally:
```bash
rm .data/db.sql || true
VORTEX_PROVISION_USE_PROFILE=1 AHOY_CONFIRM_RESPONSE=1 ahoy build
```
3. Truncate `cache_*` and `watchdog` tables.
4. Export DB `ahoy export-db` and rename it to `db.sql`.
5. Run `ahoy provision` and check if there are no errors or warnings in the output.
6. Run `ahoy test` and check if all tests pass.
7. Rename `db.sql` to `db_dX.demo.sql`, where `X` is the next Drupal version number.
5. Update references in code from the current version `db_dY.demo.sql` to `db_dX.demo.sql`.
6. Upload the DB dump file to the latest release as an asset (`db_dX.demo.sql`).
2. Update content and config:
```bash
ahoy cli

### Updating demo database container image
drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the demo site!',
'body' => [
'value' => '<p>This demo page is sourced from the Vortex database container image to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

:::note "Work in progress"
drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

The documentation section is still a work in progress.
exit

:::
```
3. Export DB:
```bash
ahoy export-db db.demo_image.sql
```
4. Seed the database container image:
```bash
curl -LO https://github.com/drevops/mariadb-drupal-data/releases/latest/download/seed.sh
chmod +x seed.sh
./seed.sh .data/db.demo_image.sql drevops/vortex-dev-mariadb-drupal-data-demo-11.x:latest
```

### Updating *test* database dump *file*

1. Run a fresh install of **Vortex** into a new directory and name the project `Star Wars`:
```bash
mkdir /tmp/star-wars
VORTEX_INSTALL_LOCAL_REPO="$(pwd)" .vortex/installer/install /tmp/star-wars --quiet
cd /tmp/star-wars
```
2. Run fresh build of **Vortex** locally:
```bash
rm .data/db.sql || true
VORTEX_PROVISION_USE_PROFILE=1 AHOY_CONFIRM_RESPONSE=1 ahoy build
```
3. Update content and config:
```bash
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the test site!',
'body' => [
'value' => '<p>This test page is sourced from the Vortex database dump file to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

```
4. Export DB:
```bash
ahoy export-db db.test.sql
```
5. Upload `db.test.sql` to the latest release as an asset and name it `db_d11.test.sql`.

### Updating *test* database *container image*

1. Run a fresh install of **Vortex** into a new directory and name the project `Star Wars`:
```bash
mkdir /tmp/star-wars
VORTEX_INSTALL_LOCAL_REPO="$(pwd)" .vortex/installer/install /tmp/star-wars --quiet
cd /tmp/star-wars
```
2. Run fresh build of **Vortex** locally:
```bash
rm .data/db.sql || true
VORTEX_PROVISION_USE_PROFILE=1 AHOY_CONFIRM_RESPONSE=1 ahoy build
```
3. Update content and config:
```bash
ahoy cli

drush eval "Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'page',
'title' => 'Welcome to the test site!',
'body' => [
'value' => '<p>This test page is sourced from the Vortex database container image to demonstrate database importing capabilities.</p>',
'format' => 'basic_html',
],
])->save();"

drush config:set system.site page.front "/node/1" -y
drush sql:query "SHOW TABLES LIKE 'cache_%'" | xargs -I{} drush sql:query "TRUNCATE TABLE {}" && drush sql:query "TRUNCATE TABLE watchdog"

exit

```
4. Export DB:
```bash
ahoy export-db db.test_image.sql
```
5. Seed the database container image:
```bash
curl -LO https://github.com/drevops/mariadb-drupal-data/releases/latest/download/seed.sh
chmod +x seed.sh
./seed.sh .data/db.test_image.sql drevops/vortex-dev-mariadb-drupal-data-test-11.x:latest
```
8 changes: 4 additions & 4 deletions .vortex/tests/bats/workflow.storage.curl.bats
Original file line number Diff line number Diff line change
Expand Up @@ -65,19 +65,19 @@ load _helper.workflow.bash

step "Case 1: Site is built from DB file, site reloaded from image, while DB file exists."
substep "Assert that the text is from the DB dump."
assert_webpage_contains "/" "test database dump"
assert_webpage_contains "/" "This test page is sourced from the Vortex database dump file"

substep "Set content to a different path."
ahoy drush config-set system.site page.front /user -y
assert_webpage_not_contains "/" "test database dump"
assert_webpage_not_contains "/" "This test page is sourced from the Vortex database dump file"

substep "Reloading DB from image with DB dump file present"
assert_file_exists .data/db.sql
run ahoy reload-db
assert_success

substep "Assert that the text is from the DB dump after reload."
assert_webpage_contains "/" "test database dump"
assert_webpage_contains "/" "This test page is sourced from the Vortex database dump file"

# Skipped: the provision.sh expects DB dump file to exist; this logic
# needs to be refactored. Currently, reloading without DB dump file present
Expand All @@ -90,7 +90,7 @@ load _helper.workflow.bash
# assert_success
#
# substep "Assert that the text is from the container image."
# assert_page_contains "/" "test database Docker image"
# assert_page_contains "/" "This test page is sourced from the Vortex database container image"

assert_ahoy_export_db "mydb.tar"
}
6 changes: 3 additions & 3 deletions .vortex/tests/bats/workflow.storage.image.bats
Original file line number Diff line number Diff line change
Expand Up @@ -59,14 +59,14 @@ load _helper.workflow.bash
step "Reload DB image"

# Assert that used DB image has content.
assert_webpage_contains "/" "test database Docker image"
assert_webpage_contains "/" "This test page is sourced from the Vortex database container image"

# Change homepage content and assert that the change was applied.
ahoy drush config-set system.site page.front /user -y
assert_webpage_not_contains "/" "test database Docker image"
assert_webpage_not_contains "/" "This test page is sourced from the Vortex database container image"

ahoy reload-db
assert_webpage_contains "/" "test database Docker image"
assert_webpage_contains "/" "This test page is sourced from the Vortex database container image"

# Other stack assertions - these run only for this container image-related test.
assert_gitignore
Expand Down
6 changes: 3 additions & 3 deletions .vortex/tests/bats/workflow.storage.image_cached.bats
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,12 @@ load _helper.workflow.bash
# Make a change to current site, export the DB image, remove existing DB image
# and rebuild the stack - the used image should have the expected changes.
substep "Assert that used DB image has content."
assert_webpage_contains "/" "test database Docker image"
assert_webpage_contains "/" "This test page is sourced from the Vortex database container image"
assert_webpage_not_contains "/" "Username"

substep "Change homepage content and assert that the change was applied."
ahoy drush config-set system.site page.front /user -y
assert_webpage_not_contains "/" "test database Docker image"
assert_webpage_not_contains "/" "This test page is sourced from the Vortex database container image"
assert_webpage_contains "/" "Username"

substep "Exporting DB image to a file"
Expand Down Expand Up @@ -107,7 +107,7 @@ load _helper.workflow.bash
assert_output_contains "Finished building project"

step "Assert that the contents of the DB was loaded from the exported DB image file."
assert_webpage_not_contains "/" "test database Docker image"
assert_webpage_not_contains "/" "This test page is sourced from the Vortex database container image"
assert_webpage_contains "/" "Username"
ahoy clean
}

1 comment on commit 26b2f2e

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.