Skip to content

Commit

Permalink
feat: move test data to dev
Browse files Browse the repository at this point in the history
also updated make test to run the data tests
and removed redundant CI job
  • Loading branch information
matthieu-foucault committed Jul 8, 2020
1 parent 2fe7c1a commit f5a5b25
Show file tree
Hide file tree
Showing 10 changed files with 19 additions and 99 deletions.
30 changes: 0 additions & 30 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -257,33 +257,6 @@ jobs:
paths:
- cas-ciip-portal # persist the build for e2e tests

deploy-test-data:
machine:
image: ubuntu-1604:201903-01
working_directory: ~/cas-ciip-portal
steps:
- attach_workspace:
at: ~/
- run:
name: "Checkout Submodules"
command: |
git submodule update --init
- run:
name: start postgres
command: |
source ~/.bashrc
pg_ctl start
- run:
name: deploy schemas and data
command: |
source ~/.bashrc
./.bin/deploy-data.sh -dev
- run:
name: deploying the data a second time should not fail on primary key conflicts
command: |
source ~/.bashrc
./.bin/deploy-data.sh -dev
acceptance:
machine:
image: ubuntu-1604:201903-01
Expand Down Expand Up @@ -535,9 +508,6 @@ workflows:
- acceptance:
requires:
- tools
- deploy-test-data:
requires:
- tools
- e2e-snapshots:
requires:
- compile
Expand Down
13 changes: 2 additions & 11 deletions schema/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,24 +21,19 @@ PG_SHAREDIR=$(shell pg_config --sharedir)
DEPLOY_DEFAULT_DATA=deploy_dev_data

.PHONY: test
test: | test_deploy_revert $(DEPLOY_DEFAULT_DATA) prove_unit prove_style dropdb
test: | test_data test_deploy_revert $(DEPLOY_DEFAULT_DATA) prove_unit prove_style dropdb

.PHONY: unit
unit: | $(DEPLOY_DEFAULT_DATA) prove_unit

.PHONY: test_data
test_data: | deploy_prod_data prove_prod_data deploy_test_data prove_test_data deploy_dev_data prove_dev_data
test_data: | deploy_prod_data prove_prod_data deploy_dev_data prove_dev_data

.PHONY: deploy_prod_data
deploy_prod_data:
# Deploy prod data in $(TEST_DB)
@@SQITCH_TARGET="db:pg:" PGHOST=localhost PGDATABASE=$(TEST_DB) ./data/deploy-data.sh -d -prod

.PHONY: deploy_test_data
deploy_test_data:
# Deploy test data in $(TEST_DB)
@@SQITCH_TARGET="db:pg:" PGHOST=localhost PGDATABASE=$(TEST_DB) ./data/deploy-data.sh -d -test

.PHONY: deploy_dev_data
deploy_dev_data:
# Deploy dev data in $(TEST_DB)
Expand Down Expand Up @@ -78,10 +73,6 @@ prove_prod_data:
# Run prod_data tests using pg_prove
@@$(PG_PROVE) --failures -d $(TEST_DB) test/data/prod_data_test.sql

.PHONY: prove_test_data
prove_test_data:
# Run test_data tests using pg_prove
@@$(PG_PROVE) --failures -d $(TEST_DB) test/data/test_data_test.sql

.PHONY: prove_dev_data
prove_dev_data:
Expand Down
26 changes: 6 additions & 20 deletions schema/data/deploy-data.sh
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,8 @@ Options
Drops the $database database before deploying
-prod, --prod-data
Deploy production data only
-test, --test-data
Deploy testing data. Inlcudes prod data
-dev, --dev-data
Deploy development data. Includes test and prod data
Deploy development data. Includes prod data
-s, --deploy-swrs-schema
Redeploys the swrs schema and inserts the swrs test reports. This requires the .cas-ggircs submodule to be initialized
-p, --deploy-portal-schema
Expand Down Expand Up @@ -138,9 +136,6 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do case $1 in
-prod | --prod-data | --oc-project=*-prod )
actions+=('deployProd')
;;
-test | --test-data | --oc-project=*-test )
actions+=('deployTest')
;;
-dev | --dev-data | --oc-project=*-dev )
actions+=('deployDev')
;;
Expand Down Expand Up @@ -168,17 +163,12 @@ deployProdData() {
return 0;
}

deployTestData() {
deployProdData
_psql -f "./test/reporting_year.sql"
_psql -f "./test/mock_current_timestamp.sql"
_psql -f "./test/product.sql"
_psql -f "./test/benchmark.sql"
return 0;
}

