Skip to content

Commit

Permalink
Change fixture loader to DROP ALL before running test.
Browse files Browse the repository at this point in the history
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).
  • Loading branch information
RickMoynihan committed Jan 31, 2018
1 parent b47b2b2 commit c6e0efc
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 9 deletions.
11 changes: 6 additions & 5 deletions test/drafter/feature/draftset/create_test.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)))
12 changes: 8 additions & 4 deletions test/drafter/fixture_data.clj
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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 ;")))

0 comments on commit c6e0efc

Please sign in to comment.