Skip to content

Commit b7a4aa2

Browse files
committed
BREAKING: Rename all the remaining dev-local occurrences
1 parent f95574d commit b7a4aa2

File tree

5 files changed

+46
-39
lines changed

5 files changed

+46
-39
lines changed

README.md

Lines changed: 19 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,30 @@
1-
# dev-local-tu
1+
# datomic-local-tu
22

3-
Test utility for Datomic dev-local.
3+
Test utility for Datomic Local.
44

55
```clojure
66
dev-local-tu {:mvn/version "0.3.0"}
77
```
88

9-
## Rationale
9+
## Rationale
1010

11-
Datomic dev-local provides a way to create clean environments useful for testing.
12-
It does not provide a methodology for how to use it.
13-
This library provides an opinionated way to use dev-local in your tests.
11+
Datomic Local provides a way to create clean environments useful for testing.
12+
It does not provide a methodology for how to use it.
13+
This library provides an opinionated way to use `:datomic-local` in your tests.
1414

1515
## Usage
1616

17-
The primary function exposed by the api is `test-env`.
17+
The primary function exposed by the api is `test-env`.
1818
This function returns a test environment.
19-
A test environment will contain a Datomic client, created by dev local, that can be cleaned up by simply calling `.close`.
19+
A test environment will contain a Datomic client, created by Datomic Local,
20+
that can be cleaned up by simply calling `.close`.
2021
A test environment is typically used within a `with-open`.
2122

2223
```clojure
23-
(require '[dev-local-tu.core :as dev-local-tu]
24+
(require '[datomic-local-tu.core :as datomic-local-tu]
2425
'[datomic.client.api :as d])
2526

26-
(with-open [db-env (dev-local-tu/test-env)]
27+
(with-open [db-env (datomic-local-tu/test-env)]
2728
(let [_ (d/create-database (:client db-env) {:db-name "test"})
2829
conn (d/connect (:client db-env) {:db-name "test"})
2930
_ (d/transact conn {:tx-data [{:db/ident ::name
@@ -37,19 +38,24 @@ A test environment is typically used within a `with-open`.
3738
=> #:example1{:name "hi"}
3839
```
3940

40-
If you would prefer to manage the lifecycle, use `new-env` to generate a new, random system and `cleanup-env!` to remove the associated resources.
41+
If you would prefer to manage the lifecycle, use `new-env` to generate a new,
42+
random system and `cleanup-env!` to remove the associated resources.
4143

42-
Alternatively, you can use test-env with fixtures.
44+
Alternatively, you can use test-env with fixtures.
4345
See `examples/example_fixture.clj` for the complete example.
4446

4547
```clojure
4648
(def ^:dynamic *client* nil)
4749

4850
(defn client-fixture
4951
[f]
50-
(with-open [db-env (dev-local-tu/test-env)]
52+
(with-open [db-env (datomic-local-tu/test-env)]
5153
(binding [*client* (:client db-env)]
5254
(f))))
5355

5456
(use-fixtures :each client-fixture)
5557
```
58+
59+
## Author
60+
61+
Kenny Williams @kennyjwilli

examples/example1.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22
(:require
33
[clojure.test :refer :all]
44
[datomic.client.api :as d]
5-
[dev-local-tu.core :as dev-local-tu]))
5+
[datomic-local-tu.core :as datomic-local-tu]))
66

77
(deftest test1
8-
(with-open [db-env (dev-local-tu/test-env)]
8+
(with-open [db-env (datomic-local-tu/test-env)]
99
(let [_ (d/create-database (:client db-env) {:db-name "test"})
1010
conn (d/connect (:client db-env) {:db-name "test"})
1111
_ (d/transact conn {:tx-data [{:db/ident ::name
@@ -16,4 +16,4 @@
1616
(is (= {::name "hi"}
1717
(d/pull (d/db conn)
1818
[::name]
19-
(get tempids "a")))))))
19+
(get tempids "a")))))))

examples/example_fixture.clj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,13 @@
22
(:require
33
[clojure.test :refer :all]
44
[datomic.client.api :as d]
5-
[dev-local-tu.core :as dev-local-tu]))
5+
[datomic-local-tu.core :as datomic-local-tu]))
66

77
(def ^:dynamic *client* nil)
88

