summaryrefslogtreecommitdiff
path: root/lib/vendor/redis/test/scripting_test.rb
diff options
context:
space:
mode:
authorJacob Vosmaer <jacob@gitlab.com>2017-01-02 16:12:06 +0100
committerJacob Vosmaer <jacob@gitlab.com>2017-01-02 16:29:14 +0100
commit3fe9cea03a6384fd8f57f10e172c134ed5c0552d (patch)
tree1148f745058b8885cd07edeb414f5822b05d616f /lib/vendor/redis/test/scripting_test.rb
parenta3712cc18de8283b25c3a8a034ecc8c9b7feca48 (diff)
downloadgitlab-shell-3fe9cea03a6384fd8f57f10e172c134ed5c0552d.tar.gz
Vendor redis_rb from Rubygems, not GitHubredis-full-gem
Also just include the entire gem. Space used is negligible and this way we don't have to think about what to leave in/out. Create a vendor-gem script in Ruby instead of Make.
Diffstat (limited to 'lib/vendor/redis/test/scripting_test.rb')
-rw-r--r--lib/vendor/redis/test/scripting_test.rb78
1 files changed, 78 insertions, 0 deletions
diff --git a/lib/vendor/redis/test/scripting_test.rb b/lib/vendor/redis/test/scripting_test.rb
new file mode 100644
index 0000000..82d0d89
--- /dev/null
+++ b/lib/vendor/redis/test/scripting_test.rb
@@ -0,0 +1,78 @@
+# encoding: UTF-8
+
+require File.expand_path("helper", File.dirname(__FILE__))
+
+class TestScripting < Test::Unit::TestCase
+
+ include Helper::Client
+
+ def to_sha(script)
+ r.script(:load, script)
+ end
+
+ def test_script_exists
+ target_version "2.5.9" do # 2.6-rc1
+ a = to_sha("return 1")
+ b = a.succ
+
+ assert_equal true, r.script(:exists, a)
+ assert_equal false, r.script(:exists, b)
+ assert_equal [true], r.script(:exists, [a])
+ assert_equal [false], r.script(:exists, [b])
+ assert_equal [true, false], r.script(:exists, [a, b])
+ end
+ end
+
+ def test_script_flush
+ target_version "2.5.9" do # 2.6-rc1
+ sha = to_sha("return 1")
+ assert r.script(:exists, sha)
+ assert_equal "OK", r.script(:flush)
+ assert !r.script(:exists, sha)
+ end
+ end
+
+ def test_script_kill
+ target_version "2.5.9" do # 2.6-rc1
+ redis_mock(:script => lambda { |arg| "+#{arg.upcase}" }) do |redis|
+ assert_equal "KILL", redis.script(:kill)
+ end
+ end
+ end
+
+ def test_eval
+ target_version "2.5.9" do # 2.6-rc1
+ assert_equal 0, r.eval("return #KEYS")
+ assert_equal 0, r.eval("return #ARGV")
+ assert_equal ["k1", "k2"], r.eval("return KEYS", ["k1", "k2"])
+ assert_equal ["a1", "a2"], r.eval("return ARGV", [], ["a1", "a2"])
+ end
+ end
+
+ def test_eval_with_options_hash
+ target_version "2.5.9" do # 2.6-rc1
+ assert_equal 0, r.eval("return #KEYS", {})
+ assert_equal 0, r.eval("return #ARGV", {})
+ assert_equal ["k1", "k2"], r.eval("return KEYS", { :keys => ["k1", "k2"] })
+ assert_equal ["a1", "a2"], r.eval("return ARGV", { :argv => ["a1", "a2"] })
+ end
+ end
+
+ def test_evalsha
+ target_version "2.5.9" do # 2.6-rc1
+ assert_equal 0, r.evalsha(to_sha("return #KEYS"))
+ assert_equal 0, r.evalsha(to_sha("return #ARGV"))
+ assert_equal ["k1", "k2"], r.evalsha(to_sha("return KEYS"), ["k1", "k2"])
+ assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), [], ["a1", "a2"])
+ end
+ end
+
+ def test_evalsha_with_options_hash
+ target_version "2.5.9" do # 2.6-rc1
+ assert_equal 0, r.evalsha(to_sha("return #KEYS"), {})
+ assert_equal 0, r.evalsha(to_sha("return #ARGV"), {})
+ assert_equal ["k1", "k2"], r.evalsha(to_sha("return KEYS"), { :keys => ["k1", "k2"] })
+ assert_equal ["a1", "a2"], r.evalsha(to_sha("return ARGV"), { :argv => ["a1", "a2"] })
+ end
+ end
+end