Thursday, February 25, 2016

Interesting use case example for `are` macro in Clojure test

I found an interesting use case for are in Clojure test.

You might have ever written a test for your data conversion logic. E.g.
  • Converting data pulled from third-party web service into your internal schema.
  • Converting data fetched from your database to more mobile friendly schema before sending out.
This is an example snippet of test for such a scenario.

convert-test1 shows the style I had been writing until recently. convert-test2 shows how using are making the test better.

Pros:
  • No more duplication of field values between input and output.
  • No more duplication between output schema and code under test schema.
  • It can be use as a document showing clearly how each individual field is mapped.
Cons:
An error message in convert-test1 is better. It shows clearly which field is wrong while convert-test2 throw out the whole problematic result data.

Updated: I have retested, are does report problem for an individual case as well.

Wednesday, February 10, 2016

[ClojureScript] Run all tests in multiple namespaces in REPL

From ClojureScript wiki, it says
If you have many test namespaces it's idiomatic to create a test runner namespace which imports all of your test namespaces and then invokes run-tests
I personally couldn't get it to work. Though I have managed to make run-all-tests works. This is an example

(ns myns.test.runner
  (:require [cljs.test :refer-macros [run-all-tests]]
            [myns.test.ns1]
            [myns.test.ns2]))

(run-all-tests #"myns.test.*")

[DataScript][Solved] Error: Expected number or lookup ref for entity id, got

When you are trying to use Map specification of Datomic's pull api and you got this error
Error: Expected number or lookup ref for entity id, got ....
This happens because you didn't specify schema for that data attribute. Schema is optional on DataScript but it is required in this case. Add this line to your database, the issue should be fixed
{:your-attribute1 {:db/valueType :db.type/ref}
 :your-attribute2 {:db/valueType :db.type/ref}}

Collectd PostgreSQL Plugin

I couldn't find this link when searching with google https://www.collectd.org/documentation/manpages/collectd.conf.html#plugin-postgresql