Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Convert to integrant and implement user resolver tests.
  • Loading branch information
codonnell committed Apr 5, 2020
1 parent 20b7a91 commit b75318c
Show file tree
Hide file tree
Showing 19 changed files with 272 additions and 113 deletions.
5 changes: 4 additions & 1 deletion .dir-locals.el
@@ -1,2 +1,5 @@
((nil . ((fill-column . 70)
(column-enforce-column . 70))))
(column-enforce-column . 70)
(cider-default-cljs-repl . shadow)
(cider-shadow-default-options . ":dev")
(cider-shadow-cljs-global-options . "-A:dev:test"))))
14 changes: 14 additions & 0 deletions Makefile
@@ -0,0 +1,14 @@
.PHONY: test test-up test-down

test:
POSTGRES_PORT=15433 docker-compose -p mygiftlist-blog-test up -d
scripts/migrate-local.sh mygiftlist-blog-test_default
clojure -A:test:run-tests
docker-compose -p mygiftlist-blog-test down

test-up:
POSTGRES_PORT=15433 docker-compose -p mygiftlist-blog-test up -d
scripts/migrate-local.sh mygiftlist-blog-test_default

test-down:
docker-compose -p mygiftlist-blog-test down
23 changes: 20 additions & 3 deletions README.md
Expand Up @@ -36,9 +36,26 @@ There's also a convenience script available at `./scripts/psql` to open up a psq

To run this application in development mode, start a shadow-cljs server with
```bash
npx shadow-cljs -d nrepl:0.7.0 -d cider/piggieback:0.4.2 -d refactor-nrepl:2.5.0 -d cider/cider-nrepl:0.25.0-SNAPSHOT server
npx shadow-cljs -A:dev:test -d nrepl:0.7.0 -d cider/piggieback:0.4.2 -d refactor-nrepl:2.5.0 -d cider/cider-nrepl:0.25.0-SNAPSHOT server
```

With this running, you can control compilation by accessing the shadow-cljs server at http://localhost:9630. In addition, this command will start up an nrepl server, which you should connect to with your preferred REPL. Alternatively, CIDER users can run `cider-jack-in-clj&cljs`.
With this running, you can control compilation by accessing the shadow-cljs server at http://localhost:9630. In addition, this command will start up an nrepl server, which you should connect to with your preferred REPL. Alternatively, CIDER users can run `cider-jack-in-clj&cljs` and choose `shadow-cljs`.

In your clojure repl, make sure you are in the `user` namespace and evaluate `(start)`. This will start our web server. With the web server running, you can access the application at http://localhost:3000.
In your clojure repl, make sure you are in the `user` namespace and evaluate `(go)`. This will start our web server. With the web server running, you can access the application at http://localhost:3000.

## Tests

To run the test suite from the command line, run
```bash
make test
```

In order to run tests from the repl, you need to start up the test database. You can do this with
```bash
make test-up
```

