Reputation: 8480
How can I mock my postgres database for testing?
My application is very simple, but I cannot find a good way to mock my database for tests. In Java I usualy use HSQLDB, but there is a solution in Clojure?
This is my project file.
(defproject account-manager "0.1.0-SNAPSHOT"
:description "Account Manager"
:url "http://example.com/FIXME"
:license {:name "Eclipse Public License"
:url "http://www.eclipse.org/legal/epl-v10.html"}
:dependencies [[org.clojure/clojure "1.8.0"]
[compojure "1.5.2"]
[cheshire "5.7.0"]
[ring/ring-core "1.5.1"]
[ring/ring-json "0.4.0"]
[ring/ring-jetty-adapter "1.5.1"]
[korma "0.4.3"]
[org.clojars.amit/postgresql "8.0.1"]
[com.h2database/h2 "1.4.188"]
[ragtime "0.7.1"]
[environ "1.1.0"]
[org.clojure/data.json "0.2.6"]
[buddy/buddy-hashers "1.2.0"]
[clj-time "0.13.0"]]
:plugins [[lein-ring "0.11.0"]]
:ring {:handler account-manager.handler/app
:nrepl {:start? true
:port 9998}}
:profiles
{:dev {:dependencies [[javax.servlet/servlet-api "2.5"]
[ring-mock "0.1.5"]]
:env {:bank-db "bank_db"
:bank-db-user "bank_db"
:bank-db-pass "-"}}
:test {:env {:bank-db "bank_db"
:bank-db-user "bank_db"
:bank-db-pass "-"}}})
And this is how I'm configuring my database. In the future I will use configuration files.
(ns bank-account-manager.db
(:use korma.db)
(:require [environ.core :refer [env]]))
(defdb db (postgres {:db (get env :bank-db "bank_db")
:user (get env :bank-db-user "bank_db")
:password (get env :bank-db-pass "-")
:host (get env :bank-db-host "localhost")
:port (get env :bank-db-port 5432)}))
There is a good way to mock?
Upvotes: 3
Views: 1158
Reputation: 12983
HSQLDB works with clojure.java.jdbc.
The readme there mentions that Korma is a compatible library with clojure.java.jdbc.
I don't see any reason why you can't continue to use HSQLDB as you would in Java then.
Upvotes: 1