Kouhei Sutou
null+****@clear*****
Thu Jan 16 16:38:01 JST 2014
Kouhei Sutou 2014-01-16 16:38:01 +0900 (Thu, 16 Jan 2014) New Revision: 1d9e7cc4bfc1bc522630169d880b2324b53caf78 https://github.com/droonga/drntest/commit/1d9e7cc4bfc1bc522630169d880b2324b53caf78 Message: Add configuration object Modified files: lib/drntest/engine.rb lib/drntest/test-executor.rb lib/drntest/test-loader.rb lib/drntest/test-runner.rb lib/drntest/tester.rb Renamed files: lib/drntest/configuration.rb (from lib/drntest/path.rb) Renamed: lib/drntest/configuration.rb (+23 -4) 52% =================================================================== --- lib/drntest/path.rb 2014-01-16 15:57:33 +0900 (310ebce) +++ lib/drntest/configuration.rb 2014-01-16 16:38:01 +0900 (4ce8190) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Droonga Project +# Copyright (C) 2014 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 @@ -14,8 +14,27 @@ # along with this program. If not, see <http://www.gnu.org/licenses/>. module Drntest - module Path - SUITE = "suite" - CONFIG = "config" + class Configuration + attr_accessor :port, :host, :tag + attr_accessor :base_path, :engine_config + attr_accessor :fluentd, :fluentd_options + + def initialize + @port = 24224 + @host = "localhost" + @tag = "droonga" + @base_path = Pathname(Dir.pwd) + @engine_config = "default" + @fluentd = "fluentd" + @fluentd_options = [] + end + + def suite_path + @base_path + "suite" + end + + def engine_config_path + @base_path + "config" + @engine_config + end end end Modified: lib/drntest/engine.rb (+12 -32) =================================================================== --- lib/drntest/engine.rb 2014-01-16 15:57:33 +0900 (1ba37d5) +++ lib/drntest/engine.rb 2014-01-16 16:38:01 +0900 (8f43e6f) @@ -20,16 +20,8 @@ require "fileutils" module Drntest class Engine - attr_reader :fluentd, :fluentd_options - - def initialize(params) - @base_path = params[:base_path] - @config_dir = params[:config_dir] - @default_port = params[:default_port] - @default_host = params[:default_host] - @default_tag = params[:default_tag] - @fluentd = params[:fluentd] - @fluentd_options = params[:fluentd_options] + def initialize(config) + @config = config end def start @@ -42,23 +34,11 @@ module Drntest end def config_file - @config_dir + "fluentd.conf" + @config.engine_config_path + "fluentd.conf" end def catalog_file - @config_dir + "catalog.json" - end - - def port - @port || @default_port - end - - def host - @host || @default_host - end - - def tag - @tag || @default_tag + @config.engine_config_path + "catalog.json" end private @@ -67,9 +47,9 @@ module Drntest catalog_json = JSON.parse(catalog_file.read, :symbolize_names => true) zone = catalog_json[:zones].first /\A([^:]+):(\d+)\/(.+)\z/ =~ zone - @host = "localhost" # $1 - @port = $2.to_i - @tag = $3 + @config.host = "localhost" # $1 + @config.port = $2.to_i + @config.tag = $3 end end @@ -84,9 +64,9 @@ module Drntest FileUtils.cp(catalog_file, temporary_catalog) command = [ - @fluentd, + @config.fluentd, "--config", temporary_config.to_s, - *@fluentd_options, + *@config.fluentd_options, ] env = { "DROONGA_CATALOG" => temporary_catalog.to_s, @@ -126,7 +106,7 @@ module Drntest end def temporary_base_dir - @base_path + "tmp" + @config.base_path + "tmp" end def temporary_dir @@ -134,12 +114,12 @@ module Drntest end def temporary? - @fluentd && config_file.exist? + @config.fluentd && config_file.exist? end def ready? begin - socket = TCPSocket.new(@host, @port) + socket = TCPSocket.new(@config.host, @config.port) socket.close true rescue Errno::ECONNREFUSED Modified: lib/drntest/test-executor.rb (+5 -7) =================================================================== --- lib/drntest/test-executor.rb 2014-01-16 15:57:33 +0900 (d0ba7fa) +++ lib/drntest/test-executor.rb 2014-01-16 16:38:01 +0900 (6c8cdec) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Droonga Project +# Copyright (C) 2013-2014 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 @@ -20,15 +20,13 @@ require "drntest/response-normalizer" module Drntest class TestExecutor - attr_reader :owner, :test_path - - def initialize(owner, test_path) - @owner = owner + def initialize(config, test_path) + @config = config @test_path = test_path end def execute - Droonga::Client.open(tag: owner.tag, port: owner.port) do |client| + Droonga::Client.open(tag: @config.tag, port: @config.port) do |client| context = Context.new(client) operations.each do |operation| context.execute(operation) @@ -40,7 +38,7 @@ module Drntest private def operations - loader = TestLoader.new(@owner, @test_path) + loader = TestLoader.new(@config, @test_path) loader.load end Modified: lib/drntest/test-loader.rb (+4 -6) =================================================================== --- lib/drntest/test-loader.rb 2014-01-16 15:57:33 +0900 (7526455) +++ lib/drntest/test-loader.rb 2014-01-16 16:38:01 +0900 (c73cb73) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Droonga Project +# Copyright (C) 2013-2014 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 @@ -18,10 +18,8 @@ require "drntest/directive" module Drntest class TestLoader - attr_reader :owner, :test_path - - def initialize(owner, test_path) - @owner = owner + def initialize(config, test_path) + @config = config @test_path = test_path end @@ -33,7 +31,7 @@ module Drntest def resolve_relative_path(path) path = path.to_s path = path[2..-1] if path[0..1] == "./" - Pathname(path).expand_path(@owner.base_path) + Pathname(path).expand_path(@config.base_path) end def load_test_file(path) Modified: lib/drntest/test-runner.rb (+4 -18) =================================================================== --- lib/drntest/test-runner.rb 2014-01-16 15:57:33 +0900 (8202f5e) +++ lib/drntest/test-runner.rb 2014-01-16 16:38:01 +0900 (5281523) @@ -19,7 +19,6 @@ require "tempfile" require "pp" require "fileutils" -require "drntest/path" require "drntest/test-results" require "drntest/test-executor" require "drntest/json-loader" @@ -27,19 +26,10 @@ require "drntest/engine" module Drntest class TestRunner - attr_reader :owner, :base_path, :target_path - - def initialize(owner, target) - @owner = owner - @base_path = Pathname(owner.base_path) + def initialize(config, target) + @config = config @target_path = Pathname(target) - @engine = Engine.new(:base_path => @base_path, - :config_dir => config_dir, - :default_port => @owner.port, - :default_host => @owner.host, - :default_tag => @owner.tag, - :fluentd => @owner.fluentd, - :fluentd_options => @owner.fluentd_options) + @engine = Engine.new(@config) end def run @@ -53,15 +43,11 @@ module Drntest results end - def config_dir - (@base_path + Path::CONFIG) +****@owner***** - end - private def process_requests results = TestResults.new(@target_path) - executor = TestExecutor.new(self, @target_path) + executor = TestExecutor.new(@config, @target_path) results.actuals = executor.execute if expected_exist? results.expecteds = load_expected_responses Modified: lib/drntest/tester.rb (+78 -83) =================================================================== --- lib/drntest/tester.rb 2014-01-16 15:57:33 +0900 (376d616) +++ lib/drntest/tester.rb 2014-01-16 16:38:01 +0900 (a34c33f) @@ -1,4 +1,4 @@ -# Copyright (C) 2013 Droonga Project +# Copyright (C) 2013-2014 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 @@ -18,7 +18,7 @@ require "optparse" require "pathname" require "drntest/version" -require "drntest/path" +require "drntest/configuration" require "drntest/test-runner" require "drntest/test-suites-result" @@ -28,99 +28,27 @@ module Drntest def run(argv=nil) argv ||= ARGV.dup tester = new - option_parser = create_option_parser(tester) - targets = option_parser.parse!(argv) + *targets = tester.parse_command_line_options(argv) tester.run(*targets) end - - private - def create_option_parser(tester) - parser = OptionParser.new - - parser.banner += " TEST_FILE..." - - parser.on("--port=PORT", - "Connect to fluent-plugin-droonga on PORT", - "(#{tester.port})") do |port| - tester.port = port - end - - parser.on("--host=HOST", - "Connect to fluent-plugin-droonga on HOST", - "(#{tester.host})") do |host| - tester.host = host - end - - parser.on("--tag=TAG", - "Send messages to fluent-plugin-droonga with TAG", - "(#{tester.tag})") do |tag| - tester.tag = tag - end - - parser.on("--base-path=PATH", - "Path to the base directory including test suite, config and fixture", - "(#{tester.base_path})") do |base_path| - tester.base_path = Pathname(base_path).expand_path(Dir.pwd) - end - - parser.on("--config=NAME", - "Name of the configuration directory for Droonga engine", - "(#{tester.config})") do |config| - tester.config = config - end - - parser.on("--fluentd=PATH", - "Path to the fluentd executable", - "(#{tester.fluentd})") do |fluentd| - tester.fluentd = fluentd - end - - parser.on("--fluentd-options=OPTIONS", - "Options for fluentd", - "You can specify this option multiple times") do |options| - tester.fluentd_options.concat(Shellwords.split(options)) - end - - parser.on("--test=PATTERN", - "Run only tests which have a name matched to the given PATTERN") do |pattern| - if /\A\/(.+)\/\z/ =~ pattern - pattern = Regexp.new($1) - end - tester.test_pattern = pattern - end - - parser.on("--test-suite=PATTERN", - "Run only test suites which have a path matched to the given PATTERN") do |pattern| - if /\A\/(.+)\/\z/ =~ pattern - pattern = Regexp.new($1) - end - tester.suite_pattern = pattern - end - - parser - end end - attr_accessor :port, :host, :tag, :fluentd, :fluentd_options - attr_accessor :test_pattern, :suite_pattern, :base_path, :config - def initialize - @port = 24224 - @host = "localhost" - @tag = "droonga" - @base_path = Pathname(Dir.pwd) - @config = "default" - @fluentd = "fluentd" - @fluentd_options = [] + @config = Configuration.new @test_pattern = nil @suite_pattern = nil end + def parse_command_line_options(command_line_options) + option_parser = create_option_parser + option_parser.parse!(command_line_options) + end + def run(*targets) test_suites_result = TestSuitesResult.new tests = load_tests(*targets) tests.each do |test| - test_runner = TestRunner.new(self, test) + test_runner = TestRunner.new(@config, test) test_suites_result.test_results << test_runner.run end @@ -140,8 +68,75 @@ module Drntest test_suites_result.success? end + private + def create_option_parser + parser = OptionParser.new + + parser.banner += " TEST_FILE..." + + parser.on("--port=PORT", + "Connect to fluent-plugin-droonga on PORT", + "(#{@config.port})") do |port| + @config.port = port + end + + parser.on("--host=HOST", + "Connect to fluent-plugin-droonga on HOST", + "(#{@config.host})") do |host| + @config.host = host + end + + parser.on("--tag=TAG", + "Send messages to fluent-plugin-droonga with TAG", + "(#{@config.tag})") do |tag| + @config.tag = tag + end + + parser.on("--base-path=PATH", + "Path to the base directory including test suite, config and fixture", + "(#{@config.base_path})") do |base_path| + @config.base_path = Pathname(base_path).expand_path(Dir.pwd) + end + + parser.on("--config=NAME", + "Name of the configuration directory for Droonga engine", + "(#{@config.engine_config})") do |config| + @config.engine_config = config + end + + parser.on("--fluentd=PATH", + "Path to the fluentd executable", + "(#{@config.fluentd})") do |fluentd| + @config.fluentd = fluentd + end + + parser.on("--fluentd-options=OPTIONS", + "Options for fluentd", + "You can specify this option multiple times") do |options| + @config.fluentd_options.concat(Shellwords.split(options)) + end + + parser.on("--test=PATTERN", + "Run only tests which have a name matched to the given PATTERN") do |pattern| + if /\A\/(.+)\/\z/ =~ pattern + pattern = Regexp.new($1) + end + @test_pattern = pattern + end + + parser.on("--test-suite=PATTERN", + "Run only test suites which have a path matched to the given PATTERN") do |pattern| + if /\A\/(.+)\/\z/ =~ pattern + pattern = Regexp.new($1) + end + @suite_pattern = pattern + end + + parser + end + def load_tests(*targets) - suite_path = @base_path + Path::SUITE + suite_path =****@confi*****_path targets << suite_path if targets.empty? tests = [] -------------- next part -------------- HTML����������������������������... Download