99
(defn client-fixture
1010
[f]
11-
(with-open [db-env (dev-local-tu/test-env)]
11+
(with-open [db-env (datomic-local-tu/test-env)]
1212
(binding [*client* (:client db-env)]
1313
(f))))
1414

@@ -25,4 +25,4 @@
2525
(is (= {::name "hi"}
2626
(d/pull (d/db conn)
2727
[::name]
28-
(get tempids "a"))))))
28+
(get tempids "a"))))))
Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,41 +1,42 @@
1-
(ns dev-local-tu.core
1+
(ns datomic-local-tu.core
2+
"Test utility for Datomic Local"
23
(:require
34
[clojure.string :as str]
45
[datomic.client.api :as d]
56
[datomic.local]
67
[clojure.java.io :as io]
7-
[dev-local-tu.internal.impl :as impl])
8+
[datomic-local-tu.internal.impl :as impl])
89
(:import (java.io Closeable File)))
910

1011
(defn gen-name!
1112
[prefix]
1213
(str prefix "-" (impl/rand-str! 7)))
1314

14-
(def default-datomic-dev-local-storage-dir
15+
(def default-datomic-local-storage-dir
1516
(.getAbsolutePath (io/file (System/getProperty "user.home") ".datomic" "data")))
1617

17-
(defn dev-local-directory
18+
(defn datomic-local-dir
1819
^File [{:keys [system-name db-name storage-dir]
19-
:or {storage-dir default-datomic-dev-local-storage-dir}}]
20+
:or {storage-dir default-datomic-local-storage-dir}}]
2021
(let [file-args (cond-> [storage-dir]
21-
system-name (conj system-name)
22-
db-name (conj db-name))]
22+
system-name (conj system-name)
23+
db-name (conj db-name))]
2324
(apply io/file file-args)))
2425

2526
(defn -new-env-map
2627
[{:keys [prefix system storage-dir]
27-
:or {prefix "dev-local"}}]
28+
:or {prefix "datomic-local"}}]
2829
(let [system (or system (gen-name! prefix))
2930
storage-dir (if (or
3031
(= storage-dir :mem)
3132
(and storage-dir
32-
(str/starts-with? storage-dir "/")))
33+
(str/starts-with? storage-dir "/")))
3334
storage-dir
3435
(.getAbsolutePath
35-
(dev-local-directory
36+
(datomic-local-dir
3637
(cond-> {}
37-
storage-dir
38-
(assoc ::storage-dir storage-dir)))))
38+
storage-dir
39+
(assoc ::storage-dir storage-dir)))))
3940
client-map {:server-type :datomic-local
4041
:system system
4142
:storage-dir storage-dir}]
@@ -44,13 +45,13 @@
4445
:system system
4546
:storage-dir storage-dir}))
4647

47-
(defn delete-dev-local-system!
48-
"Deletes a :dev-local system's data. Always returns true. Throws on failure."
48+
(defn delete-datomic-local-system!
49+
"Deletes a `:datomic-local` system's data. Always returns true. Throws on failure."
4950
([system-name]
50-
(delete-dev-local-system! system-name default-datomic-dev-local-storage-dir))
51+
(delete-datomic-local-system! system-name default-datomic-local-storage-dir))
5152
([system-name storage-dir]
52-
(let [f (dev-local-directory {:system-name system-name
53-
:storage-dir storage-dir})]
53+
(let [f (datomic-local-dir {:system-name system-name
54+
:storage-dir storage-dir})]
5455
(when (.exists ^File f)
5556
(impl/delete-directory! f))
5657
true)))
@@ -72,7 +73,7 @@
7273
[{:keys [client system client-map]}]
7374
(release-dbs client system)
7475
(when (string? (:storage-dir client-map))
75-
(delete-dev-local-system! system)))
76+
(delete-datomic-local-system! system)))
7677

7778
(defrecord TestEnv [system client]
7879
Closeable
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
(ns dev-local-tu.internal.impl
1+
(ns datomic-local-tu.internal.impl
22
(:require [clojure.java.io :as io])
33
(:import (java.nio.file Files SimpleFileVisitor FileVisitResult)
44
(java.security SecureRandom)
@@ -22,4 +22,4 @@
2222
[length]
2323
(let [buffer (byte-array length)
2424
_ (.nextBytes random buffer)]
25-
(.encodeToString encoder buffer))))
25+
(.encodeToString encoder buffer))))

0 commit comments

Comments
 (0)