about summary refs log tree commit homepage
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2012-06-06 02:10:52 +0000
committerEric Wong <normalperson@yhbt.net>2012-06-06 02:10:52 +0000
commitdc0fa66e56a271f4de431ecfc909686d27d73f78 (patch)
tree2a923981c6cd55eb92ff1a1f455d0b2c9e372090
parent112df6360d87356e03a21e8cc4ae24b49eede95f (diff)
downloadmogilefs-client-dc0fa66e56a271f4de431ecfc909686d27d73f78.tar.gz
Specifying an invalid domain will raise
MogileFS::Backend::UnregDomain error instead of merely
returning `false'.  Only checks for keys in the correct
domain (but non-existent keys) return false.
-rw-r--r--lib/mogilefs/mogilefs.rb9
-rw-r--r--test/test_fresh.rb12
2 files changed, 20 insertions, 1 deletions
diff --git a/lib/mogilefs/mogilefs.rb b/lib/mogilefs/mogilefs.rb
index ba8de2c..eccca78 100644
--- a/lib/mogilefs/mogilefs.rb
+++ b/lib/mogilefs/mogilefs.rb
@@ -140,7 +140,14 @@ class MogileFS::MogileFS < MogileFS::Client
   # Returns +true+ if +key+ exists, +false+ if not
   def exist?(key)
     args = { :key => key, :domain => @domain , :ruby_no_raise => true}
-    Hash === @backend.get_paths(args)
+    case rv = @backend.get_paths(args)
+    when Hash
+      true
+    when MogileFS::Backend::UnknownKeyError
+      false
+    else
+      raise rv
+    end
   end
 
   # Get the URIs for +key+ (paths) as URI::HTTP objects
diff --git a/test/test_fresh.rb b/test/test_fresh.rb
index b7882cd..41c30ef 100644
--- a/test/test_fresh.rb
+++ b/test/test_fresh.rb
@@ -14,4 +14,16 @@ class TestMogFresh < Test::Unit::TestCase
       client.list_keys
     end
   end
+
+  def test_invalid_key_exists
+    add_host_device_domain
+    domain = @domain + ".non-existent"
+    client = MogileFS::MogileFS.new :hosts => @hosts, :domain => domain
+    assert_raises(MogileFS::Backend::UnregDomainError) do
+      client.exist?("FOO")
+    end
+
+    client = MogileFS::MogileFS.new :hosts => @hosts, :domain => @domain
+    assert_equal false, client.exist?("non-existent")
+  end
 end