With the test database up and running, you should be able to run tests. You can shut down the test database with
```bash
make test-down
```
21 changes: 13 additions & 8 deletions deps.edn
@@ -1,30 +1,35 @@
{:paths ["src" "resources"]
:deps {com.fulcrologic/fulcro {:mvn/version "3.1.22"}
:deps {com.fulcrologic/fulcro {:mvn/version "3.2.0"}
com.wsscode/pathom {:mvn/version "2.2.31"}
edn-query-language/eql {:mvn/version "0.0.9"}
com.taoensso/timbre {:mvn/version "4.10.0"}
com.cognitect/transit-clj {:mvn/version "1.0.324"}
ring/ring-core {:mvn/version "1.8.0"}
ring/ring-defaults {:mvn/version "0.3.2"}
bk/ring-gzip {:mvn/version "0.3.0"}
mount {:mvn/version "0.1.16"}
integrant {:mvn/version "0.8.0"}
seancorfield/next.jdbc {:mvn/version "1.0.409"}
honeysql {:mvn/version "0.9.10"}
nilenso/honeysql-postgres {:mvn/version "0.2.6"}
org.postgresql/postgresql {:mvn/version "42.2.11"}
org.postgresql/postgresql {:mvn/version "42.2.12"}
hikari-cp {:mvn/version "2.11.0"}
aero {:mvn/version "1.1.6"}
http-kit {:mvn/version "2.4.0-alpha6"}}
:aliases {:dev {:extra-paths ["dev"]
:jvm-opts ["-Dtrace"]
:extra-deps {org.clojure/tools.namespace {:mvn/version "0.3.1"}
:extra-deps {org.clojure/tools.namespace {:mvn/version "1.0.0"}
org.clojure/clojurescript {:mvn/version "1.10.597"}
com.fulcrologic/semantic-ui-wrapper {:mvn/version "1.0.0"}
org.clojure/core.async {:mvn/version "1.0.567"}
org.clojure/core.async {:mvn/version "1.1.587"}
com.cognitect/transit-cljs {:mvn/version "0.8.256"}
com.wsscode/async {:mvn/version "1.0.2"}
com.wsscode/async {:mvn/version "1.0.3"}
clj-commons/pushy {:mvn/version "0.3.10"}
thheller/shadow-cljs {:mvn/version "2.8.83"}
binaryage/devtools {:mvn/version "0.9.10"}}}
thheller/shadow-cljs {:mvn/version "2.8.94"}
binaryage/devtools {:mvn/version "1.0.0"}
integrant/repl {:mvn/version "0.3.1"}}}
:test {:extra-paths ["test"]
:extra-deps {com.cognitect/test-runner {:git/url "https://github.com/cognitect-labs/test-runner.git"
:sha "209b64504cb3bd3b99ecfec7937b358a879f55c1"}}}
:run-tests {:main-opts ["-m" "cognitect.test-runner"]}
:outdated {:extra-deps {olical/depot {:mvn/version "1.8.4"}}
:main-opts ["-m" "depot.outdated.main"]}}}
1 change: 1 addition & 0 deletions dev/resources/dev.edn
@@ -0,0 +1 @@
{:rocks.mygiftlist.config/config {:rocks.mygiftlist.config/profile :dev}}
1 change: 1 addition & 0 deletions dev/resources/test.edn
@@ -0,0 +1 @@
{:rocks.mygiftlist.config/config {:rocks.mygiftlist.config/profile :test}}
40 changes: 18 additions & 22 deletions dev/user.clj
@@ -1,27 +1,23 @@
(ns user
(:require
rocks.mygiftlist.server
[clojure.tools.namespace.repl :as tools-ns :refer [set-refresh-dirs]]
[mount.core :as mount]))
rocks.mygiftlist.parser
rocks.mygiftlist.db
rocks.mygiftlist.config
[integrant.core :as ig]
[integrant.repl :refer [clear go halt prep init reset reset-all]]
[integrant.repl.state :refer [system]]
[clojure.java.io :as io]))

;; ==================== REPL TOOLING ====================
(integrant.repl/set-prep!
(fn []
(merge
(ig/read-string (slurp (io/resource "system.edn")))
(ig/read-string (slurp (io/resource "resources/dev.edn"))))))

(set-refresh-dirs "src" "dev")

(defn start
"Start the web server"
[] (mount/start))

(defn stop
"Stop the web server"
[] (mount/stop))

