]> git.netwichtig.de Git - user/henk/code/ruby/rbot.git/commitdiff
test: small changes and fixes to existing tests
authorMatthias Hecker <mail@apoc.cc>
Sun, 29 Mar 2020 10:46:43 +0000 (12:46 +0200)
committerMatthias Hecker <mail@apoc.cc>
Sun, 29 Mar 2020 10:46:43 +0000 (12:46 +0200)
tasks/test.rake [new file with mode: 0644]
test/test_journal.rb
test/test_plugins_threshold.rb
test/test_registry.rb

diff --git a/tasks/test.rake b/tasks/test.rake
new file mode 100644 (file)
index 0000000..b7939f7
--- /dev/null
@@ -0,0 +1,8 @@
+require "rake/testtask.rb"
+require 'rake'
+
+Rake::TestTask.new do |t|
+  t.libs << "test"
+  t.test_files = FileList['test/test_*.rb']
+  t.verbose = true
+end
index f1653c164783e35eb3830228aac58531403f337e..73dbcf42e4ecd80b61933e693e3a537bbb82dbc5 100644 (file)
@@ -1,10 +1,17 @@
 $:.unshift File.join(File.dirname(__FILE__), '../lib')
 
+module Irc
+class Bot
+  module Config
+    @@datadir = File.expand_path(File.dirname($0) + '/../data/rbot')
+    @@coredir = File.expand_path(File.dirname($0) + '/../lib/rbot/core') 
+  end
+end
+end
+
 require 'test/unit'
 require 'rbot/ircbot'
 require 'rbot/journal'
-require 'rbot/journal/postgres.rb'
-require 'rbot/journal/mongo.rb'
 
 require 'benchmark'
 
@@ -364,58 +371,63 @@ module JournalStorageTestMixin
 
 end
 
-if ENV['PG_URI']
-class JournalStoragePostgresTest < Test::Unit::TestCase
+begin
+  require 'rbot/journal/postgres.rb'
+  if ENV['PG_URI']
+  class JournalStoragePostgresTest < Test::Unit::TestCase
 
-  include JournalStorageTestMixin
+    include JournalStorageTestMixin
 
-  def setup
-    @storage = Storage::PostgresStorage.new(
-      uri: ENV['PG_URI'] || 'postgresql://localhost/rbot_journal',
-      drop: true)
-  end
-
-  def test_query_to_sql
-    q = Query.define do
-      id 'foo'
-      id 'bar', 'baz'
-      topic 'log.irc.*'
-      topic 'log.core', 'baz'
-      timestamp from: Time.now, to: Time.now + 60 * 10
-      payload 'action': :privmsg, 'alice': 'bob'
-      payload 'channel': '#rbot'
-      payload 'foo.bar': 'baz'
+    def setup
+      @storage = Storage::PostgresStorage.new(
+        uri: ENV['PG_URI'] || 'postgresql://localhost/rbot_journal',
+        drop: true)
     end
-    sql = @storage.query_to_sql(q)
-    assert_equal("(id = $1 OR id = $2 OR id = $3) AND (topic ILIKE $4 OR topic ILIKE $5 OR topic ILIKE $6) AND (timestamp >= $7 AND timestamp <= $8) AND (payload->>'action' = $9 OR payload->>'alice' = $10 OR payload->>'channel' = $11 OR payload->'foo'->>'bar' = $12)", sql[0])
-    q = Query.define do
-      id 'foo'
-    end
-    assert_equal('(id = $1)', @storage.query_to_sql(q)[0])
-    q = Query.define do
-      topic 'foo.*.bar'
+
+    def test_query_to_sql
+      q = Query.define do
+        id 'foo'
+        id 'bar', 'baz'
+        topic 'log.irc.*'
+        topic 'log.core', 'baz'
+        timestamp from: Time.now, to: Time.now + 60 * 10
+        payload 'action': :privmsg, 'alice': 'bob'
+        payload 'channel': '#rbot'
+        payload 'foo.bar': 'baz'
+      end
+      sql = @storage.query_to_sql(q)
+      assert_equal("(id = $1 OR id = $2 OR id = $3) AND (topic ILIKE $4 OR topic ILIKE $5 OR topic ILIKE $6) AND (timestamp >= $7 AND timestamp <= $8) AND (payload->>'action' = $9 OR payload->>'alice' = $10 OR payload->>'channel' = $11 OR payload->'foo'->>'bar' = $12)", sql[0])
+      q = Query.define do
+        id 'foo'
+      end
+      assert_equal('(id = $1)', @storage.query_to_sql(q)[0])
+      q = Query.define do
+        topic 'foo.*.bar'
+      end
+      assert_equal('(topic ILIKE $1)', @storage.query_to_sql(q)[0])
+      assert_equal(['foo.%.bar'], @storage.query_to_sql(q)[1])
     end
-    assert_equal('(topic ILIKE $1)', @storage.query_to_sql(q)[0])
-    assert_equal(['foo.%.bar'], @storage.query_to_sql(q)[1])
-  end
 
-end
-else
-  puts 'NOTE: Set PG_URI environment variable to test postgresql storage.'
-end
+  end
+  else
+    puts 'NOTE: Set PG_URI environment variable to test postgresql storage.'
+  end
+rescue Exception; end
 
-if ENV['MONGO_URI']
-class JournalStorageMongoTest < Test::Unit::TestCase
+begin
+  require 'rbot/journal/mongo.rb'
+  if ENV['MONGO_URI']
+  class JournalStorageMongoTest < Test::Unit::TestCase
 
-  include JournalStorageTestMixin
+    include JournalStorageTestMixin
 
