about summary refs log tree commit homepage
path: root/test/integration.rb
diff options
context:
space:
mode:
authorEric Wong <normalperson@yhbt.net>2011-11-06 04:39:08 +0000
committerEric Wong <normalperson@yhbt.net>2011-11-06 04:39:08 +0000
commit347c41d307f85b1264fbf1c06fff9e5c8cb2e091 (patch)
treed71bb2f453ffe7166d5aa0a6cd3dd9ec4abe8771 /test/integration.rb
parentc66266416da2e05889ed93997f2c8a7cba216c56 (diff)
downloadmogilefs-client-347c41d307f85b1264fbf1c06fff9e5c8cb2e091.tar.gz
We need to test deprecated behavior to not break
expectations for large, archived files in the future.
Diffstat (limited to 'test/integration.rb')
-rw-r--r--test/integration.rb82
1 files changed, 82 insertions, 0 deletions
diff --git a/test/integration.rb b/test/integration.rb
new file mode 100644
index 0000000..548cb02
--- /dev/null
+++ b/test/integration.rb
@@ -0,0 +1,82 @@
+# -*- encoding: binary -*-
+$stdout.sync = $stderr.sync = true
+require 'test/unit'
+require 'securerandom'
+require 'tempfile'
+require 'digest'
+require 'mogilefs'
+
+class TestMogIntegration < Test::Unit::TestCase
+  def uuid
+    SecureRandom.uuid
+  rescue NoMethodError
+    require "uuid"
+    UUID.generate
+  end
+
+  def setup
+    @to_close = []
+    @trackers = ENV["MOG_TEST_TRACKERS"].split(/,/)
+    now = Time.now
+    domain = "rbmogtest#{now.strftime('%Y%m%d%H%M%S')}.#{uuid}"
+    mogadm!("domain", "add", domain)
+    sleep 4 # wait for monitor to refresh caches
+    @domain = domain
+  end
+
+  def mogadm(*args)
+    x("mogadm", "--trackers=#{@trackers.join(',')}", *args)
+  end
+
+  def x(*cmd)
+    out, err = tmpfile("out"), tmpfile("err")
+    puts cmd.join(' ') if $VERBOSE
+    pid = fork do
+      $stderr.reopen(err.path, "a")
+      $stdout.reopen(out.path, "a")
+      out.close
+      err.close
+      exec(*cmd)
+    end
+    _, status = Process.waitpid2(pid)
+    out.rewind
+    err.rewind
+    [ status, out, err ]
+  end
+
+  def mogadm!(*args)
+    status, out, err = mogadm(*args)
+    assert status.success?, "#{status.inspect} / #{out.read} / #{err.read}"
+    [ status, out, err ]
+  end
+
+  def x!(*cmd)
+    status, out, err = x(*cmd)
+    assert status.success?, "#{status.inspect} / #{out.read} / #{err.read}"
+    [ status, out, err ]
+  end
+
+  def tmpfile(name)
+    tmp = Tempfile.new(name)
+    @to_close << tmp
+    tmp
+  end
+
+  def teardown
+    if defined?(@domain)
+      client = MogileFS::MogileFS.new :hosts => @trackers, :domain => @domain
+      client.each_key("") { |key|
+        p [ :delete, key ] if $VERBOSE
+        client.delete(key)
+      }
+      mogadm!("domain", "delete", @domain)
+    end
+    @to_close.each do |io|
+      io.closed? or io.close
+    end
+  end
+end if ENV["MOG_TEST_TRACKERS"]
+
+class TestMogIntegration
+  warn "MOG_TEST_TRACKERS not defined"
+end unless ENV["MOG_TEST_TRACKERS"]