Last active
August 29, 2015 13:57
-
-
Save andreas/9802796 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
open Core.Std | |
open Async.Std | |
module Ints = struct | |
type t = int | |
let to_string = string_of_int | |
let of_string = int_of_string | |
end | |
module IntCache = Memcached.Make(Ints) | |
let int_suite = TestAsync.( | |
create ~before_all:(fun () -> | |
IntCache.connect "localhost" 11212 | |
) | |
~before:(fun cache -> | |
return cache | |
) | |
~after:(fun cache -> | |
IntCache.flush cache | |
>>= fun _ -> Deferred.unit | |
) | |
~after_all:(fun cache -> | |
IntCache.close cache | |
) | |
|> test "set" (fun cache -> | |
Bool.assert_equal (IntCache.set cache "foo" 1) true | |
) | |
|> test "get" (fun cache -> | |
IntCache.set cache "foo" 1 >>= fun _ -> | |
Int.assert_equal (IntCache.get cache "foo") 1 | |
) | |
|> test "get missing" (fun cache -> | |
assert_error (IntCache.get cache "foo") "Not found" | |
) | |
|> test "flush" (fun cache -> | |
IntCache.set cache "foo" 1 >>= fun _ -> | |
IntCache.flush cache >>= fun _ -> | |
assert_error (IntCache.get cache "foo") "Not found" | |
) | |
|> test "delete" (fun cache -> | |
IntCache.set cache "foo" 1 >>= fun _ -> | |
IntCache.delete cache "foo" >>= fun _ -> | |
assert_error (IntCache.get cache "foo") "Not found" | |
) | |
) | |
let main () = | |
TestAsync.run int_suite >>> fun _ -> | |
Async_unix.Shutdown.shutdown 1 | |
in | |
main (); | |
Scheduler.go () |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Where's the TestAsync module supposed to be coming from?