-  def setup
-    @storage = Storage::MongoStorage.new(
-      uri: ENV['MONGO_URI'] || 'mongodb://127.0.0.1:27017/rbot',
-      drop: true)
+    def setup
+      @storage = Storage::MongoStorage.new(
+        uri: ENV['MONGO_URI'] || 'mongodb://127.0.0.1:27017/rbot',
+        drop: true)
+    end
   end
-end
-else
-  puts 'NOTE: Set MONGO_URI environment variable to test postgresql storage.'
-end
-
+  else
+    puts 'NOTE: Set MONGO_URI environment variable to test postgresql storage.'
+  end
+rescue Exception; end
index 8e92a095e9cc319bb2579746c77aa3300b33c275..261849d63de21db6396f73ca8afa5a6e9fb68316 100644 (file)
@@ -3,6 +3,7 @@ $:.unshift File.join(File.dirname(__FILE__), '../lib')
 require 'test/unit'
 require 'rbot/config'
 require 'rbot/plugins'
+require 'rbot/message'
 
 require 'pp'
 
@@ -93,7 +94,7 @@ class PluginsPriorityTest < Test::Unit::TestCase
   end
 
   def test_above
-    @@manager.delegate_event('test', :above => 3)
+    @@manager.delegate('test', :above => 3)
 
     assert_equal 0, @mock1.test_called_at.size
     assert_equal 0, @mock2.test_called_at.size
@@ -103,7 +104,7 @@ class PluginsPriorityTest < Test::Unit::TestCase
   end
 
   def test_below
-    @@manager.delegate_event('test', :below => 3)
+    @@manager.delegate('test', :below => 3)
 
     assert_equal 1, @mock1.test_called_at.size
     assert_equal 1, @mock2.test_called_at.size
@@ -113,7 +114,7 @@ class PluginsPriorityTest < Test::Unit::TestCase
   end
 
   def test_fast_delagate_above
-    @@manager.delegate_event('connect', :above => 3)
+    @@manager.delegate('connect', :above => 3)
 
     assert_equal 0, @mock1.connect_called_at.size
     assert_equal 0, @mock2.connect_called_at.size
@@ -123,7 +124,7 @@ class PluginsPriorityTest < Test::Unit::TestCase
   end
 
   def test_fast_delagate_above
-    @@manager.delegate_event('connect', :below => 3)
+    @@manager.delegate('connect', :below => 3)
 
     assert_equal 1, @mock1.connect_called_at.size
     assert_equal 1, @mock2.connect_called_at.size
@@ -133,7 +134,7 @@ class PluginsPriorityTest < Test::Unit::TestCase
   end
 
   def test_call_with_args
-    @@manager.delegate_event('test_arg', :above => 3, :args => [1])
+    @@manager.delegate('test_arg', 1, :above => 3)
 
     assert_equal 0, @mock3.test_arg_called_at.size
     assert_equal 1, @mock4.test_arg_called_at.size
index c6d68902937157a5c0a3e400093866621c444612..1f25f89d3a087de5bfb0492640deced705602386 100644 (file)
@@ -1,5 +1,14 @@
 $:.unshift File.join(File.dirname(__FILE__), '../lib')
 
+module Irc
+class Bot
+  module Config
+    @@datadir = File.expand_path(File.dirname($0) + '/../data/rbot')
+    @@coredir = File.expand_path(File.dirname($0) + '/../lib/rbot/core') 
+  end
+end
+end
+
 require 'test/unit'
 require 'rbot/ircbot'
 require 'rbot/registry'
@@ -293,34 +302,39 @@ class RegistryTCTest < Test::Unit::TestCase
   end
 end
 
-class RegistryDaybreakTest < Test::Unit::TestCase
-  include RegistryTestModule
-  include RegistryHashInterfaceTests
-
-  def initialize(o)
-    super o
-    @format = 'daybreak'
-    Irc::Bot::Registry.new(@format)
-    @registry_class = Irc::Bot::Registry::DaybreakAccessor
-  end
-end
-
-class RegistrySqliteTest < Test::Unit::TestCase
-  include RegistryTestModule
-  include RegistryHashInterfaceTests
-
-  def initialize(o)
-    super o
-    @format = 'sqlite'
-    Irc::Bot::Registry.new(@format)
-    @registry_class = Irc::Bot::Registry::SqliteAccessor
+begin
+  require 'daybreak'
+  class RegistryDaybreakTest < Test::Unit::TestCase
+    include RegistryTestModule
+    include RegistryHashInterfaceTests
+
+    def initialize(o)
+      super o
+      @format = 'daybreak'
+      Irc::Bot::Registry.new(@format)
+      @registry_class = Irc::Bot::Registry::DaybreakAccessor
+    end
   end
+rescue Exception; end
+
+begin
+  require 'sqlite'
+  class RegistrySqliteTest < Test::Unit::TestCase
+    include RegistryTestModule
+    include RegistryHashInterfaceTests
+
+    def initialize(o)
+      super o
+      @format = 'sqlite'
+      Irc::Bot::Registry.new(@format)
+      @registry_class = Irc::Bot::Registry::SqliteAccessor
+    end
 
-  def test_duplicate_keys
-    @reg['foo'] = 1
-    @reg['foo'] = 2
-    res = @reg.registry.execute('select key from data')
-    assert res.length == 1
+    def test_duplicate_keys
+      @reg['foo'] = 1
+      @reg['foo'] = 2
+      res = @reg.registry.execute('select key from data')
+      assert res.length == 1
+    end
   end
-end
-
+rescue Exception; end