Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add initial test and setup fig.sh for redis in docker #8

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)))))))