[Groonga-commit] ranguba/groonga-client at b0cac72 [master] test: add test case for --check-index-integrity option

アーカイブの一覧に戻る

Kentaro Hayashi null+****@clear*****
Thu Oct 26 13:09:36 JST 2017


Kentaro Hayashi	2017-10-26 13:09:36 +0900 (Thu, 26 Oct 2017)

  New Revision: b0cac72809e2b4338471180560050c6fd9e7b8eb
  https://github.com/ranguba/groonga-client/commit/b0cac72809e2b4338471180560050c6fd9e7b8eb

  Merged 64e66c2: Merge pull request #30 from kenhys/groonga-client-index-check

  Message:
    test: add test case for --check-index-integrity option

  Added files:
    test/command-line/test-index-check.rb

  Added: test/command-line/test-index-check.rb (+140 -0) 100644
===================================================================
--- /dev/null
+++ test/command-line/test-index-check.rb    2017-10-26 13:09:36 +0900 (b58bc1c)
@@ -0,0 +1,140 @@
+# Copyright (C) 2017  Kouhei Sutou <kou �� clear-code.com>
+# Copyright (C) 2017  Kentaro Hayashi <hayashi �� 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 as published by the Free Software Foundation; either
+# version 2.1 of the License, or (at your option) any later version.
+#
+# 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., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
+
+require "time"
+
+require "groonga/command/parser"
+
+require "groonga/client"
+require "groonga/client/test-helper"
+require "groonga/client/command-line/groonga-client-index-check"
+
+class TestCommandLineIndexCheck < Test::Unit::TestCase
+  include Groonga::Client::TestHelper
+
+  def groonga_url
+    @groonga_server_runner.url.to_s
+  end
+
+  def open_client
+    Groonga::Client.open(:url => groonga_url) do |client|
+      yield(client)
+    end
+  end
+
+  def restore(commands)
+    open_client do |client|
+      values = nil
+      Groonga::Command::Parser.parse(commands) do |event, *args|
+        case event
+        when :on_command
+          command, = args
+          response = client.execute(command)
+          unless response.success?
+            raise Groonga::Client::Request::ErrorResponse.new(response)
+          end
+        when :on_load_start
+          command, = args
+          values = []
+        when :on_load_columns
+          command, columns = args
+          command[:columns] ||= columns.join(",")
+        when :on_load_value
+          command, value = args
+          values << value
+        when :on_load_complete
+          command, = args
+          command[:values] ||= JSON.generate(values)
+          response = client.execute(command)
+          unless response.success?
+            raise Groonga::Client::Request::ErrorResponse.new(response)
+          end
+        else
+          p [:unhandled_event, event, *args]
+        end
+      end
+    end
+  end
+
+  def run_client_index_check(*arguments)
+    command_line = Groonga::Client::CommandLine::GroongaClientIndexCheck.new
+    begin
+      stdout, $stdout = $stdout, StringIO.new
+      stderr, $stderr = $stderr, StringIO.new
+      [
+        command_line.run(["--url", groonga_url,
+                          *arguments]),
+        $stdout.string,
+        $stderr.string,
+      ]
+    ensure
+      $stdout, $stderr = stdout, stderr
+    end
+  end
+
+  def test_check_missing_source
+    restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos_content \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos
+    COMMANDS
+
+    expected = <<CLIENT_OUTPUT
+index column:<Terms.memos_content> is missing source.
+CLIENT_OUTPUT
+
+    assert_equal([1, expected, ""],
+                 run_client_index_check("--check-missing-source",
+                                        "Terms.memos_content"))
+  end
+
+  def test_check_index_integrity
+    restore(<<-COMMANDS)
+table_create Memos TABLE_HASH_KEY ShortText
+column_create Memos content COLUMN_SCALAR Text
+
+table_create Terms TABLE_PAT_KEY ShortText \
+  --normalizer NormalizerAuto \
+  --default_tokenizer TokenBigram
+column_create Terms memos_content \
+  COLUMN_INDEX|WITH_POSITION \
+  Memos content
+
+load --table Memos
+[
+["_key","content"],
+["groonga","Groonga is fast"]
+]
+    COMMANDS
+
+    expected = <<CLIENT_OUTPUT
+check 3 tokens against <Terms.memos_content>.
+CLIENT_OUTPUT
+
+    assert_equal([0, expected, ""],
+                 run_client_index_check("--check-index-integrity",
+                                        "Terms.memos_content"))
+    
+  end
+
+end
-------------- next part --------------
HTML����������������������������...
URL: https://lists.osdn.me/mailman/archives/groonga-commit/attachments/20171026/427943ba/attachment-0001.htm 



More information about the Groonga-commit mailing list
アーカイブの一覧に戻る