SHIMODA Piro Hiroshi
null+****@clear*****
Sat Oct 4 19:26:46 JST 2014
SHIMODA "Piro" Hiroshi 2014-10-04 19:26:46 +0900 (Sat, 04 Oct 2014) New Revision: 2fa46590a4a750be3448c4c86ea53a241e94063e https://github.com/droonga/drnbench/commit/2fa46590a4a750be3448c4c86ea53a241e94063e Message: Add test for request-patterns Added files: test/run-test.rb test/test-request-pattern.rb Modified files: Rakefile drnbench.gemspec Modified: Rakefile (+7 -0) =================================================================== --- Rakefile 2014-10-04 18:53:54 +0900 (bec4615) +++ Rakefile 2014-10-04 19:26:46 +0900 (34ad01a) @@ -15,6 +15,8 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see <http://www.gnu.org/licenses/>. +task :default => :test + require "bundler/gem_helper" require "packnga" @@ -31,3 +33,8 @@ Packnga::DocumentTask.new(spec) do |task| task.original_language = "en" task.translate_languages = ["ja"] end + +desc "Run tests" +task :test do + ruby("test/run-test.rb") +end \ No newline at end of file Modified: drnbench.gemspec (+1 -0) =================================================================== --- drnbench.gemspec 2014-10-04 18:53:54 +0900 (bb44899) +++ drnbench.gemspec 2014-10-04 19:26:46 +0900 (0d5fd66) @@ -56,4 +56,5 @@ Gem::Specification.new do |spec| spec.add_development_dependency("rake") spec.add_development_dependency("packnga") spec.add_development_dependency("kramdown") + spec.add_development_dependency("test-unit") end Added: test/run-test.rb (+42 -0) 100755 =================================================================== --- /dev/null +++ test/run-test.rb 2014-10-04 19:26:46 +0900 (32f70e1) @@ -0,0 +1,42 @@ +#!/usr/bin/env ruby +# -*- coding: utf-8 -*- +# +# Copyright (C) 2013 Droonga Project +# +# 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 "pathname" + +require "rubygems" +require "bundler" +begin + Bundler.setup(:default, :development) +rescue Bundler::BundlerError => e + $stderr.puts e.message + $stderr.puts "Run `bundle install` to install missing gems" + exit e.status_code +end + +require "test-unit" + +base_dir = File.expand_path(File.join(File.dirname(__FILE__), "..")) +lib_dir = File.join(base_dir, "lib") +test_dir = File.join(base_dir, "test") + +$LOAD_PATH.unshift(lib_dir) +$LOAD_PATH.unshift(test_dir) + +ARGV.unshift("--max-diff-target-string-size=10000") + +exit Test::Unit::AutoRunner.run(true, test_dir) Added: test/test-request-pattern.rb (+110 -0) 100755 =================================================================== --- /dev/null +++ test/test-request-pattern.rb 2014-10-04 19:26:46 +0900 (a1490a6) @@ -0,0 +1,110 @@ +# Copyright (C) 2014 Droonga Project +# +# 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 "ostruct" +require "json" +require "drnbench/request-response/request-pattern" + +module Drnbench::RequestResponse::RequestPattern + class RequestResponsePatternsTest < Test::Unit::TestCase + CONFIG = OpenStruct.new + CONFIG.n_requests = 1 + CONFIG.end_n_clients = 1 + + PATH_STRING = "/path/to/endpoint" + PATTERN_HASH = { "path" => PATH_STRING } + + class PatternTest < self + data("path string" => PATH_STRING, + "hash" => PATTERN_HASH) + def test_validation(source) + Pattern.valid_source?(source) + end + end + + class PatternsGroupTest < self + data("path string array" => [ + PATH_STRING, + ], + "hash array" => [ + PATTERN_HASH, + ], + "hash with path string array" => { + "patterns" => [ + PATH_STRING, + ], + }, + "hash with hash array" => { + "patterns" => [ + PATTERN_HASH, + ], + }) + def test_validation(source) + PatternsGroup.valid_source?(source) + end + end + + class AbstractTest < self + data("path string array" => [ + PATH_STRING, + ], + "pattern hash array" => [ + PATTERN_HASH, + ], + + "group, hash with path string array" => { + "patterns" => [ + PATH_STRING, + ], + }, + "group, hash with hash array" => { + "patterns" => [ + PATTERN_HASH, + ], + }, + + "array of groups, path string array" => [ + [PATH_STRING], + ], + "array of groups, hash array" => [ + [PATTERN_HASH], + ], + "array of groups, hash with path string array" => [ + { "patterns" => [PATH_STRING] }, + ], + "array of groups, hash with hash array" => [ + { "patterns" => [PATTERN_HASH] }, + ], + + "named groups, path string array" => { + "group" => [PATH_STRING], + }, + "named groups, hash array" => { + "group" => [PATTERN_HASH], + }, + "named groups, hash with path string array" => { + "group" => { "patterns" => [PATH_STRING] }, + }, + "named groups, hash with hash array" => { + "group" => { "patterns" => [PATTERN_HASH] }, + }) + def test_parse(source) + abstract = Abstract.new(source, CONFIG) + assert_equal(PATH_STRING, + abstract.groups.first.patterns.first.path) + end + end + end +end \ No newline at end of file -------------- next part -------------- HTML����������������������������...下载