From 915e596ccf4791e7f2b6388f59163cbd60cbc753 Mon Sep 17 00:00:00 2001
From: Ilia Eriomenco <ilia.eriomenco@endava.com>
Date: Fri, 26 Mar 2021 16:53:46 +0200
Subject: [PATCH] ci: refactored eLife tests with DRY

---
 .gitlab-ci.elife.yml | 299 ++++++++++++++++++++++++-------------------
 1 file changed, 165 insertions(+), 134 deletions(-)

diff --git a/.gitlab-ci.elife.yml b/.gitlab-ci.elife.yml
index 70501f54cd..7fa454775f 100644
--- a/.gitlab-ci.elife.yml
+++ b/.gitlab-ci.elife.yml
@@ -83,6 +83,37 @@ lint:
     INSTANCE_NAME: elife
   services:
     - postgres
+  script:
+    - cd ${HOME}
+    - apt-get -y install postgresql-client
+    # this is needed for pgboss initial setup
+    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+    # use the example env for tests
+    - cp .env.example .env
+    - # specify host here else it confuses the linked postgres image
+    - POSTGRES_HOST=postgres yarn test:all:chrome:$TEST_ITEM
+
+test-chrome:
+  <<: *run_test_template
+  variables:
+    TEST_ITEM: elife
+
+# .test_template: &run_test_template
+#   image: $IMAGE_ORG/$IMAGE_NAME-dev:$CI_COMMIT_SHA
+#   stage: test
+#   variables:
+#     GIT_STRATEGY: none
+#     # setup data for postgres image
+#     POSTGRES_USER: kotahidev
+#     POSTGRES_PASSWORD: kotahidev
+#     # used by psql
+#     PGUSER: kotahidev
+#     PGPASSWORD: kotahidev
+#     # this is used to ignore self signed certs
+#     START_SERVER_AND_TEST_INSECURE: 1
+#     INSTANCE_NAME: elife
+#   services:
+#     - postgres
 
 #.script_template: &run_script_template
 #    - cd ${HOME}
@@ -94,148 +125,148 @@ lint:
 #    - # specify host here else it confuses the linked postgres image
 #    - POSTGRES_HOST=postgres yarn test:all:chrome:$TEST_ITEM
 
-test-chrome:
-  <<: *run_test_template
-  variables:
-    TEST_ITEM: elife
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:chrome:elife
+# test-chrome:
+#   <<: *run_test_template
+#   variables:
+#     TEST_ITEM: elife
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:chrome:elife
 
-test-chrome-samsung:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:chrome:elife:samsung
+# test-chrome-samsung:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:chrome:elife:samsung
 
-test-chrome-samsung-tablet:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:chrome:elife:samsung:tablet
+# test-chrome-samsung-tablet:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:chrome:elife:samsung:tablet
 
-test-chrome-iPhone:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:chrome:elife:iPhone
+# test-chrome-iPhone:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:chrome:elife:iPhone
 
-test-chrome-iPhone-tablet:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:chrome:elife:iPhone:tablet
+# test-chrome-iPhone-tablet:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:chrome:elife:iPhone:tablet
 
-test-chrome-hd-laptop:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:chrome:elife:hd:laptop
+# test-chrome-hd-laptop:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:chrome:elife:hd:laptop
 
-test-firefox:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:firefox:elife
+# test-firefox:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:firefox:elife
 
-test-firefox-samsung:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:firefox:elife:samsung
+# test-firefox-samsung:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:firefox:elife:samsung
 
-test-firefox-samsung-tablet:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:firefox:elife:samsung:tablet
+# test-firefox-samsung-tablet:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:firefox:elife:samsung:tablet
 
-test-firefox-iPhone:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:firefox:elife:iPhone
+# test-firefox-iPhone:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:firefox:elife:iPhone
 
-test-firefox-iPhone-tablet:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:firefox:elife:iPhone:tablet
+# test-firefox-iPhone-tablet:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:firefox:elife:iPhone:tablet
 
-test-firefox-hd-laptop:
-  <<: *run_test_template
-  script:
-    - cd ${HOME}
-    - apt-get -y install postgresql-client
-    # this is needed for pgboss initial setup
-    - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
-    # use the example env for tests
-    - cp .env.example .env
-    # specify host here else it confuses the linked postgres image
-    - POSTGRES_HOST=postgres yarn test:all:firefox:elife:hd:laptop
\ No newline at end of file
+# test-firefox-hd-laptop:
+#   <<: *run_test_template
+#   script:
+#     - cd ${HOME}
+#     - apt-get -y install postgresql-client
+#     # this is needed for pgboss initial setup
+#     - psql -h postgres -U kotahidev -d kotahidev -c "create extension pgcrypto;"
+#     # use the example env for tests
+#     - cp .env.example .env
+#     # specify host here else it confuses the linked postgres image
+#     - POSTGRES_HOST=postgres yarn test:all:firefox:elife:hd:laptop
\ No newline at end of file
-- 
GitLab