Yoji Shidara
null+****@clear*****
Tue Oct 15 17:40:26 JST 2013
Yoji Shidara 2013-10-15 17:40:26 +0900 (Tue, 15 Oct 2013) New Revision: 4bb415c5f633661daf8fe62fb8b34298801c4007 https://github.com/droonga/fluent-plugin-droonga/commit/4bb415c5f633661daf8fe62fb8b34298801c4007 Message: Add test cases for watch.feed Modified files: test/helper/stub_worker.rb test/plugin/handler/test_handler_watch.rb Modified: test/helper/stub_worker.rb (+2 -1) =================================================================== --- test/helper/stub_worker.rb 2013-10-15 14:45:39 +0900 (b7387c4) +++ test/helper/stub_worker.rb 2013-10-15 17:40:26 +0900 (eec82a5) @@ -14,10 +14,11 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA class StubWorker - attr_reader :context, :body + attr_reader :context, :body, :envelope def initialize() @context = Groonga::Context.default + @envelope = {} end def post(body, destination=nil) Modified: test/plugin/handler/test_handler_watch.rb (+39 -0) =================================================================== --- test/plugin/handler/test_handler_watch.rb 2013-10-15 14:45:39 +0900 (f03e096) +++ test/plugin/handler/test_handler_watch.rb 2013-10-15 17:40:26 +0900 (1a422cc) @@ -121,4 +121,43 @@ class WatchHandlerTest < Test::Unit::TestCase @handler.subscribe(request) end end + + class TestFeed < self + def setup + super + setup_subscription + end + + def test_feed_match + request = { + "targets" => { + "text" => "たいやきおいしいです" + } + } + @handler.feed(request) + assert_equal(request, @worker.body) + assert_equal({"to" => ["localhost"]}, @worker.envelope) + end + + def test_feed_not_match + request = { + "targets" => { + "text" => "たこやきおいしいです" + } + } + @handler.feed(request) + assert_nil(@worker.body) + end + + private + def setup_subscription + request = { + "route" => "localhost:23003/output", + "condition" => "たいやき", + "subscriber" => "localhost" + } + stub(@handler).emit([true]) + @handler.subscribe(request) + end + end end -------------- next part -------------- HTML����������������������������...Download