|
1 | 1 | (ns rethinkdb.async-test |
2 | 2 | (:require [clojure.test :refer :all] |
| 3 | + [clojure.core.async :as async] |
3 | 4 | [rethinkdb.query :as r] |
4 | | - [clojure.core.async :as async]) |
| 5 | + [rethinkdb.test-utils :as utils]) |
5 | 6 | (:import (clojure.core.async.impl.protocols ReadPort))) |
6 | 7 |
|
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) |
40 | 10 |
|
41 | 11 | (deftest always-return-async |
42 | 12 | (with-open [conn (r/connect :async? true)] |
43 | 13 | (are [query] (instance? ReadPort (r/run query conn)) |
44 | 14 | (r/db-list) |
45 | 15 | (-> (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}))))) |
47 | 17 |
|
48 | 18 | (deftest async-results |
49 | | - (let [conn (r/connect :async? true :db test-db) |
| 19 | + (let [conn (r/connect :async? true :db utils/test-db) |
50 | 20 | pokemon [{:national_no 25 :name "Pikachu"} |
51 | 21 | {:national_no 26 :name "Raichu"}]] |
52 | 22 | (are [expected query] (= (->> (r/run query conn) |
|
59 | 29 | :replaced 0 |
60 | 30 | :skipped 0 |
61 | 31 | :unchanged 0}] |
62 | | - (-> (r/table test-table) |
| 32 | + (-> (r/table utils/test-table) |
63 | 33 | (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)) |
66 | 36 |
|
67 | 37 | ))) |
0 commit comments