[Groonga-commit] groonga/fluent-plugin-groonga [master] Add a test for input plugin

Back to archive index

Kouhei Sutou null+****@clear*****
Fri Oct 26 18:34:05 JST 2012


Kouhei Sutou	2012-10-26 18:34:05 +0900 (Fri, 26 Oct 2012)

  New Revision: 725181ea123f84bd4a24de6c685f67e703f6e54c
  https://github.com/groonga/fluent-plugin-groonga/commit/725181ea123f84bd4a24de6c685f67e703f6e54c

  Log:
    Add a test for input plugin

  Added files:
    .gitignore
    test/test_input.rb
  Copied files:
    Rakefile
      (from fluent-plugin-groonga.gemspec)
    test/run-test.rb
      (from fluent-plugin-groonga.gemspec)
  Modified files:
    fluent-plugin-groonga.gemspec
    lib/fluent/plugin/in_groonga.rb

  Added: .gitignore (+1 -0) 100644
===================================================================
--- /dev/null
+++ .gitignore    2012-10-26 18:34:05 +0900 (05273c9)
@@ -0,0 +1 @@
+/test/.test-result/

  Copied: Rakefile (+16 -15) 52%
===================================================================
--- fluent-plugin-groonga.gemspec    2012-10-26 17:37:03 +0900 (8220a97)
+++ Rakefile    2012-10-26 18:34:05 +0900 (ec0be25)
@@ -1,4 +1,4 @@
-# -*- mode: ruby; coding: utf-8 -*-
+# -*- coding: utf-8; mode: ruby -*-
 #
 # Copyright (C) 2012  Kouhei Sutou <kou �� clear-code.com>
 #
@@ -15,20 +15,21 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-Gem::Specification.new do |spec|
-  spec.name = "fluent-plugin-groonga"
-  spec.version = "1.0.0"
-  spec.authors = ["Kouhei Sutou"]
-  spec.email = ["kou �� clear-code.com"]
-  spec.summary = "Fluentd plugin collection for groonga users"
-  spec.description =
-    "Groonga users can replicate their data by fluent-plugin-groonga"
-  spec.homepage = "https://github.com/groonga/fluent-plugin-groonga"
+require "bundler/gem_helper"
 
-  spec.files = ["README.md", "Gemfile", "#{spec.name}.gemspec"]
-  spec.files += Dir.glob("lib/**/*.rb")
-  spec.files += Dir.glob("doc/text/**/*")
-  spec.require_paths = ["lib"]
+base_dir = File.join(File.dirname(__FILE__))
 
-  spec.add_runtime_dependency("fluentd")
+helper = Bundler::GemHelper.new(base_dir)
+def helper.version_tag
+  version
 end
+
+helper.install
+spec = helper.gemspec
+
+desc "Run test"
+task :test do
+  ruby("-rubygems", "test/run-test.rb")
+end
+
+task :default => :test

  Modified: fluent-plugin-groonga.gemspec (+2 -0)
===================================================================
--- fluent-plugin-groonga.gemspec    2012-10-26 17:37:03 +0900 (8220a97)
+++ fluent-plugin-groonga.gemspec    2012-10-26 18:34:05 +0900 (407a1bf)
@@ -31,4 +31,6 @@ Gem::Specification.new do |spec|
   spec.require_paths = ["lib"]
 
   spec.add_runtime_dependency("fluentd")
+  spec.add_development_dependency("test-unit")
+  spec.add_development_dependency("test-unit-notify")
 end

  Modified: lib/fluent/plugin/in_groonga.rb (+2 -2)
===================================================================
--- lib/fluent/plugin/in_groonga.rb    2012-10-26 17:37:03 +0900 (5a83cd1)
+++ lib/fluent/plugin/in_groonga.rb    2012-10-26 18:34:05 +0900 (1199c9b)
@@ -26,6 +26,7 @@ module Fluent
     end
 
     config_param :protocol, :string, :default => "http"
+    config_param :port, :integer, :default => 10041
 
     def configure(conf)
       super
@@ -39,7 +40,7 @@ module Fluent
         $log.error message
         raise ConfigError, message
       end
-      @input.configure(conf.merge("port" => 10041))
+      @input.configure({"port" => @port}.merge(conf))
     end
 
     def start
@@ -52,7 +53,6 @@ module Fluent
 
     class HTTPInput < HttpInput
       def on_request(path_info, params)
-        p [path_info, params]
         case path_info
         when /\A\/d\/([a-zA-Z0-9\-_]+)\z/
           command = $1

  Copied: test/run-test.rb (+23 -17) 52%
  Mode: 100644 -> 100755
