From c6e0efcd8b0d8f0db4246a3e68c57f22818cadaa Mon Sep 17 00:00:00 2001 From: Rick Moynihan Date: Wed, 31 Jan 2018 15:41:30 +0000 Subject: [PATCH] Change fixture loader to DROP ALL before running test. One of our tests was somehow not cleaning up after itself. Switching the order to drop before a test runs makes things more debuggable (and also fixed the error). --- test/drafter/feature/draftset/create_test.clj | 11 ++++++----- test/drafter/fixture_data.clj | 12 ++++++++---- 2 files changed, 14 insertions(+), 9 deletions(-) diff --git a/test/drafter/feature/draftset/create_test.clj b/test/drafter/feature/draftset/create_test.clj index e9d34b5be..0cf16f0ab 100644 --- a/test/drafter/feature/draftset/create_test.clj +++ b/test/drafter/feature/draftset/create_test.clj @@ -34,8 +34,6 @@ (defn assert-is-see-other-response [response] (tc/assert-schema see-other-response-schema response)) - - (defn valid-swagger-response? "Applies handler to request and validates the response against the swagger spec for the requested route. @@ -54,18 +52,21 @@ ([user display-name description] (tc/with-identity user {:uri "/v1/draftsets" :request-method :post :params {:display-name display-name :description description}}))) -(tc/deftest-system create-draftset-without-title-or-description +(tc/deftest-system-with-keys create-draftset-without-title-or-description + [:drafter.fixture-data/loader :drafter.feature.draftset.create/handler] [{handler :drafter.feature.draftset.create/handler} "test-system.edn"] (let [request (tc/with-identity test-editor {:uri "/v1/draftsets" :request-method :post}) response (valid-swagger-response? handler request)] (assert-is-see-other-response response))) -(tc/deftest-system create-draftset-with-title-and-without-description +(tc/deftest-system-with-keys create-draftset-with-title-and-without-description + [:drafter.fixture-data/loader :drafter.feature.draftset.create/handler] [{handler :drafter.feature.draftset.create/handler} "test-system.edn"] (let [response (valid-swagger-response? handler (create-draftset-request test-editor "Test Title!"))] (assert-is-see-other-response response))) -(tc/deftest-system create-draftset-with-title-and-description +(tc/deftest-system-with-keys create-draftset-with-title-and-description + [:drafter.fixture-data/loader :drafter.feature.draftset.create/handler] [{handler :drafter.feature.draftset.create/handler} "test-system.edn"] (let [response (valid-swagger-response? handler (create-draftset-request test-editor "Test title" "Test description"))] (assert-is-see-other-response response))) diff --git a/test/drafter/fixture_data.clj b/test/drafter/fixture_data.clj index 68dceaf7a..69c4c38ad 100644 --- a/test/drafter/fixture_data.clj +++ b/test/drafter/fixture_data.clj @@ -5,14 +5,20 @@ [grafter.rdf.protocols :as pr] [clojure.java.io :as io] [integrant.core :as ig] - [clojure.spec.alpha :as s]) + [clojure.spec.alpha :as s] + [clojure.tools.logging :as log]) (:import org.eclipse.rdf4j.repository.Repository)) +(defn drop-all! [repo] + (log/debug "Tearing down fixtures") + (with-open [conn (repo/->connection repo)] + (pr/update! conn "DROP ALL ;"))) (defn load-fixture! [{:keys [repo fixtures format] :as opts}] (with-open [conn (repo/->connection repo)] (doseq [res-path fixtures] (rdf/add conn (rdf/statements res-path :format format)))) + (log/debug "Loaded fixtures" fixtures) (assoc opts :repo repo)) (s/def ::resource #(instance? java.net.URL %)) ;; io/resource creates urls. @@ -25,8 +31,6 @@ (s/keys :req-un [::repo ::fixtures])) (defmethod ig/init-key ::loader [_ opts] + (drop-all! (:repo opts)) (load-fixture! opts)) -(defmethod ig/halt-key! ::loader [_ {:keys [repo] :as sys}] - (with-open [conn (repo/->connection repo)] - (pr/update! conn "DROP ALL ;")))