Skip to content

Commit

Permalink
Add initial test and setup fig.sh for redis in docker
Browse files Browse the repository at this point in the history
  • Loading branch information
micha committed Oct 17, 2014
1 parent 8a356cb commit bff9f0c
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
26 changes: 26 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
11 changes: 11 additions & 0 deletions fig.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
redis:
image: orchardup/redis
ports:
- "6379"
lein:
image: pandeiro/lein
links:
- redis:db
volumes:
- .:/project
command: test
19 changes: 19 additions & 0 deletions test/crache/memo_test.clj
Original file line number Diff line number Diff line change
@@ -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)))))))

0 comments on commit bff9f0c

Please sign in to comment.