1

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?

juan.facorro
  • 9,791
  • 2
  • 33
  • 41
ahoffer
  • 6,347
  • 4
  • 39
  • 68

1 Answers1

0

It looks like actual is a list and not a map. Try (-> actual first keys pprint)

Frank Henard
  • 3,638
  • 3
  • 28
  • 41
  • That's exactly right. How do you figure it out? Could you tell from the log or did you have to clone the project and try it out? – ahoffer Mar 06 '17 at 15:27
  • Glad it worked! I saw the open paren `(` in front of the map in the results from your `(pprint actual)`. I have also done some db work in Clojure, so I probably have encountered that issue before. – Frank Henard Mar 06 '17 at 15:35