[Groonga-commit] groonga/fluent-plugin-groonga at a06e772 [master] test: create test case instead of creating custom driver in test

Back to archive index

Kouhei Sutou null+****@clear*****
Tue Jan 16 09:15:17 JST 2018


Kouhei Sutou	2018-01-16 09:15:17 +0900 (Tue, 16 Jan 2018)

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

  Message:
    test: create test case instead of creating custom driver in test

  Modified files:
    test/test_input.rb

  Modified: test/test_input.rb (+64 -34)
===================================================================
--- test/test_input.rb    2018-01-16 08:57:08 +0900 (6245283)
+++ test/test_input.rb    2018-01-16 09:15:17 +0900 (564a44b)
@@ -32,9 +32,9 @@ class GroongaInputTest < Test::Unit::TestCase
   end
 
   private
-  def create_driver(conf = configuration)
+  def create_driver
     driver = Fluent::Test::Driver::Input.new(Fluent::Plugin::GroongaInput)
-    driver.configure(conf)
+    driver.configure(configuration)
     driver
   end
 
@@ -117,38 +117,6 @@ EOC
                    @driver.events)
     end
 
-    def test_target_command_with_command_name_position_record
-      @real_response["Content-Type"] = "application/json"
-      @real_response.body = JSON.generate([[0, 0.0, 0.0], true])
-      conf = <<EOC
-      protocol http
-      bind #{@host}
-      port #{@port}
-      real_host #{@real_host}
-      real_port #{@real_port}
-      command_name_position record
-EOC
-      driver = create_driver(conf)
-      driver.run do
-        get("/d/table_create", "name" => "Users", "flags" => "TABLE_NO_KEY")
-        assert_equal("200", @last_response.code)
-      end
-      assert_equal([
-                     [
-                       "groonga.command",
-                       @now,
-                       {
-                         "name" => "table_create",
-                         "arguments" => {
-                           "name" => "Users",
-                           "flags" => "TABLE_NO_KEY",
-                         }
-                       },
-                     ]
-                   ],
-                   driver.events)
-    end
-
     def test_not_target_command
       @driver.run do
         get("/d/status")
@@ -191,6 +159,68 @@ EOJ
       end
     end
 
+    sub_test_case("command_name_position") do
+      sub_test_case("record") do
+        def configuration
+          super + <<-CONFIGURATION
+  command_name_position record
+          CONFIGURATION
+        end
+
+        def test_not_load
+          @real_response["Content-Type"] = "application/json"
+          @real_response.body = JSON.generate([[0, 0.0, 0.0], true])
+          @driver.run do
+            get("/d/table_create", "name" => "Users", "flags" => "TABLE_NO_KEY")
+            assert_equal("200", @last_response.code)
+          end
+          assert_equal([
+                         [
+                           "groonga.command",
+                           @now,
+                           {
+                             "name" => "table_create",
+                             "arguments" => {
+                               "name" => "Users",
+                               "flags" => "TABLE_NO_KEY",
+                             }
+                           },
+                         ]
+                       ],
+                       @driver.events)
+        end
+
+        def test_load
+          @real_response["Content-Type"] = "application/json"
+          @real_response.body = JSON.generate([[0, 0.0, 0.0], true])
+          json = <<-JSON
+[
+{"name": "Alice"},
+{"name": "Bob"}
+]
+          JSON
+          @driver.run do
+            post("/d/load", json, "table" => "Users")
+            assert_equal("200", @last_response.code)
+          end
+          assert_equal([
+                         [
+                           "groonga.command",
+                           @now,
+                           {
+                             "name" => "load",
+                             "arguments" => {
+                               "table" => "Users",
+                               "values" => json,
+                             }
+                           },
+                         ]
+                       ],
+                       @driver.events)
+        end
+      end
+    end
+
     private
     def get(path, parameters={})
       http = Net::HTTP.new(@host, @port)
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20180116/486f089c/attachment-0001.htm 



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