summaryrefslogtreecommitdiff
path: root/test/test_registry.rb
diff options
context:
space:
mode:
authorMatthias H <apoc@sixserv.org>2014-03-06 16:07:13 +0100
committerMatthias H <apoc@sixserv.org>2014-03-06 16:07:13 +0100
commitbaff61847ea90195e4ef1b063e4da521e02ab9d9 (patch)
tree72e89e8c43fdeafd4bbbcc86592a706c5148d7f5 /test/test_registry.rb
parent15be46dbc99df42db41c247967c9c504008de5cf (diff)
[registry] improved tests, sqlite/tc bugfixes
Diffstat (limited to 'test/test_registry.rb')
-rw-r--r--test/test_registry.rb92
1 files changed, 52 insertions, 40 deletions
diff --git a/test/test_registry.rb b/test/test_registry.rb
index 85383269..c6d68902 100644
--- a/test/test_registry.rb
+++ b/test/test_registry.rb
@@ -7,7 +7,27 @@ require 'rbot/registry'
require 'pp'
require 'tmpdir'
+class FooObj
+ attr_reader :bar
+ def initialize(bar)
+ @bar = bar
+ end
+end
+
module RegistryHashInterfaceTests
+ def test_object
+ @reg['store'] = {
+ :my_obj => FooObj.new(42)
+ }
+
+ assert_equal(42, @reg['store'][:my_obj].bar)
+
+ @reg.close
+ @reg = open(@tempdir)
+
+ assert_equal(42, @reg['store'][:my_obj].bar)
+ end
+
def test_default
@reg.set_default(42)
assert_equal(42, @reg['not-here'])
@@ -232,83 +252,75 @@ module RegistryHashInterfaceTests
end
end
-module TempRegistryTest
- def setup_temp
+module RegistryTestModule
+ def setup
@tempdir = Dir.mktmpdir
+ @reg = open(@tempdir)
end
- def teardown_temp
+ def teardown
+ @reg.close
FileUtils.remove_entry @tempdir
end
def open(path, filename='testcase')
- @@factory ||= Irc::Bot::Registry.new(@format)
- @reg = @@factory.create(path, filename)
+ puts 'open type: ' + @format
+ @registry_class.new(File.join(path, filename))
end
end
class RegistryDBMTest < Test::Unit::TestCase
- include TempRegistryTest
+ include RegistryTestModule
include RegistryHashInterfaceTests
- def setup
- setup_temp
+ def initialize(o)
+ super o
@format = 'dbm'
- @reg = open(@tempdir)
- end
-
- def teardown
- @reg.close
- teardown_temp
+ Irc::Bot::Registry.new(@format)
+ @registry_class = Irc::Bot::Registry::DBMAccessor
end
end
class RegistryTCTest < Test::Unit::TestCase
- include TempRegistryTest
+ include RegistryTestModule
include RegistryHashInterfaceTests
- def setup
- setup_temp
+ def initialize(o)
+ super o
@format = 'tc'
- @reg = open(@tempdir)
- end
-
- def teardown
- @reg.close
- teardown_temp
+ Irc::Bot::Registry.new(@format)
+ @registry_class = Irc::Bot::Registry::TokyoCabinetAccessor
end
end
class RegistryDaybreakTest < Test::Unit::TestCase
- include TempRegistryTest
+ include RegistryTestModule
include RegistryHashInterfaceTests
- def setup
- setup_temp
+ def initialize(o)
+ super o
@format = 'daybreak'
- @reg = open(@tempdir)
- end
-
- def teardown
- @reg.close
- teardown_temp
+ Irc::Bot::Registry.new(@format)
+ @registry_class = Irc::Bot::Registry::DaybreakAccessor
end
end
-
class RegistrySqliteTest < Test::Unit::TestCase
- include TempRegistryTest
+ include RegistryTestModule
include RegistryHashInterfaceTests
- def setup
- setup_temp
+ def initialize(o)
+ super o
@format = 'sqlite'
- @reg = open(@tempdir)
+ Irc::Bot::Registry.new(@format)
+ @registry_class = Irc::Bot::Registry::SqliteAccessor
end
- def teardown
- @reg.close
- teardown_temp
+ def test_duplicate_keys
+ @reg['foo'] = 1
+ @reg['foo'] = 2
+ res = @reg.registry.execute('select key from data')
+ assert res.length == 1
end
end