I'm playing with the luminus guestbook app.
I added some logging statements in g.test.db.core.clj
to look at the keys of the data structures. Look at "Expected Keys" and "Actual Keys" below.
(deftest test-messages
(jdbc/with-db-transaction [t-conn db/conn]
(jdbc/db-set-rollback-only! t-conn)
(let [timestamp (java.util.Date.)]
(is (= 1 (db/save-message!
{:name "Bobby"
:message "Hello World!"
:timestamp timestamp}
{:connection t-conn})))
(let [actual (-> (db/get-messages {} {:connection t-conn}))
expected {:name "Bobby"
:message "Hello World!"
:timestamp timestamp}]
(log/info "Expected Keys")
(pprint (keys expected))
(log/info "Actual Keys")
(pprint (keys actual)) ;;<--this is the problem
(is (= actual
expected))))))
The "Expected Keys" print fine, but I get a runtime exception for "Actual Keys":
[2017-03-04 14:31:28,076]Expected Keys (:name :message :timestamp)
[2017-03-04 14:31:28,089]Actual Keys
lein test :only guestbook.test.db.core/test-messages
ERROR in (test-messages) (:) Uncaught exception, not in assertion. expected: nil actual: java.lang.ClassCastException: null at [empty stack trace]
lein test guestbook.test.handler
However, if I do this:
(pprint actual)
I get what I want:
({:id 35,
:name "Bobby",
:message "Hello World!",
:timestamp #inst "2017-03-04T04:31:01.030000000-00:00"})
What is going on? Why can't I print the keys from the data structure returned from the database?
It looks like actual is a list and not a map. Try (-> actual first keys pprint)