(defn restart
"Stop, reload code, and restart the server. If there is a compile error, use:
```
(tools-ns/refresh)
```
to recompile, and then use `start` once things are good."
[]
(stop)
(tools-ns/refresh :after 'user/start))
(comment
system
(go)
(reset)
(halt)
)
2 changes: 1 addition & 1 deletion docker-compose.yaml
Expand Up @@ -6,7 +6,7 @@ services:
environment:
POSTGRES_PASSWORD: password
ports:
- "15432:5432"
- "${POSTGRES_PORT:-15432}:5432"
volumes:
- db_data:/var/lib/postgresql/data
volumes:
Expand Down
70 changes: 23 additions & 47 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 4 additions & 5 deletions package.json
Expand Up @@ -4,12 +4,11 @@
"description": "",
"private": true,
"devDependencies": {
"@auth0/auth0-spa-js": "^1.6.4",
"minimist": "^1.2.2",
"react": "^16.13.0",
"react-dom": "^16.13.0",
"@auth0/auth0-spa-js": "^1.6.5",
"react": "^16.13.1",
"react-dom": "^16.13.1",
"semantic-ui-react": "^0.88.2",
"shadow-cljs": "^2.8.83"
"shadow-cljs": "^2.8.94"
},
"author": "Chris O'Donnell",
"license": "MIT"
Expand Down
8 changes: 6 additions & 2 deletions resources/config.edn
@@ -1,7 +1,11 @@
{:database-spec {:username #or [#env POSTGRES_USER "postgres"]
:password #or [#env POSTGRES_PASSWORD "password"]
:server-name #or [#env POSTGRES_HOSTNAME "localhost"]
:port-number #long #or [#env POSTGRES_PORT 15432]
:port-number #long #profile {:dev 15432
:test 15433
:prod #env POSTGRES_PORT}
:database-name #or [#env POSTGRES_DB "postgres"]
:sslmode #or [#env POSTGRES_SSLMODE "disable"]}
:port #long #or [#env PORT 3000]}
:port #long #profile {:dev 3000
:test 3001
:prod #env PORT}}
12 changes: 12 additions & 0 deletions resources/system.edn
@@ -0,0 +1,12 @@
{:rocks.mygiftlist.config/config
{:rocks.mygiftlist.config/profile :prod}

:rocks.mygiftlist.db/pool
{:rocks.mygiftlist.config/config #ig/ref :rocks.mygiftlist.config/config}

:rocks.mygiftlist.parser/parser
{:rocks.mygiftlist.db/pool #ig/ref :rocks.mygiftlist.db/pool}

:rocks.mygiftlist.server/server
{:rocks.mygiftlist.parser/parser #ig/ref :rocks.mygiftlist.parser/parser
:rocks.mygiftlist.config/config #ig/ref :rocks.mygiftlist.config/config}}
2 changes: 1 addition & 1 deletion scripts/migrate-local.sh
Expand Up @@ -7,7 +7,7 @@ docker build \
-t cpodonnell/mygiftlist-blog:migrate-local .

docker run --rm \
--network mygiftlist-blog_default \
--network "${1:-mygiftlist-blog_default}" \
-e POSTGRES_USER=postgres \
-e POSTGRES_PASSWORD=password \
-e POSTGRES_HOSTNAME=postgres \
Expand Down
14 changes: 10 additions & 4 deletions src/rocks/mygiftlist/config.clj
@@ -1,9 +1,15 @@
(ns rocks.mygiftlist.config
(:require [clojure.java.io :as io]
(:require [integrant.core :as ig]
[clojure.java.io :as io]
[aero.core :as aero]))

(def ^:private config (aero/read-config (io/resource "config.edn")))
(defmethod ig/init-key ::config
[_ {::keys [profile]}]
(aero/read-config (io/resource "config.edn")
{:profile profile}))

(def database-spec (:database-spec config))
(defn database-spec [config]
(:database-spec config))

(def port (:port config))
(defn port [config]
(:port config))
16 changes: 10 additions & 6 deletions src/rocks/mygiftlist/db.clj
@@ -1,6 +1,6 @@
(ns rocks.mygiftlist.db
(:require [rocks.mygiftlist.config :as config]
[mount.core :refer [defstate]]
[integrant.core :as ig]
[hikari-cp.core :as pool]
[next.jdbc :as jdbc]
[next.jdbc.result-set :as result-set]
Expand All @@ -9,7 +9,7 @@
[honeysql.core :as sql]
honeysql-postgres.format))

(def datasource-options
(defn datasource-options [database-spec]
(merge {:auto-commit true
:read-only false
:connection-timeout 30000
Expand All @@ -21,11 +21,15 @@
:pool-name "db-pool"
:adapter "postgresql"
:register-mbeans false}
config/database-spec))
database-spec))

(defstate pool
:start (pool/make-datasource datasource-options)
:stop (pool/close-datasource pool))
(defmethod ig/init-key ::pool
[_ {::config/keys [config]}]
(pool/make-datasource (datasource-options (config/database-spec config))))

(defmethod ig/halt-key! ::pool
[_ pool]
(pool/close-datasource pool))

(defn- qualify
"Given a kebab-case database table name, returns the namespace that
Expand Down

0 comments on commit b75318c

Please sign in to comment.