diff --git a/bin/run_test_script b/bin/run_test_script new file mode 100755 index 0000000..6df2ce1 --- /dev/null +++ b/bin/run_test_script @@ -0,0 +1,15 @@ +#!/bin/bash +# usage: run_test_script test_name output_file +# +# See http://mongodb.onconfluence.com/display/DOCS/Using+the+Framework+(for+Driver+Developers) + +HERE=`dirname $0` + +begintime=`date` +ruby $HERE/../tests/mongo-qa/$1 +exitval=$? +endtime=`date` + +echo "begintime:$begintime" >> $2 +echo "endtime:$endtime" >> $2 +echo "exit_code:$exitval" >> $2 diff --git a/bin/validate b/bin/validate deleted file mode 100755 index 2d25548..0000000 --- a/bin/validate +++ /dev/null @@ -1,51 +0,0 @@ -#!/usr/bin/env ruby -# -# usage: validate somefile.xson somefile.bson -# -# Reads somefile.xson file (XML that describes a Mongo-type document), -# converts it into a Ruby OrderedHash, runs that through the BSON -# serialization code, and writes the BSON bytes to somefile.bson. -# -# In addition, this script takes the generated BSON, reads it in then writes -# it back out to a temp BSON file. If they are different, we report that error -# to STDOUT. -# -# This script is used by the mongo-qa project -# (http://github.com/mongodb/mongo-qa). - -$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '..', 'lib') -require 'mongo' -require 'mongo/util/xml_to_ruby' - -if ARGV.length < 2 - $stderr.puts "usage: validate somefile.xson somefile.bson" - exit 1 -end - -# Translate the .xson XML into a Ruby object, turn that object into BSON, and -# write the BSON to the file as requested. -obj = File.open(ARGV[0], 'rb') { |f| XMLToRuby.new.xml_to_ruby(f) } -bson = BSON.new.serialize(obj).to_a -File.open(ARGV[1], 'wb') { |f| bson.each { |b| f.putc(b) } } - -# Now the additional testing. Read the generated BSON back in, deserialize it, -# and re-serialize the results. Compare that BSON with the BSON from the file -# we output. -bson = File.open(ARGV[1], 'rb') { |f| f.read } -bson = if RUBY_VERSION >= '1.9' - bson.bytes.to_a - else - bson.split(//).collect { |c| c[0] } - end - -# Turn the Ruby object into BSON bytes and compare with the BSON bytes from -# the file. -bson_from_ruby = BSON.new.serialize(obj).to_a - -if bson.length != bson_from_ruby.length - $stderr.puts "error: round-trip BSON lengths differ when testing #{ARGV[0]}" - exit 1 -elsif bson != bson_from_ruby - $stderr.puts "error: round-trip BSON contents differ when testing #{ARGV[0]}" - exit 1 -end diff --git a/tests/mongo-qa/_common.rb b/tests/mongo-qa/_common.rb new file mode 100644 index 0000000..2760de5 --- /dev/null +++ b/tests/mongo-qa/_common.rb @@ -0,0 +1,8 @@ +$LOAD_PATH[0,0] = File.join(File.dirname(__FILE__), '../..', 'lib') +require 'mongo' + +DEFAULT_HOST = '127.0.0.1' +DEFAULT_PORT = 27017 +DEFAULT_DB = 'driver_test_framework' + +include XGen::Mongo::Driver diff --git a/tests/mongo-qa/capped b/tests/mongo-qa/capped new file mode 100755 index 0000000..31ef1b7 --- /dev/null +++ b/tests/mongo-qa/capped @@ -0,0 +1,17 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +db.create_collection('capped1', :capped => true, :size => 500) +coll = db.collection('capped1') +coll.insert('x' => 1) +coll.insert('x' => 2) + +db.create_collection('capped2', :capped => true, :size => 1000, :max => 11) +coll = db.collection('capped2') +str = '' +100.times { + coll.insert('dashes' => str) + str << '-' +} diff --git a/tests/mongo-qa/circular b/tests/mongo-qa/circular new file mode 100755 index 0000000..a8c0d10 --- /dev/null +++ b/tests/mongo-qa/circular @@ -0,0 +1,16 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +colla = db.collection('a') +collb = db.collection('b') +collc = db.collection('c') + +colla.insert('c' => 'b') +collb.insert('c' => 1) + +x_id = ObjectID.new +x_dbref = DBRef.new(nil, 'thiz', db, 'c', x_id) +x = {'_id' => x_id, 'that' => 2, 'thiz' => x_dbref} +collc.insert(x) diff --git a/tests/mongo-qa/count1 b/tests/mongo-qa/count1 new file mode 100755 index 0000000..745b941 --- /dev/null +++ b/tests/mongo-qa/count1 @@ -0,0 +1,10 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +puts db.collection('test1').count +puts db.collection('test2').count +puts db.collection('test3').count('i' => 'a') +puts db.collection('test3').count('i' => 3) +puts db.collection('test3').count({'i' => {'$gte' => 67}}) diff --git a/tests/mongo-qa/find b/tests/mongo-qa/find new file mode 100755 index 0000000..0ff7f4b --- /dev/null +++ b/tests/mongo-qa/find @@ -0,0 +1,6 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +db.collection('test').insert('a' => 2) diff --git a/tests/mongo-qa/remove b/tests/mongo-qa/remove new file mode 100755 index 0000000..7241c8d --- /dev/null +++ b/tests/mongo-qa/remove @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +db.collection('remove1').clear +db.collection('remove2').remove('a' => 3) diff --git a/tests/mongo-qa/test1 b/tests/mongo-qa/test1 new file mode 100755 index 0000000..a0b0dda --- /dev/null +++ b/tests/mongo-qa/test1 @@ -0,0 +1,7 @@ +#!/usr/bin/env ruby + +require File.join(File.dirname(__FILE__), '_common.rb') +db = Mongo.new(DEFAULT_HOST, DEFAULT_PORT).db(DEFAULT_DB) + +coll = db.collection('part1') +100.times { |i| coll.insert('x' => i) }