From fa93e5a1a7a2b06cc7a9d5585b4a70c4d08ed342 Mon Sep 17 00:00:00 2001 From: Andrey Antukh Date: Thu, 3 Nov 2022 10:35:19 +0100 Subject: [PATCH] :recycle: Refactor backend tests directory tree --- .circleci/config.yml | 59 ++++++++---------- backend/dev/user.clj | 2 +- .../test_bounce_handling.clj} | 4 +- .../test_email_sending.clj} | 8 +-- .../{app => app_tests}/test_files/font-1.otf | Bin .../{app => app_tests}/test_files/font-1.ttf | Bin .../{app => app_tests}/test_files/font-1.woff | Bin .../{app => app_tests}/test_files/font-2.otf | Bin .../{app => app_tests}/test_files/font-2.woff | Bin .../{app => app_tests}/test_files/sample.jpg | Bin .../{app => app_tests}/test_files/sample1.svg | 0 .../{app => app_tests}/test_files/sample2.svg | 0 .../test_files/template.penpot | Bin .../test/{app => app_tests}/test_helpers.clj | 4 +- .../test_rpc_file.clj} | 6 +- .../test_rpc_font.clj} | 8 +-- .../test_rpc_management.clj} | 8 +-- .../test_rpc_media.clj} | 8 +-- .../test_rpc_profile.clj} | 6 +- .../test_rpc_project.clj} | 4 +- .../test_rpc_team.clj} | 4 +- .../test_rpc_viewer.clj} | 4 +- .../test_storage.clj} | 12 ++-- .../test_telemetry_task.clj} | 4 +- 24 files changed, 68 insertions(+), 73 deletions(-) rename backend/test/{app/bounce_handling_test.clj => app_tests/test_bounce_handling.clj} (99%) rename backend/test/{app/emails_test.clj => app_tests/test_email_sending.clj} (88%) rename backend/test/{app => app_tests}/test_files/font-1.otf (100%) rename backend/test/{app => app_tests}/test_files/font-1.ttf (100%) rename backend/test/{app => app_tests}/test_files/font-1.woff (100%) rename backend/test/{app => app_tests}/test_files/font-2.otf (100%) rename backend/test/{app => app_tests}/test_files/font-2.woff (100%) rename backend/test/{app => app_tests}/test_files/sample.jpg (100%) rename backend/test/{app => app_tests}/test_files/sample1.svg (100%) rename backend/test/{app => app_tests}/test_files/sample2.svg (100%) rename backend/test/{app => app_tests}/test_files/template.penpot (100%) rename backend/test/{app => app_tests}/test_helpers.clj (99%) rename backend/test/{app/services_files_test.clj => app_tests/test_rpc_file.clj} (99%) rename backend/test/{app/services_fonts_test.clj => app_tests/test_rpc_font.clj} (92%) rename backend/test/{app/services_management_test.clj => app_tests/test_rpc_management.clj} (99%) rename backend/test/{app/services_media_test.clj => app_tests/test_rpc_media.clj} (96%) rename backend/test/{app/services_profile_test.clj => app_tests/test_rpc_profile.clj} (99%) rename backend/test/{app/services_projects_test.clj => app_tests/test_rpc_project.clj} (99%) rename backend/test/{app/services_teams_test.clj => app_tests/test_rpc_team.clj} (99%) rename backend/test/{app/services_viewer_test.clj => app_tests/test_rpc_viewer.clj} (98%) rename backend/test/{app/storage_test.clj => app_tests/test_storage.clj} (97%) rename backend/test/{app/tasks_telemetry_test.clj => app_tests/test_telemetry_task.clj} (96%) diff --git a/.circleci/config.yml b/.circleci/config.yml index 41160d33b..f044e1780 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -3,19 +3,19 @@ jobs: build: docker: - image: penpotapp/devenv:latest - - image: cimg/postgres:13.5 + - image: cimg/postgres:14.5 environment: POSTGRES_USER: penpot_test POSTGRES_PASSWORD: penpot_test POSTGRES_DB: penpot_test - - image: cimg/redis:6.2.6 + - image: cimg/redis:7.0.5 working_directory: ~/repo resource_class: large environment: # Customize the JVM maximum heap limit - JVM_OPTS: -Xmx1g + JVM_OPTS: -Xmx4g steps: - checkout @@ -29,6 +29,13 @@ jobs: - run: cd .clj-kondo && cat config.edn + - run: + name: frontend styles prettier + working_directory: "./frontend" + command: | + yarn install + yarn run lint-scss + - run: name: common lint working_directory: "./common" @@ -43,13 +50,6 @@ jobs: clj-kondo --version clj-kondo --parallel --lint src/ - - run: - name: frontend styles prettier - working_directory: "./frontend" - command: | - yarn install - yarn run lint-scss - - run: name: backend lint working_directory: "./backend" @@ -57,16 +57,31 @@ jobs: clj-kondo --version clj-kondo --parallel --lint src/ - # run backend test + - run: + working_directory: "./common" + name: common tests + command: | + yarn install + yarn run compile-test + node target/test.js + clojure -X:dev:test :patterns '["common-tests.test-.*"]' + + environment: + PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin + JVM_OPTS: -Xmx4g + - run: name: backend test working_directory: "./backend" - command: "clojure -X:dev:test" + command: | + clojure -X:dev:test :patterns '["app-tests.test-.*"]' + environment: PENPOT_TEST_DATABASE_URI: "postgresql://localhost/penpot_test" PENPOT_TEST_DATABASE_USERNAME: penpot_test PENPOT_TEST_DATABASE_PASSWORD: penpot_test PENPOT_TEST_REDIS_URI: "redis://localhost/1" + JVM_OPTS: -Xmx4g - run: name: frontend tests @@ -79,26 +94,6 @@ jobs: environment: PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin - - run: - working_directory: "./common" - name: common tests (cljs) - command: | - yarn install - yarn run compile-test - node target/test.js - - environment: - PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin - - - run: - working_directory: "./common" - name: common tests (clj) - command: | - clojure -X:dev:test :patterns '["common-tests.test-.*"]' - - environment: - PATH: /usr/local/nodejs/bin/:/usr/local/bin:/bin:/usr/bin - - save_cache: paths: - ~/.m2 diff --git a/backend/dev/user.clj b/backend/dev/user.clj index 53a10faaa..bf41b1dc6 100644 --- a/backend/dev/user.clj +++ b/backend/dev/user.clj @@ -63,7 +63,7 @@ ;; --- Development Stuff (defn- run-tests - ([] (run-tests #"^app.*-test$")) + ([] (run-tests #"^app-tests.test-.*$")) ([o] (repl/refresh) (cond diff --git a/backend/test/app/bounce_handling_test.clj b/backend/test/app_tests/test_bounce_handling.clj similarity index 99% rename from backend/test/app/bounce_handling_test.clj rename to backend/test/app_tests/test_bounce_handling.clj index 2e22c1fa8..dacea8e0c 100644 --- a/backend/test/app/bounce_handling_test.clj +++ b/backend/test/app_tests/test_bounce_handling.clj @@ -4,12 +4,12 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.bounce-handling-test +(ns app-tests.test-bounce-handling (:require + [app-tests.test-helpers :as th] [app.db :as db] [app.emails :as emails] [app.http.awsns :as awsns] - [app.test-helpers :as th] [app.tokens :as tokens] [app.util.time :as dt] [clojure.pprint :refer [pprint]] diff --git a/backend/test/app/emails_test.clj b/backend/test/app_tests/test_email_sending.clj similarity index 88% rename from backend/test/app/emails_test.clj rename to backend/test/app_tests/test_email_sending.clj index d429065aa..b91cf5780 100644 --- a/backend/test/app/emails_test.clj +++ b/backend/test/app_tests/test_email_sending.clj @@ -4,13 +4,13 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.emails-test +(ns app-tests.test-email-sending (:require - [clojure.test :as t] - [promesa.core :as p] + [app-tests.test-helpers :as th] [app.db :as db] [app.emails :as emails] - [app.test-helpers :as th])) + [clojure.test :as t] + [promesa.core :as p])) (t/use-fixtures :once th/state-init) (t/use-fixtures :each th/database-reset) diff --git a/backend/test/app/test_files/font-1.otf b/backend/test/app_tests/test_files/font-1.otf similarity index 100% rename from backend/test/app/test_files/font-1.otf rename to backend/test/app_tests/test_files/font-1.otf diff --git a/backend/test/app/test_files/font-1.ttf b/backend/test/app_tests/test_files/font-1.ttf similarity index 100% rename from backend/test/app/test_files/font-1.ttf rename to backend/test/app_tests/test_files/font-1.ttf diff --git a/backend/test/app/test_files/font-1.woff b/backend/test/app_tests/test_files/font-1.woff similarity index 100% rename from backend/test/app/test_files/font-1.woff rename to backend/test/app_tests/test_files/font-1.woff diff --git a/backend/test/app/test_files/font-2.otf b/backend/test/app_tests/test_files/font-2.otf similarity index 100% rename from backend/test/app/test_files/font-2.otf rename to backend/test/app_tests/test_files/font-2.otf diff --git a/backend/test/app/test_files/font-2.woff b/backend/test/app_tests/test_files/font-2.woff similarity index 100% rename from backend/test/app/test_files/font-2.woff rename to backend/test/app_tests/test_files/font-2.woff diff --git a/backend/test/app/test_files/sample.jpg b/backend/test/app_tests/test_files/sample.jpg similarity index 100% rename from backend/test/app/test_files/sample.jpg rename to backend/test/app_tests/test_files/sample.jpg diff --git a/backend/test/app/test_files/sample1.svg b/backend/test/app_tests/test_files/sample1.svg similarity index 100% rename from backend/test/app/test_files/sample1.svg rename to backend/test/app_tests/test_files/sample1.svg diff --git a/backend/test/app/test_files/sample2.svg b/backend/test/app_tests/test_files/sample2.svg similarity index 100% rename from backend/test/app/test_files/sample2.svg rename to backend/test/app_tests/test_files/sample2.svg diff --git a/backend/test/app/test_files/template.penpot b/backend/test/app_tests/test_files/template.penpot similarity index 100% rename from backend/test/app/test_files/template.penpot rename to backend/test/app_tests/test_files/template.penpot diff --git a/backend/test/app/test_helpers.clj b/backend/test/app_tests/test_helpers.clj similarity index 99% rename from backend/test/app/test_helpers.clj rename to backend/test/app_tests/test_helpers.clj index 0d9c3ddf5..e5837ebc1 100644 --- a/backend/test/app/test_helpers.clj +++ b/backend/test/app_tests/test_helpers.clj @@ -4,7 +4,7 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.test-helpers +(ns app-tests.test-helpers (:require [app.common.data :as d] [app.common.flags :as flags] @@ -65,7 +65,7 @@ :name "test" :file-uri "test" :thumbnail-uri "test" - :path (-> "app/test_files/template.penpot" io/resource fs/path)}] + :path (-> "app_tests/test_files/template.penpot" io/resource fs/path)}] system (-> (merge main/system-config main/worker-config) (assoc-in [:app.redis/redis :uri] (:redis-uri config)) (assoc-in [:app.db/pool :uri] (:database-uri config)) diff --git a/backend/test/app/services_files_test.clj b/backend/test/app_tests/test_rpc_file.clj similarity index 99% rename from backend/test/app/services_files_test.clj rename to backend/test/app_tests/test_rpc_file.clj index 913ddba5e..cdaf56171 100644 --- a/backend/test/app/services_files_test.clj +++ b/backend/test/app_tests/test_rpc_file.clj @@ -4,14 +4,14 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-files-test +(ns app-tests.test-rpc-file (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.db.sql :as sql] [app.http :as http] [app.storage :as sto] - [app.test-helpers :as th] [app.util.time :as dt] [clojure.test :as t] [datoteka.core :as fs])) @@ -124,7 +124,7 @@ (t/deftest file-gc-task (letfn [(create-file-media-object [{:keys [profile-id file-id]}] (let [mfile {:filename "sample.jpg" - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg" :size 312043} params {::th/type :upload-file-media-object diff --git a/backend/test/app/services_fonts_test.clj b/backend/test/app_tests/test_rpc_font.clj similarity index 92% rename from backend/test/app/services_fonts_test.clj rename to backend/test/app_tests/test_rpc_font.clj index 36c6112cf..40f9b8085 100644 --- a/backend/test/app/services_fonts_test.clj +++ b/backend/test/app_tests/test_rpc_font.clj @@ -4,13 +4,13 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-fonts-test +(ns app-tests.test-rpc-font (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.http :as http] [app.storage :as sto] - [app.test-helpers :as th] [clojure.test :as t] [datoteka.fs :as fs] [datoteka.io :as io])) @@ -24,7 +24,7 @@ proj-id (:default-project-id prof) font-id (uuid/custom 10 1) - ttfdata (-> (io/resource "app/test_files/font-1.ttf") + ttfdata (-> (io/resource "app_tests/test_files/font-1.ttf") io/input-stream io/read-as-bytes) @@ -59,7 +59,7 @@ proj-id (:default-project-id prof) font-id (uuid/custom 10 1) - data (-> (io/resource "app/test_files/font-1.woff") + data (-> (io/resource "app_tests/test_files/font-1.woff") io/input-stream io/read-as-bytes) diff --git a/backend/test/app/services_management_test.clj b/backend/test/app_tests/test_rpc_management.clj similarity index 99% rename from backend/test/app/services_management_test.clj rename to backend/test/app_tests/test_rpc_management.clj index 79a08d4ec..194508b5e 100644 --- a/backend/test/app/services_management_test.clj +++ b/backend/test/app_tests/test_rpc_management.clj @@ -4,16 +4,16 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-management-test +(ns app-tests.test-rpc-management (:require + [app-tests.test-storage :refer [configure-storage-backend]] + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.http :as http] [app.storage :as sto] - [app.test-helpers :as th] - [app.storage-test :refer [configure-storage-backend]] - [clojure.test :as t] [buddy.core.bytes :as b] + [clojure.test :as t] [datoteka.core :as fs])) (t/use-fixtures :once th/state-init) diff --git a/backend/test/app/services_media_test.clj b/backend/test/app_tests/test_rpc_media.clj similarity index 96% rename from backend/test/app/services_media_test.clj rename to backend/test/app_tests/test_rpc_media.clj index 8e638f490..e36159713 100644 --- a/backend/test/app/services_media_test.clj +++ b/backend/test/app_tests/test_rpc_media.clj @@ -4,12 +4,12 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-media-test +(ns app-tests.test-rpc-media (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.storage :as sto] - [app.test-helpers :as th] [clojure.test :as t] [datoteka.core :as fs])) @@ -60,7 +60,7 @@ :project-id (:default-project-id prof) :is-shared false}) mfile {:filename "sample.jpg" - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg" :size 312043} @@ -99,7 +99,7 @@ :project-id (:default-project-id prof) :is-shared false}) mfile {:filename "sample.jpg" - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg" :size 312043} diff --git a/backend/test/app/services_profile_test.clj b/backend/test/app_tests/test_rpc_profile.clj similarity index 99% rename from backend/test/app/services_profile_test.clj rename to backend/test/app_tests/test_rpc_profile.clj index 884707598..574d77745 100644 --- a/backend/test/app/services_profile_test.clj +++ b/backend/test/app_tests/test_rpc_profile.clj @@ -4,14 +4,14 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-profile-test +(ns app-tests.test-rpc-profile (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.config :as cf] [app.db :as db] [app.rpc.commands.auth :as cauth] [app.rpc.mutations.profile :as profile] - [app.test-helpers :as th] [app.tokens :as tokens] [app.util.time :as dt] [clojure.java.io :as io] @@ -110,7 +110,7 @@ :profile-id (:id profile) :file {:filename "sample.jpg" :size 123123 - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg"}} out (th/mutation! data)] diff --git a/backend/test/app/services_projects_test.clj b/backend/test/app_tests/test_rpc_project.clj similarity index 99% rename from backend/test/app/services_projects_test.clj rename to backend/test/app_tests/test_rpc_project.clj index 4507f4f65..dd71e9fb9 100644 --- a/backend/test/app/services_projects_test.clj +++ b/backend/test/app_tests/test_rpc_project.clj @@ -4,12 +4,12 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-projects-test +(ns app-tests.test-rpc-project (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.http :as http] - [app.test-helpers :as th] [app.util.time :as dt] [clojure.test :as t])) diff --git a/backend/test/app/services_teams_test.clj b/backend/test/app_tests/test_rpc_team.clj similarity index 99% rename from backend/test/app/services_teams_test.clj rename to backend/test/app_tests/test_rpc_team.clj index 650fda6b6..930269817 100644 --- a/backend/test/app/services_teams_test.clj +++ b/backend/test/app_tests/test_rpc_team.clj @@ -4,13 +4,13 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-teams-test +(ns app-tests.test-rpc-team (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] [app.http :as http] [app.storage :as sto] - [app.test-helpers :as th] [app.tokens :as tokens] [app.util.time :as dt] [clojure.test :as t] diff --git a/backend/test/app/services_viewer_test.clj b/backend/test/app_tests/test_rpc_viewer.clj similarity index 98% rename from backend/test/app/services_viewer_test.clj rename to backend/test/app_tests/test_rpc_viewer.clj index 688e09597..5e8ef519a 100644 --- a/backend/test/app/services_viewer_test.clj +++ b/backend/test/app_tests/test_rpc_viewer.clj @@ -4,11 +4,11 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.services-viewer-test +(ns app-tests.test-rpc-viewer (:require + [app-tests.test-helpers :as th] [app.common.uuid :as uuid] [app.db :as db] - [app.test-helpers :as th] [clojure.test :as t] [datoteka.core :as fs])) diff --git a/backend/test/app/storage_test.clj b/backend/test/app_tests/test_storage.clj similarity index 97% rename from backend/test/app/storage_test.clj rename to backend/test/app_tests/test_storage.clj index b619cbda3..3821672da 100644 --- a/backend/test/app/storage_test.clj +++ b/backend/test/app_tests/test_storage.clj @@ -4,13 +4,13 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.storage-test +(ns app-tests.test-storage (:require + [app-tests.test-helpers :as th] [app.common.exceptions :as ex] [app.common.uuid :as uuid] [app.db :as db] [app.storage :as sto] - [app.test-helpers :as th] [app.util.time :as dt] [clojure.test :as t] [cuerdas.core :as str] @@ -126,7 +126,7 @@ :is-shared false}) mfile {:filename "sample.jpg" - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg" :size 312043} @@ -196,12 +196,12 @@ :project-id proj-id :is-shared false}) - ttfdata (-> (io/resource "app/test_files/font-1.ttf") + ttfdata (-> (io/resource "app_tests/test_files/font-1.ttf") io/input-stream io/read-as-bytes) mfile {:filename "sample.jpg" - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg" :size 312043} @@ -267,7 +267,7 @@ :project-id (:default-project-id prof) :is-shared false}) mfile {:filename "sample.jpg" - :path (th/tempfile "app/test_files/sample.jpg") + :path (th/tempfile "app_tests/test_files/sample.jpg") :mtype "image/jpeg" :size 312043} diff --git a/backend/test/app/tasks_telemetry_test.clj b/backend/test/app_tests/test_telemetry_task.clj similarity index 96% rename from backend/test/app/tasks_telemetry_test.clj rename to backend/test/app_tests/test_telemetry_task.clj index 89f4007d5..9a233e163 100644 --- a/backend/test/app/tasks_telemetry_test.clj +++ b/backend/test/app_tests/test_telemetry_task.clj @@ -4,11 +4,11 @@ ;; ;; Copyright (c) KALEIDOS INC -(ns app.tasks-telemetry-test +(ns app-tests.test-telemetry-task (:require + [app-tests.test-helpers :as th] [app.db :as db] [app.emails :as emails] - [app.test-helpers :as th] [app.util.time :as dt] [clojure.pprint :refer [pprint]] [clojure.test :as t]