diff --git a/.vortex/docs/content/contributing/maintenance/tests.mdx b/.vortex/docs/content/contributing/maintenance/tests.mdx index 55194d5d6..38ee271dc 100644 --- a/.vortex/docs/content/contributing/maintenance/tests.mdx +++ b/.vortex/docs/content/contributing/maintenance/tests.mdx @@ -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' => '

This demo page is sourced from the Vortex database dump file to demonstrate database importing capabilities.

', + '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' => '

This demo page is sourced from the Vortex database container image to demonstrate database importing capabilities.

', + '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' => '

This test page is sourced from the Vortex database dump file to demonstrate database importing capabilities.

', + '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' => '

This test page is sourced from the Vortex database container image to demonstrate database importing capabilities.

', + '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 +``` diff --git a/.vortex/tests/bats/workflow.storage.curl.bats b/.vortex/tests/bats/workflow.storage.curl.bats index 1dcc345e0..e79f76e05 100644 --- a/.vortex/tests/bats/workflow.storage.curl.bats +++ b/.vortex/tests/bats/workflow.storage.curl.bats @@ -65,11 +65,11 @@ 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 @@ -77,7 +77,7 @@ load _helper.workflow.bash 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 @@ -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" } diff --git a/.vortex/tests/bats/workflow.storage.image.bats b/.vortex/tests/bats/workflow.storage.image.bats index adf61a8ec..49a3eb343 100644 --- a/.vortex/tests/bats/workflow.storage.image.bats +++ b/.vortex/tests/bats/workflow.storage.image.bats @@ -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 diff --git a/.vortex/tests/bats/workflow.storage.image_cached.bats b/.vortex/tests/bats/workflow.storage.image_cached.bats index 7a3777c61..9e82f0ff9 100644 --- a/.vortex/tests/bats/workflow.storage.image_cached.bats +++ b/.vortex/tests/bats/workflow.storage.image_cached.bats @@ -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" @@ -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 }