Skip to content

Commit 707394c

Browse files
committed
Extract fixtures into a test-utils namespace
1 parent faaa39e commit 707394c

File tree

1 file changed

+9
-39
lines changed

1 file changed

+9
-39
lines changed

test/rethinkdb/async_test.clj

Lines changed: 9 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,52 +1,22 @@
11
(ns rethinkdb.async-test
22
(:require [clojure.test :refer :all]
3+
[clojure.core.async :as async]
34
[rethinkdb.query :as r]
4-
[clojure.core.async :as async])
5+
[rethinkdb.test-utils :as utils])
56
(:import (clojure.core.async.impl.protocols ReadPort)))
67

7-
(def test-db "cljrethinkdb_test")
8-
(def test-table :pokedex)
9-
10-
(defn ensure-table
11-
"Ensures that an empty table \"table-name\" exists"
12-
[table-name optargs conn]
13-
(if (some #{table-name} (r/run (r/table-list) conn))
14-
(r/run (r/table-drop table-name) conn))
15-
(r/run (r/table-create (r/db test-db) table-name optargs) conn))
16-
17-
(defn ensure-db
18-
"Ensures that an empty database \"db-name\" exists"
19-
[db-name conn]
20-
(if (some #{db-name} (r/run (r/db-list) conn))
21-
(r/run (r/db-drop db-name) conn))
22-
(r/run (r/db-create db-name) conn))
23-
24-
(defn setup-each [test-fn]
25-
(with-open [conn (r/connect :db test-db)]
26-
(-> (r/table test-table)
27-
(r/delete {:durability :soft :return-changes false})
28-
(r/run conn))
29-
(test-fn)))
30-
31-
(defn setup-once [test-fn]
32-
(with-open [conn (r/connect)]
33-
(ensure-db test-db conn)
34-
(ensure-table test-table {:primary-key :national_no} conn)
35-
(test-fn)
36-
(r/run (r/db-drop test-db) conn)))
37-
38-
(use-fixtures :each setup-each)
39-
(use-fixtures :once setup-once)
8+
(use-fixtures :each utils/setup-each)
9+
(use-fixtures :once utils/setup-once)
4010

4111
(deftest always-return-async
4212
(with-open [conn (r/connect :async? true)]
4313
(are [query] (instance? ReadPort (r/run query conn))
4414
(r/db-list)
4515
(-> (r/db :non-existent) (r/table :nope))
46-
(-> (r/db test-db) (r/table test-table) (r/insert {:a 1})))))
16+
(-> (r/db utils/test-db) (r/table utils/test-table) (r/insert {:a 1})))))
4717

4818
(deftest async-results
49-
(let [conn (r/connect :async? true :db test-db)
19+
(let [conn (r/connect :async? true :db utils/test-db)
5020
pokemon [{:national_no 25 :name "Pikachu"}
5121
{:national_no 26 :name "Raichu"}]]
5222
(are [expected query] (= (->> (r/run query conn)
@@ -59,9 +29,9 @@
5929
:replaced 0
6030
:skipped 0
6131
:unchanged 0}]
62-
(-> (r/table test-table)
32+
(-> (r/table utils/test-table)
6333
(r/insert pokemon))
64-
pokemon (-> (r/table test-table))
65-
[pokemon] (-> (r/table test-table) (r/order-by :name))
34+
pokemon (-> (r/table utils/test-table))
35+
[pokemon] (-> (r/table utils/test-table) (r/order-by :name))
6636

6737
)))

0 commit comments

Comments
 (0)