From 0c8d27c0b20a8d995aa7b85f7e003dfe569d6bc1 Mon Sep 17 00:00:00 2001 From: Kyle Banker Date: Tue, 12 Oct 2010 15:41:24 -0400 Subject: [PATCH] minor: added missing tests --- test/cursor_fail_test.rb | 76 ++++++++++++++++++++++++++++++++++++++++ test/support_test.rb | 19 ++++++++++ 2 files changed, 95 insertions(+) create mode 100644 test/cursor_fail_test.rb create mode 100644 test/support_test.rb diff --git a/test/cursor_fail_test.rb b/test/cursor_fail_test.rb new file mode 100644 index 0000000..463c39e --- /dev/null +++ b/test/cursor_fail_test.rb @@ -0,0 +1,76 @@ +require './test/test_helper' +require 'logger' + +class CursorTest < Test::Unit::TestCase + + include Mongo + + @@connection = Connection.new(ENV['MONGO_RUBY_DRIVER_HOST'] || 'localhost', + ENV['MONGO_RUBY_DRIVER_PORT'] || Connection::DEFAULT_PORT) + @@db = @@connection.db(MONGO_TEST_DB) + @@coll = @@db.collection('test') + @@version = @@connection.server_version + + def setup + @@coll.remove + @@coll.insert('a' => 1) # collection not created until it's used + @@coll_full_name = "#{MONGO_TEST_DB}.test" + end + + def test_refill_via_get_more + assert_equal 1, @@coll.count + 1000.times { |i| + assert_equal 1 + i, @@coll.count + @@coll.insert('a' => i) + } + + assert_equal 1001, @@coll.count + count = 0 + @@coll.find.each { |obj| + count += obj['a'] + } + assert_equal 1001, @@coll.count + + # do the same thing again for debugging + assert_equal 1001, @@coll.count + count2 = 0 + @@coll.find.each { |obj| + count2 += obj['a'] + } + assert_equal 1001, @@coll.count + + assert_equal count, count2 + assert_equal 499501, count + end + + def test_refill_via_get_more_alt_coll + coll = @@db.collection('test-alt-coll') + coll.remove + coll.insert('a' => 1) # collection not created until it's used + assert_equal 1, coll.count + + 1000.times { |i| + assert_equal 1 + i, coll.count + coll.insert('a' => i) + } + + assert_equal 1001, coll.count + count = 0 + coll.find.each { |obj| + count += obj['a'] + } + assert_equal 1001, coll.count + + # do the same thing again for debugging + assert_equal 1001, coll.count + count2 = 0 + coll.find.each { |obj| + count2 += obj['a'] + } + assert_equal 1001, coll.count + + assert_equal count, count2 + assert_equal 499501, count + end + +end diff --git a/test/support_test.rb b/test/support_test.rb new file mode 100644 index 0000000..feda438 --- /dev/null +++ b/test/support_test.rb @@ -0,0 +1,19 @@ +require './test/test_helper' + +class SupportTest < Test::Unit::TestCase + include Mongo + + def test_command_response_succeeds + assert Support.ok?('ok' => 1) + assert Support.ok?('ok' => 1.0) + assert Support.ok?('ok' => true) + end + + def test_command_response_fails + assert !Support.ok?('ok' => 0) + assert !Support.ok?('ok' => 0.0) + assert !Support.ok?('ok' => 0.0) + assert !Support.ok?('ok' => 'str') + assert !Support.ok?('ok' => false) + end +end