From bff9f0ca81c0a41c48a8b2dd48b2b409f2002134 Mon Sep 17 00:00:00 2001 From: Micha Niskin Date: Thu, 16 Oct 2014 17:26:49 -0400 Subject: [PATCH] Add initial test and setup fig.sh for redis in docker --- README.md | 26 ++++++++++++++++++++++++++ fig.yml | 11 +++++++++++ test/crache/memo_test.clj | 19 +++++++++++++++++++ 3 files changed, 56 insertions(+) create mode 100644 fig.yml create mode 100644 test/crache/memo_test.clj diff --git a/README.md b/README.md index b32a16c..f13b4c0 100644 --- a/README.md +++ b/README.md @@ -48,6 +48,30 @@ then use `memo-f` like you would use your usual memoized fn: => (memo-f some-input) ;=> some-output ``` +### Tests + +You can run tests in a Docker container via [fig.sh][4]: + +``` +$ fig up +``` + +You can also run tests interactively from a REPL: + +``` +$ fig run lein repl +``` + +```clj +=> (require 'crache.memo-test) +=> (in-ns 'crache.memo-test) +=> (run-tests) +``` + +> **OSX:** Docker on OSX is a little tricky. Use [boot2docker][5] and get +> VirtualBox configured so it can map directories from the host into the +> container. Here is [a pretty good intro to docker on OSX][5]. + ### License ------- Copyright (C) 2014 Homer Strong @@ -57,3 +81,5 @@ Distributed under the Eclipse Public License, the same as Clojure. [1]: https://clojars.org/crache/latest-version.svg?raw=true [2]: https://clojars.org/crache [3]: https://github.com/ptaoussanis/carmine#connections +[4]: http://www.fig.sh/index.html +[5]: http://viget.com/extend/how-to-use-docker-on-os-x-the-missing-guide diff --git a/fig.yml b/fig.yml new file mode 100644 index 0000000..3a60276 --- /dev/null +++ b/fig.yml @@ -0,0 +1,11 @@ +redis: + image: orchardup/redis + ports: + - "6379" +lein: + image: pandeiro/lein + links: + - redis:db + volumes: + - .:/project + command: test \ No newline at end of file diff --git a/test/crache/memo_test.clj b/test/crache/memo_test.clj new file mode 100644 index 0000000..6545691 --- /dev/null +++ b/test/crache/memo_test.clj @@ -0,0 +1,19 @@ +(ns crache.memo-test + (:require [clojure.test :refer :all] + [crache.memo :refer :all])) + +(defonce conn + {:pool {} + :spec {:host (System/getenv "DB_PORT_6379_TCP_ADDR") + :port (Integer/parseInt (System/getenv "DB_PORT_6379_TCP_PORT"))}}) + +(deftest a-test + (testing "Memoize a function" + (let [f (memo-redis (fn [x] (System/currentTimeMillis)) conn (str ::memo) 5) + v (f 10)] + (is (= v (f 10))) + (is (= v (f 10))) + (Thread/sleep 5500) + (let [v' (f 10)] + (is (not= v v')) + (is (= v' (f 10)))))))