===================================================================
--- fluent-plugin-groonga.gemspec    2012-10-26 17:37:03 +0900 (8220a97)
+++ test/run-test.rb    2012-10-26 18:34:05 +0900 (e76e879)
@@ -1,4 +1,4 @@
-# -*- mode: ruby; coding: utf-8 -*-
+#!/usr/bin/env ruby
 #
 # Copyright (C) 2012  Kouhei Sutou <kou �� clear-code.com>
 #
@@ -15,20 +15,26 @@
 # License along with this library; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
-Gem::Specification.new do |spec|
-  spec.name = "fluent-plugin-groonga"
-  spec.version = "1.0.0"
-  spec.authors = ["Kouhei Sutou"]
-  spec.email = ["kou �� clear-code.com"]
-  spec.summary = "Fluentd plugin collection for groonga users"
-  spec.description =
-    "Groonga users can replicate their data by fluent-plugin-groonga"
-  spec.homepage = "https://github.com/groonga/fluent-plugin-groonga"
-
-  spec.files = ["README.md", "Gemfile", "#{spec.name}.gemspec"]
-  spec.files += Dir.glob("lib/**/*.rb")
-  spec.files += Dir.glob("doc/text/**/*")
-  spec.require_paths = ["lib"]
-
-  spec.add_runtime_dependency("fluentd")
+# $VERBOSE = true
+
+base_dir = File.expand_path(File.join(File.dirname(__FILE__), ".."))
+lib_dir = File.join(base_dir, "lib")
+test_dir = File.join(base_dir, "test")
+
+require "test-unit"
+require "test/unit/notify"
+
+Test::Unit::Priority.enable
+
+$LOAD_PATH.unshift(lib_dir)
+
+require "fluent/log"
+$log = Fluent::Log.new($stdout, Fluent::Log::LEVEL_WARN)
+
+Dir.glob("#{base_dir}/test/**/test{_,-}*.rb") do |file|
+  require file.sub(/\.rb$/, '')
 end
+
+ENV["TEST_UNIT_MAX_DIFF_TARGET_STRING_SIZE"] ||= "5000"
+
+exit Test::Unit::AutoRunner.run

  Added: test/test_input.rb (+85 -0) 100644
===================================================================
--- /dev/null
+++ test/test_input.rb    2012-10-26 18:34:05 +0900 (1fee996)
@@ -0,0 +1,85 @@
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012  Kouhei Sutou <kou �� clear-code.com>
+#
+# This library is free software; you can redistribute it and/or
+# modify it under the terms of the GNU Lesser General Public
+# License version 2.1 as published by the Free Software Foundation.
+#
+# This library is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+# Lesser General Public License for more details.
+#
+# You should have received a copy of the GNU Lesser General Public
+# License along with this library; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
+
+require "time"
+require "cgi/util"
+require "net/http"
+
+require "fluent/test"
+require "fluent/plugin/in_groonga"
+
+class GroongaInputTest < Test::Unit::TestCase
+  setup
+  def setup_fluent
+    Fluent::Test.setup
+    @now = Time.parse("2012-10-26T08:45:42Z").to_i
+    Fluent::Engine.now = @now
+  end
+
+  private
+  def create_driver
+    driver = Fluent::Test::InputTestDriver.new(Fluent::GroongaInput)
+    driver.configure(configuration)
+    driver
+  end
+
+  def configuration
+    <<-EOC
+EOC
+  end
+
+  class HTTPTest < self
+    def setup
+      @host = "127.0.0.1"
+      @port = 2929
+
+      @driver = create_driver
+    end
+
+    def configuration
+      <<-EOC
+      protocol http
+      bind #{@host}
+      port #{@port}
+EOC
+    end
+
+    def test_basic_command
+      @driver.expect_emit("groonga.command.table_create",
+                          @now,
+                          {"name" => "Users"})
+
+      @driver.run do
+        get("/d/table_create", "name" => "Users")
+      end
+    end
+
+    private
+    def get(path, parameters={})
+      unless parameters.empty?
+        url_encoded_parameters = parameters.collect do |key, value|
+          "#{CGI.escape(key)}=#{CGI.escape(value)}"
+        end
+        path += "?" + url_encoded_parameters.join("&")
+      end
+      http = Net::HTTP.new(@host, @port)
+      response = http.get(path)
+      assert_equal("200", response.code)
+      response
+    end
+  end
+end
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Back to archive index