drntest 1.0.0 → 1.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/drntest.gemspec +1 -1
- data/lib/drntest/directive.rb +30 -0
- data/lib/drntest/json-loader.rb +62 -0
- data/lib/drntest/path.rb +21 -0
- data/lib/drntest/{executor.rb → response-normalizer.rb} +17 -31
- data/lib/drntest/test-executor.rb +105 -0
- data/lib/drntest/test-loader.rb +74 -0
- data/lib/drntest/test-runner.rb +54 -105
- data/lib/drntest/tester.rb +8 -3
- data/lib/drntest/version.rb +1 -1
- metadata +27 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 04d9acd495e58d18289127e4bb88eb63b2a4ef6d
|
4
|
+
data.tar.gz: 233acd50bd676565e1ec6e0151184912d8068b8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 414223a7360b5f2502f9ea5da7ca759bfee4d8216e05ab6688ceb0a796b0f8da97e1dc1b8086ff82bdbc01e283f0e181ae4dff35be14e26f97e8a21a72a87b18
|
7
|
+
data.tar.gz: cbd23eb74bf5ae7bf7991d5b382cf453cd220ed02cfa882cc659a6fe1da562eec1595c7522d7c32590a446a26a3923e8ec1ec37a51574a2f45f3bdcc23d0c842
|
data/drntest.gemspec
CHANGED
@@ -42,7 +42,7 @@ Gem::Specification.new do |spec|
|
|
42
42
|
|
43
43
|
spec.add_runtime_dependency("json")
|
44
44
|
spec.add_runtime_dependency("yajl-ruby")
|
45
|
-
spec.add_runtime_dependency("droonga-client")
|
45
|
+
spec.add_runtime_dependency("droonga-client", ">= 0.1.0")
|
46
46
|
|
47
47
|
spec.add_development_dependency("bundler")
|
48
48
|
spec.add_development_dependency("rake")
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module Drntest
|
17
|
+
class Directive
|
18
|
+
attr_reader :type, :value
|
19
|
+
|
20
|
+
def initialize(type, value)
|
21
|
+
@type = normalize_type(type)
|
22
|
+
@value = value
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
def normalize_type(type)
|
27
|
+
type.gsub("-", "_").to_sym
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,62 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "yajl"
|
17
|
+
|
18
|
+
module Drntest
|
19
|
+
class JSONLoader
|
20
|
+
class << self
|
21
|
+
def report_error(path, data, error)
|
22
|
+
marker = "-" * 60
|
23
|
+
puts("Failed to load JSONs file: #{path}")
|
24
|
+
puts(marker)
|
25
|
+
puts(data)
|
26
|
+
puts(marker)
|
27
|
+
puts(error)
|
28
|
+
puts(marker)
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
attr_reader :objects
|
33
|
+
|
34
|
+
def initialize
|
35
|
+
@parser = Yajl::Parser.new
|
36
|
+
@objects = []
|
37
|
+
@parser.on_parse_complete = lambda do |object|
|
38
|
+
@objects << object
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
def <<(data)
|
43
|
+
@parser << data
|
44
|
+
end
|
45
|
+
|
46
|
+
def load(path)
|
47
|
+
path.open do |file|
|
48
|
+
data = ""
|
49
|
+
file.each_line do |line|
|
50
|
+
data << line
|
51
|
+
begin
|
52
|
+
self << line
|
53
|
+
rescue Yajl::ParseError => error
|
54
|
+
self.class.report_error(path, data, error)
|
55
|
+
break
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
59
|
+
@objects
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/lib/drntest/path.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
module Drntest
|
17
|
+
module Path
|
18
|
+
SUITE = "suite"
|
19
|
+
CONFIG = "config"
|
20
|
+
end
|
21
|
+
end
|
@@ -13,48 +13,34 @@
|
|
13
13
|
# You should have received a copy of the GNU General Public License
|
14
14
|
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
15
|
|
16
|
-
require "droonga/client"
|
17
|
-
|
18
16
|
module Drntest
|
19
|
-
class
|
20
|
-
|
21
|
-
|
22
|
-
def initialize(owner, request)
|
23
|
-
@owner = owner
|
17
|
+
class ResponseNormalizer
|
18
|
+
def initialize(request, response)
|
24
19
|
@request = request
|
20
|
+
@response = response
|
25
21
|
end
|
26
22
|
|
27
|
-
def
|
28
|
-
|
29
|
-
end
|
30
|
-
|
31
|
-
private
|
32
|
-
def execute_commands
|
33
|
-
client = Droonga::Client.new(tag: owner.tag, port: owner.port)
|
34
|
-
client.connection.send(request, :response => :one)
|
35
|
-
end
|
23
|
+
def normalize
|
24
|
+
return @response if @response.nil?
|
36
25
|
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
normalize_envelope!(normalized_result)
|
42
|
-
normalize_body!(normalized_result)
|
43
|
-
normalized_result
|
26
|
+
normalized_response = @response.dup
|
27
|
+
normalize_envelope!(normalized_response)
|
28
|
+
normalize_body!(normalized_response)
|
29
|
+
normalized_response
|
44
30
|
end
|
45
31
|
|
46
|
-
|
32
|
+
private
|
33
|
+
def normalize_envelope!(normalized_response)
|
47
34
|
normalized_start_time = 0
|
48
|
-
|
35
|
+
normalized_response[1] = normalized_start_time
|
49
36
|
end
|
50
37
|
|
51
|
-
def normalize_body!(
|
38
|
+
def normalize_body!(normalized_response)
|
52
39
|
return unless groonga_command?
|
53
40
|
begin
|
54
|
-
|
41
|
+
normalize_groonga_command_response!(normalized_response[2])
|
55
42
|
rescue StandardError => error
|
56
43
|
p error
|
57
|
-
normalized_result
|
58
44
|
end
|
59
45
|
end
|
60
46
|
|
@@ -64,11 +50,11 @@ module Drntest
|
|
64
50
|
"select",
|
65
51
|
]
|
66
52
|
def groonga_command?
|
67
|
-
GROONGA_COMMANDS.include?(request["type"])
|
53
|
+
GROONGA_COMMANDS.include?(@request["type"])
|
68
54
|
end
|
69
55
|
|
70
|
-
def
|
71
|
-
normalize_groonga_command_header!(
|
56
|
+
def normalize_groonga_command_response!(response)
|
57
|
+
normalize_groonga_command_header!(response["body"][0])
|
72
58
|
end
|
73
59
|
|
74
60
|
def normalize_groonga_command_header!(header)
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "droonga/client"
|
17
|
+
|
18
|
+
require "drntest/test-loader"
|
19
|
+
require "drntest/response-normalizer"
|
20
|
+
|
21
|
+
module Drntest
|
22
|
+
class TestExecutor
|
23
|
+
attr_reader :owner, :test_path
|
24
|
+
|
25
|
+
def initialize(owner, test_path)
|
26
|
+
@owner = owner
|
27
|
+
@test_path = test_path
|
28
|
+
end
|
29
|
+
|
30
|
+
def execute
|
31
|
+
Droonga::Client.open(tag: owner.tag, port: owner.port) do |client|
|
32
|
+
context = Context.new(client)
|
33
|
+
operations.each do |operation|
|
34
|
+
context.execute(operation)
|
35
|
+
end
|
36
|
+
context.finish
|
37
|
+
context.responses
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
def operations
|
43
|
+
loader = TestLoader.new(@owner, @test_path)
|
44
|
+
loader.load
|
45
|
+
end
|
46
|
+
|
47
|
+
class Context
|
48
|
+
attr_reader :responses
|
49
|
+
|
50
|
+
def initialize(client)
|
51
|
+
@client = client
|
52
|
+
@requests = []
|
53
|
+
@responses = []
|
54
|
+
@logging = true
|
55
|
+
end
|
56
|
+
|
57
|
+
def execute(operation)
|
58
|
+
case operation
|
59
|
+
when Directive
|
60
|
+
execute_directive(operation)
|
61
|
+
else
|
62
|
+
execute_request(operation)
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def finish
|
67
|
+
consume_requests
|
68
|
+
end
|
69
|
+
|
70
|
+
private
|
71
|
+
def execute_directive(directive)
|
72
|
+
case directive.type
|
73
|
+
when :enable_logging
|
74
|
+
@logging = true
|
75
|
+
consume_requests
|
76
|
+
when :disable_logging
|
77
|
+
@logging = false
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
def execute_request(request)
|
82
|
+
if @logging
|
83
|
+
response = @client.connection.execute(request)
|
84
|
+
@responses << normalize_response(request, response)
|
85
|
+
else
|
86
|
+
@requests << @client.connection.execute(request,
|
87
|
+
:connect_timeout => 2) do
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
91
|
+
|
92
|
+
def consume_requests
|
93
|
+
@requests.each do |request|
|
94
|
+
request.wait
|
95
|
+
end
|
96
|
+
@requests.clear
|
97
|
+
end
|
98
|
+
|
99
|
+
def normalize_response(request, response)
|
100
|
+
normalizer = ResponseNormalizer.new(request, response)
|
101
|
+
normalizer.normalize
|
102
|
+
end
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|
@@ -0,0 +1,74 @@
|
|
1
|
+
# Copyright (C) 2013 Droonga Project
|
2
|
+
#
|
3
|
+
# This program is free software: you can redistribute it and/or modify
|
4
|
+
# it under the terms of the GNU General Public License as published by
|
5
|
+
# the Free Software Foundation, either version 3 of the License, or
|
6
|
+
# (at your option) any later version.
|
7
|
+
#
|
8
|
+
# This program is distributed in the hope that it will be useful,
|
9
|
+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
10
|
+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
11
|
+
# GNU General Public License for more details.
|
12
|
+
#
|
13
|
+
# You should have received a copy of the GNU General Public License
|
14
|
+
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
15
|
+
|
16
|
+
require "drntest/json-loader"
|
17
|
+
require "drntest/directive"
|
18
|
+
|
19
|
+
module Drntest
|
20
|
+
class TestLoader
|
21
|
+
attr_reader :owner, :test_path
|
22
|
+
|
23
|
+
def initialize(owner, test_path)
|
24
|
+
@owner = owner
|
25
|
+
@test_path = test_path
|
26
|
+
end
|
27
|
+
|
28
|
+
def load
|
29
|
+
load_test_file(@test_path)
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
def resolve_relative_path(path)
|
34
|
+
path = path.to_s
|
35
|
+
path = path[2..-1] if path[0..1] == "./"
|
36
|
+
Pathname(path).expand_path(@owner.base_path)
|
37
|
+
end
|
38
|
+
|
39
|
+
def load_test_file(path)
|
40
|
+
parser = Yajl::Parser.new
|
41
|
+
operations = []
|
42
|
+
parser.on_parse_complete = lambda do |operation|
|
43
|
+
operations << operation
|
44
|
+
end
|
45
|
+
data = ""
|
46
|
+
Pathname(path).read.each_line do |line|
|
47
|
+
data << line
|
48
|
+
case line.chomp
|
49
|
+
when /\A\#\@([^\s]+)(?:\s+(.+))?\z/
|
50
|
+
type = $1
|
51
|
+
value = $2
|
52
|
+
directive = Directive.new(type, value)
|
53
|
+
if directive.type == :include
|
54
|
+
included = resolve_relative_path(directive.value)
|
55
|
+
included_operations = load_test_file(included)
|
56
|
+
operations += included_operations
|
57
|
+
else
|
58
|
+
operations << directive
|
59
|
+
end
|
60
|
+
when /\A\#/
|
61
|
+
# comment
|
62
|
+
else
|
63
|
+
begin
|
64
|
+
parser << line
|
65
|
+
rescue Yajl::ParseError => error
|
66
|
+
JSONLoader.report_error(path, data, error)
|
67
|
+
raise error
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
operations
|
72
|
+
end
|
73
|
+
end
|
74
|
+
end
|
data/lib/drntest/test-runner.rb
CHANGED
@@ -17,10 +17,13 @@ require "json"
|
|
17
17
|
require "yajl"
|
18
18
|
require "tempfile"
|
19
19
|
require "pp"
|
20
|
-
require "drntest/test-results"
|
21
|
-
require "drntest/executor"
|
22
20
|
require "fileutils"
|
23
21
|
|
22
|
+
require "drntest/path"
|
23
|
+
require "drntest/test-results"
|
24
|
+
require "drntest/test-executor"
|
25
|
+
require "drntest/json-loader"
|
26
|
+
|
24
27
|
module Drntest
|
25
28
|
class TestRunner
|
26
29
|
attr_reader :owner, :base_path, :target_path
|
@@ -44,7 +47,7 @@ module Drntest
|
|
44
47
|
end
|
45
48
|
|
46
49
|
def config_dir
|
47
|
-
(@base_path +
|
50
|
+
(@base_path + Path::CONFIG) + @owner.config
|
48
51
|
end
|
49
52
|
|
50
53
|
def config_file
|
@@ -68,12 +71,6 @@ module Drntest
|
|
68
71
|
end
|
69
72
|
|
70
73
|
private
|
71
|
-
def resolve_relative_path(path, base)
|
72
|
-
path = path.to_s
|
73
|
-
path = path[2..-1] if path[0..1] == "./"
|
74
|
-
Pathname(path).expand_path(base)
|
75
|
-
end
|
76
|
-
|
77
74
|
def prepare
|
78
75
|
if catalog_file.exist?
|
79
76
|
catalog_json = JSON.parse(catalog_file.read, :symbolize_names => true)
|
@@ -88,8 +85,7 @@ module Drntest
|
|
88
85
|
def setup
|
89
86
|
return unless temporary_engine?
|
90
87
|
|
91
|
-
|
92
|
-
FileUtils.mkdir_p(temporary_dir)
|
88
|
+
setup_temporary_dir
|
93
89
|
|
94
90
|
temporary_config = temporary_dir + "fluentd.conf"
|
95
91
|
FileUtils.cp(config_file, temporary_config)
|
@@ -102,8 +98,6 @@ module Drntest
|
|
102
98
|
*@owner.fluentd_options,
|
103
99
|
]
|
104
100
|
engine_env = {
|
105
|
-
"RUBYOPT" => nil,
|
106
|
-
"BUNDLE_GEMFILE" => nil,
|
107
101
|
"DROONGA_CATALOG" => temporary_catalog.to_s,
|
108
102
|
}
|
109
103
|
engine_options = {
|
@@ -123,11 +117,29 @@ module Drntest
|
|
123
117
|
Process.kill(:TERM, @engine_pid)
|
124
118
|
Process.wait(@engine_pid)
|
125
119
|
|
120
|
+
teardown_temporary_dir
|
121
|
+
end
|
122
|
+
|
123
|
+
def setup_temporary_dir
|
124
|
+
tmpfs = Pathname("/run/shm")
|
125
|
+
if tmpfs.directory? and tmpfs.writable?
|
126
|
+
FileUtils.rm_rf(temporary_base_dir)
|
127
|
+
FileUtils.ln_s(tmpfs.to_s, temporary_base_dir.to_s)
|
128
|
+
end
|
129
|
+
FileUtils.rm_rf(temporary_dir)
|
130
|
+
FileUtils.mkdir_p(temporary_dir)
|
131
|
+
end
|
132
|
+
|
133
|
+
def teardown_temporary_dir
|
126
134
|
FileUtils.rm_rf(temporary_dir.to_s)
|
127
135
|
end
|
128
136
|
|
137
|
+
def temporary_base_dir
|
138
|
+
@base_path + "tmp"
|
139
|
+
end
|
140
|
+
|
129
141
|
def temporary_dir
|
130
|
-
|
142
|
+
temporary_base_dir + "drntest"
|
131
143
|
end
|
132
144
|
|
133
145
|
def temporary_engine?
|
@@ -137,21 +149,8 @@ module Drntest
|
|
137
149
|
def process_requests
|
138
150
|
results = TestResults.new(@target_path)
|
139
151
|
|
140
|
-
|
141
|
-
|
142
|
-
if request.is_a?(Directive)
|
143
|
-
case request.type
|
144
|
-
when :enable_logging
|
145
|
-
logging = true
|
146
|
-
when :disable_logging
|
147
|
-
logging = false
|
148
|
-
end
|
149
|
-
next
|
150
|
-
end
|
151
|
-
executor = Executor.new(self, request)
|
152
|
-
response = executor.execute
|
153
|
-
results.actuals << response if logging
|
154
|
-
end
|
152
|
+
executor = TestExecutor.new(self, @target_path)
|
153
|
+
results.actuals = executor.execute
|
155
154
|
if expected_exist?
|
156
155
|
results.expecteds = load_expected_responses
|
157
156
|
end
|
@@ -174,61 +173,13 @@ module Drntest
|
|
174
173
|
results
|
175
174
|
end
|
176
175
|
|
177
|
-
def load_request_envelopes
|
178
|
-
load_jsons(@target_path)
|
179
|
-
end
|
180
|
-
|
181
176
|
def load_expected_responses
|
182
177
|
load_jsons(expected_path)
|
183
178
|
end
|
184
179
|
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
class << self
|
189
|
-
def directive?(source)
|
190
|
-
MATCHER =~ source.strip
|
191
|
-
end
|
192
|
-
end
|
193
|
-
|
194
|
-
attr_reader :type, :value
|
195
|
-
|
196
|
-
def initialize(source)
|
197
|
-
MATCHER =~ source.strip
|
198
|
-
@value = $2
|
199
|
-
@type = $1.gsub("-", "_").to_sym
|
200
|
-
end
|
201
|
-
end
|
202
|
-
|
203
|
-
def load_jsons(path, options={})
|
204
|
-
parser = Yajl::Parser.new
|
205
|
-
json_objects = []
|
206
|
-
parser.on_parse_complete = Proc.new do |json_object|
|
207
|
-
json_objects << json_object
|
208
|
-
end
|
209
|
-
Pathname(path).read.each_line do |line|
|
210
|
-
if line[0] == "#"
|
211
|
-
if Directive.directive?(line)
|
212
|
-
directive = Directive.new(line)
|
213
|
-
if directive.type == :include
|
214
|
-
included = resolve_relative_path(directive.value,
|
215
|
-
options[:base_path] || @base_path)
|
216
|
-
included_jsons = load_jsons(included)
|
217
|
-
json_objects += included_jsons
|
218
|
-
else
|
219
|
-
json_objects << directive
|
220
|
-
end
|
221
|
-
end
|
222
|
-
else
|
223
|
-
begin
|
224
|
-
parser << line
|
225
|
-
rescue StandardError => error
|
226
|
-
p "Failed to load JSONs file: #{path.to_s}"
|
227
|
-
raise error
|
228
|
-
end
|
229
|
-
end
|
230
|
-
end
|
231
|
-
json_objects
|
180
|
+
def load_jsons(path)
|
181
|
+
loader = JSONLoader.new
|
182
|
+
loader.load(path)
|
232
183
|
end
|
233
184
|
|
234
185
|
def expected_exist?
|
@@ -263,37 +214,17 @@ module Drntest
|
|
263
214
|
puts "Saving received results as #{output_path}"
|
264
215
|
File.open(output_path, "w") do |file|
|
265
216
|
results.each do |result|
|
266
|
-
|
267
|
-
json = JSON.pretty_generate(result)
|
268
|
-
file.puts(json)
|
269
|
-
rescue JSON::GeneratorError => error
|
270
|
-
p error
|
271
|
-
p result
|
272
|
-
end
|
217
|
+
file.puts(format_result(result))
|
273
218
|
end
|
274
219
|
end
|
275
220
|
end
|
276
221
|
|
277
222
|
def show_diff(expecteds, actuals)
|
278
|
-
|
279
|
-
|
280
|
-
JSON.pretty_generate(expected)
|
281
|
-
rescue JSON::GeneratorError => error
|
282
|
-
p error
|
283
|
-
p expected
|
284
|
-
end
|
285
|
-
end.join("\n")
|
286
|
-
actual_pretty = actuals.collect do |actual|
|
287
|
-
begin
|
288
|
-
JSON.pretty_generate(actual)
|
289
|
-
rescue JSON::GeneratorError => error
|
290
|
-
p error
|
291
|
-
p actual
|
292
|
-
end
|
293
|
-
end.join("\n")
|
223
|
+
formatted_expected = format_results(expecteds)
|
224
|
+
formatted_actual = format_results(actuals)
|
294
225
|
|
295
|
-
create_temporary_file("expected",
|
296
|
-
create_temporary_file("actual",
|
226
|
+
create_temporary_file("expected", formatted_expected) do |expected_file|
|
227
|
+
create_temporary_file("actual", formatted_actual) do |actual_file|
|
297
228
|
diff_options = [
|
298
229
|
"-u",
|
299
230
|
"--label", "(expected)", expected_file.path,
|
@@ -304,6 +235,24 @@ module Drntest
|
|
304
235
|
end
|
305
236
|
end
|
306
237
|
|
238
|
+
def format_results(results)
|
239
|
+
formatted_results = ""
|
240
|
+
results.each do |result|
|
241
|
+
formatted_results << format_result(result)
|
242
|
+
formatted_results << "\n"
|
243
|
+
end
|
244
|
+
formatted_results
|
245
|
+
end
|
246
|
+
|
247
|
+
def format_result(result)
|
248
|
+
return "" if result.nil?
|
249
|
+
begin
|
250
|
+
JSON.pretty_generate(result)
|
251
|
+
rescue JSON::GeneratorError
|
252
|
+
result.inspect
|
253
|
+
end
|
254
|
+
end
|
255
|
+
|
307
256
|
def create_temporary_file(key, content)
|
308
257
|
file = Tempfile.new("drntest-#{key}")
|
309
258
|
file.write(content)
|
data/lib/drntest/tester.rb
CHANGED
@@ -16,7 +16,9 @@
|
|
16
16
|
require "shellwords"
|
17
17
|
require "optparse"
|
18
18
|
require "pathname"
|
19
|
+
|
19
20
|
require "drntest/version"
|
21
|
+
require "drntest/path"
|
20
22
|
require "drntest/test-runner"
|
21
23
|
require "drntest/test-suites-result"
|
22
24
|
|
@@ -28,7 +30,6 @@ module Drntest
|
|
28
30
|
tester = new
|
29
31
|
option_parser = create_option_parser(tester)
|
30
32
|
targets = option_parser.parse!(argv)
|
31
|
-
targets << tester.base_path + "suite" if targets.empty?
|
32
33
|
tester.run(*targets)
|
33
34
|
end
|
34
35
|
|
@@ -56,7 +57,7 @@ module Drntest
|
|
56
57
|
tester.tag = tag
|
57
58
|
end
|
58
59
|
|
59
|
-
parser.on("--base=PATH",
|
60
|
+
parser.on("--base-path=PATH",
|
60
61
|
"Path to the base directory including test suite, config and fixture",
|
61
62
|
"(#{tester.base_path})") do |base_path|
|
62
63
|
tester.base_path = Pathname(base_path).expand_path(Dir.pwd)
|
@@ -140,6 +141,9 @@ module Drntest
|
|
140
141
|
end
|
141
142
|
|
142
143
|
def load_tests(*targets)
|
144
|
+
suite_path = @base_path + Path::SUITE
|
145
|
+
targets << suite_path if targets.empty?
|
146
|
+
|
143
147
|
tests = []
|
144
148
|
targets.each do |target|
|
145
149
|
target_path = Pathname(target)
|
@@ -159,7 +163,8 @@ module Drntest
|
|
159
163
|
|
160
164
|
unless @suite_pattern.nil?
|
161
165
|
tests.select! do |test|
|
162
|
-
|
166
|
+
test_suite_name = test.relative_path_from(suite_path).dirname.to_s
|
167
|
+
@suite_pattern === test_suite_name
|
163
168
|
end
|
164
169
|
end
|
165
170
|
|
data/lib/drntest/version.rb
CHANGED
metadata
CHANGED
@@ -1,83 +1,83 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: drntest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Droonga Project
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: json
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- -
|
17
|
+
- - '>='
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '0'
|
20
20
|
type: :runtime
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- -
|
24
|
+
- - '>='
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: yajl-ruby
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - '>='
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - '>='
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: droonga-client
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - '>='
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version:
|
47
|
+
version: 0.1.0
|
48
48
|
type: :runtime
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - '>='
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version:
|
54
|
+
version: 0.1.0
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: bundler
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - '>='
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - '>='
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - '>='
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
description: ''
|
@@ -88,17 +88,22 @@ executables:
|
|
88
88
|
extensions: []
|
89
89
|
extra_rdoc_files: []
|
90
90
|
files:
|
91
|
-
- Gemfile
|
92
91
|
- README.md
|
93
92
|
- Rakefile
|
94
|
-
-
|
93
|
+
- Gemfile
|
95
94
|
- drntest.gemspec
|
96
|
-
- lib/drntest/executor.rb
|
97
95
|
- lib/drntest/test-results.rb
|
98
|
-
- lib/drntest/
|
96
|
+
- lib/drntest/version.rb
|
97
|
+
- lib/drntest/directive.rb
|
99
98
|
- lib/drntest/test-suites-result.rb
|
99
|
+
- lib/drntest/json-loader.rb
|
100
|
+
- lib/drntest/test-loader.rb
|
100
101
|
- lib/drntest/tester.rb
|
101
|
-
- lib/drntest/
|
102
|
+
- lib/drntest/path.rb
|
103
|
+
- lib/drntest/response-normalizer.rb
|
104
|
+
- lib/drntest/test-runner.rb
|
105
|
+
- lib/drntest/test-executor.rb
|
106
|
+
- bin/drntest
|
102
107
|
homepage: https://github.com/droonga/drntest
|
103
108
|
licenses:
|
104
109
|
- GPLv3 or later
|
@@ -109,17 +114,17 @@ require_paths:
|
|
109
114
|
- lib
|
110
115
|
required_ruby_version: !ruby/object:Gem::Requirement
|
111
116
|
requirements:
|
112
|
-
- -
|
117
|
+
- - '>='
|
113
118
|
- !ruby/object:Gem::Version
|
114
119
|
version: '0'
|
115
120
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
116
121
|
requirements:
|
117
|
-
- -
|
122
|
+
- - '>='
|
118
123
|
- !ruby/object:Gem::Version
|
119
124
|
version: '0'
|
120
125
|
requirements: []
|
121
126
|
rubyforge_project:
|
122
|
-
rubygems_version: 2.
|
127
|
+
rubygems_version: 2.0.14
|
123
128
|
signing_key:
|
124
129
|
specification_version: 4
|
125
130
|
summary: Drntest is a testing framework for Droonga. You can write a test for Droonga
|