Kouhei Sutou
null+****@clear*****
Thu Nov 21 16:15:23 JST 2013
Kouhei Sutou 2013-11-21 16:15:23 +0900 (Thu, 21 Nov 2013) New Revision: 9feb2002b22108d1fab2fd0c9754046a54c7b36a https://github.com/droonga/drntest/commit/9feb2002b22108d1fab2fd0c9754046a54c7b36a Message: Extract coommand executor as a class Added files: lib/drntest/executor.rb Modified files: lib/drntest/test-runner.rb Added: lib/drntest/executor.rb (+74 -0) 100644 =================================================================== --- /dev/null +++ lib/drntest/executor.rb 2013-11-21 16:15:23 +0900 (f54fee9) @@ -0,0 +1,74 @@ +# Copyright (C) 2013 Droonga Project +# +# This program is free software: you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation, either version 3 of the License, or +# (at your option) any later version. +# +# This program 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 General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +require "droonga/client" + +module Drntest + class Executor + attr_reader :tester, :request + + def initialize(tester, request) + @tester = tester + @request = request + end + + def execute + normalize_result(execute_commands) + end + + private + def execute_commands + client = Droonga::Client.new(tag: tester.tag, port: tester.port) + client.connection.send(request, :response => :one) + end + + def normalize_result(result) + return result if result.nil? + + normalized_result = result.dup + normalize_envelope!(normalized_result) + normalize_body!(normalized_result) + normalized_result + end + + def normalize_envelope!(normalized_result) + normalized_start_time = 0 + normalized_result[1] = normalized_start_time + end + + def normalize_body!(normalized_result) + return unless groonga_command? + normalize_groonga_command_result!(normalized_result[2]) + end + + GROONGA_COMMANDS = [ + "table_create", + ] + def groonga_command? + GROONGA_COMMANDS.include?(request["type"]) + end + + def normalize_groonga_command_result!(result) + normalize_groonga_command_header!(result["body"][0]) + end + + def normalize_groonga_command_header!(header) + normalized_start_time = 0.0 + normalized_elapsed = 0.0 + header[1] = normalized_start_time + header[2] = normalized_elapsed + end + end +end Modified: lib/drntest/test-runner.rb (+3 -58) =================================================================== --- lib/drntest/test-runner.rb 2013-11-21 15:50:51 +0900 (8cb5bce) +++ lib/drntest/test-runner.rb 2013-11-21 16:15:23 +0900 (e8e4408) @@ -14,10 +14,10 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. require "json" -require "droonga/client" require "tempfile" require "pp" require "drntest/test-result" +require "drntest/executor" require "fileutils" module Drntest @@ -34,11 +34,8 @@ module Drntest print "#{target_path}: " request_envelope = load_request_envelope - actual = execute_commands(request_envelope) - if actual - actual = normalize_result(request_envelope, actual) - result.actual = actual - end + executor = Executor.new(tester, request_envelope) + result.actual = executor.execute if expected_exist? result.expected = load_expected @@ -63,11 +60,6 @@ module Drntest end private - def execute_commands(request_envelope) - client = Droonga::Client.new(tag: tester.tag, port: tester.port) - actual = client.connection.send(request_envelope, :response => :one) - end - def load_request_envelope JSON.parse(target_path.read) end @@ -134,52 +126,5 @@ module Drntest file.close yield(file) end - - def normalize_result(requet_envelope, result) - result = normalize_envelope(result) - normalize_body(requet_envelope, result) - end - - def normalize_envelope(result) - result = result.dup - result[1] = 0 # Mask start time - result - end - - def normalize_body(request_envelope, result) - if groonga_command?(request_envelope) - normalize_groonga_command_result(result) - else - result - end - end - - GROONGA_COMMANDS = [ - "table_create", - ] - def groonga_command?(request_envelope) - GROONGA_COMMANDS.include?(request_envelope["type"]) - end - - def normalize_groonga_command_result(result) - result = result.dup - header, *return_values = result[2]["body"] - normalized_header = normalize_groonga_command_header(header) - result[2]["body"] = [normalized_header, *return_values] - result - end - - def normalize_groonga_command_header(header) - status_code, start_time, elapsed, *others = header - normalized_start_time = 0.0 - normalized_elapsed = 0.0 - - [ - status_code, - normalized_start_time, - normalized_elapsed, - *others, - ] - end end end -------------- next part -------------- HTML����������������������������... 다운로드