deployDevData() {
deployTestData
deployProdData
_psql -f "./dev/reporting_year.sql"
_psql -f "./dev/mock_current_timestamp.sql"
_psql -f "./dev/product.sql"
_psql -f "./dev/benchmark.sql"
_psql -f "./dev/user.sql"
_psql -f "./dev/ciip_user_organisation.sql"
_psql -f "./dev/application.sql"
Expand Down Expand Up @@ -206,10 +196,6 @@ if [[ " ${actions[*]} " =~ " deployProd " ]]; then
echo 'Deploying production data'
deployProdData
fi
if [[ " ${actions[*]} " =~ " deployTest " ]]; then
echo 'Deploying testing data'
deployTestData
fi
if [[ " ${actions[*]} " =~ " deployDev " ]]; then
echo 'Deploying development data'
deployDevData
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 2 additions & 4 deletions schema/test/data/dev_data_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,14 @@ create extension if not exists pgtap;
reset client_min_messages;

begin;
select plan(14);
select plan(13);

-- Following dev data (including prod & test) should exist
-- Following dev data (including prod) should exist

prepare reporting_year_data as select * from ggircs_portal.reporting_year;
prepare form_json_data as select * from ggircs_portal.form_json;
prepare ciip_application_wizard_data as select * from ggircs_portal.ciip_application_wizard;
prepare fuel_data as select * from ggircs_portal.fuel;
prepare product_form_data as select * from ggircs_portal.product_form;
prepare product_data as select * from ggircs_portal.product;
prepare organisation_data as select * from ggircs_portal.organisation;
prepare facility_data as select * from ggircs_portal.facility;
Expand All @@ -26,7 +25,6 @@ select isnt_empty('reporting_year_data', 'reporting_year table should not be emp
select isnt_empty('form_json_data', 'form_json table should not be empty');
select isnt_empty('ciip_application_wizard_data', 'ciip_application_wizard table should not be empty');
select isnt_empty('fuel_data', 'fuel table should not be empty');
select isnt_empty('product_form_data', 'product_form table should not be empty');
select isnt_empty('product_data', 'product table should not be empty');
select isnt_empty('organisation_data', 'organisation table should not be empty');
select isnt_empty('facility_data', 'facility table should not be empty');
Expand Down
12 changes: 9 additions & 3 deletions schema/test/data/prod_data_test.sql
Original file line number Diff line number Diff line change
Expand Up @@ -3,31 +3,37 @@ create extension if not exists pgtap;
reset client_min_messages;

begin;
select plan(8);
select plan(11);

-- Following prod data should exist

prepare reporting_year_data as select * from ggircs_portal.reporting_year;
prepare fuel_data as select * from ggircs_portal.fuel;
prepare gas_data as select * from ggircs_portal.gas;
prepare emission_category_gas_data as select * from ggircs_portal.emission_category_gas;

select isnt_empty('reporting_year_data', 'reporting_year table should not be empty');
select isnt_empty('fuel_data', 'fuel table should not be empty');
select isnt_empty('gas_data', 'gas table should not be empty');
select isnt_empty('emission_category_gas_data', 'emission_category_gas table should not be empty');

-- Following data are not prod and tables should be empty

prepare reporting_year_data as select * from ggircs_portal.reporting_year;
prepare benchmark_data as select * from ggircs_portal.benchmark;
prepare user_data as select * from ggircs_portal.ciip_user;
prepare application_data as select * from ggircs_portal.application;
prepare certification_url_data as select * from ggircs_portal.certification_url;
prepare application_revision_data as select * from ggircs_portal.application_revision;
prepare application_revision_status_data as select * from ggircs_portal.application_revision_status;
prepare form_result_data as select * from ggircs_portal.form_result;

select is_empty('reporting_year_data', 'reporting_year table should be empty');
select is_empty('benchmark_data', 'benchmark table should be empty');
select is_empty('user_data', 'ciip_user table should be empty');
select is_empty('application_data', 'application table should be empty');
select is_empty('certification_url_data', 'certification_url table should be empty');
select is_empty('application_revision_data', 'application_revision table should be empty');
select is_empty('application_revision_status_data', 'application_revision_status table should be empty');
select is_empty('form_result_data', 'form_result table should be empty');

select finish();
rollback;
31 changes: 0 additions & 31 deletions schema/test/data/test_data_test.sql

This file was deleted.

0 comments on commit f5a5b25

Please sign in to comment.