kronk 1.5.4 → 1.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/History.rdoc +14 -0
- data/Manifest.txt +8 -2
- data/README.rdoc +6 -0
- data/TODO.rdoc +12 -0
- data/lib/kronk.rb +6 -2
- data/lib/kronk/cmd.rb +18 -2
- data/lib/kronk/constants.rb +1 -0
- data/lib/kronk/data_renderer.rb +95 -22
- data/lib/kronk/diff.rb +18 -64
- data/lib/kronk/diff/ascii_format.rb +11 -0
- data/lib/kronk/diff/color_format.rb +14 -2
- data/lib/kronk/diff/output.rb +155 -0
- data/lib/kronk/path.rb +48 -153
- data/lib/kronk/path/matcher.rb +189 -0
- data/lib/kronk/path/path_match.rb +74 -0
- data/lib/kronk/path/transaction.rb +157 -47
- data/lib/kronk/player/benchmark.rb +2 -1
- data/lib/kronk/player/suite.rb +8 -0
- data/lib/kronk/response.rb +7 -6
- data/test/test_cmd.rb +29 -8
- data/test/test_data_string.rb +58 -0
- data/test/test_diff.rb +137 -36
- data/test/test_helper.rb +2 -0
- data/test/test_kronk.rb +19 -3
- data/test/test_path.rb +87 -170
- data/test/test_path_match.rb +60 -0
- data/test/test_path_matcher.rb +329 -0
- data/test/test_response.rb +10 -10
- data/test/test_transaction.rb +132 -3
- metadata +82 -75
data/test/test_helper.rb
CHANGED
data/test/test_kronk.rb
CHANGED
@@ -10,6 +10,7 @@ class TestKronk < Test::Unit::TestCase
|
|
10
10
|
'plist' => 'PlistParser',
|
11
11
|
'xml' => 'XMLParser'
|
12
12
|
},
|
13
|
+
:context => nil,
|
13
14
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
14
15
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
15
16
|
:history_file => Kronk::DEFAULT_HISTORY_FILE,
|
@@ -34,6 +35,7 @@ class TestKronk < Test::Unit::TestCase
|
|
34
35
|
'soap' => "SOAPParser",
|
35
36
|
'js' => "JsEngine"
|
36
37
|
},
|
38
|
+
:context => 3,
|
37
39
|
:ignore_headers => ["Content-Type"],
|
38
40
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
39
41
|
:cookies_file => Kronk::DEFAULT_COOKIES_FILE,
|
@@ -65,6 +67,7 @@ class TestKronk < Test::Unit::TestCase
|
|
65
67
|
'plist' => "PlistParser",
|
66
68
|
'xml' => "XMLParser"
|
67
69
|
},
|
70
|
+
:context => 3,
|
68
71
|
:default_host => "http://localhost:3000",
|
69
72
|
:diff_format => :ascii_diff,
|
70
73
|
:cache_file => Kronk::DEFAULT_CACHE_FILE,
|
@@ -371,7 +374,11 @@ class TestKronk < Test::Unit::TestCase
|
|
371
374
|
:raw => true
|
372
375
|
|
373
376
|
exp_diff = Kronk::Diff.new resp1.selective_string(:with_headers => true),
|
374
|
-
resp2.selective_string(:with_headers => true)
|
377
|
+
resp2.selective_string(:with_headers => true),
|
378
|
+
:labels => [
|
379
|
+
"test/mocks/200_response.json",
|
380
|
+
"test/mocks/200_response.xml"
|
381
|
+
]
|
375
382
|
|
376
383
|
assert_equal exp_diff.formatted, diff.formatted
|
377
384
|
end
|
@@ -447,7 +454,11 @@ class TestKronk < Test::Unit::TestCase
|
|
447
454
|
|
448
455
|
exp_diff = Kronk::Diff.new_from_data \
|
449
456
|
resp1.selective_data(:with_headers => true),
|
450
|
-
resp2.selective_data(:with_headers => true)
|
457
|
+
resp2.selective_data(:with_headers => true),
|
458
|
+
:labels => [
|
459
|
+
"test/mocks/200_response.json",
|
460
|
+
"test/mocks/200_response.xml"
|
461
|
+
]
|
451
462
|
|
452
463
|
assert_equal exp_diff.formatted, diff.formatted
|
453
464
|
end
|
@@ -535,7 +546,12 @@ class TestKronk < Test::Unit::TestCase
|
|
535
546
|
|
536
547
|
exp_diff = Kronk::Diff.new_from_data \
|
537
548
|
resp2.selective_data(:with_headers => true),
|
538
|
-
resp1.selective_data(:with_headers => true)
|
549
|
+
resp1.selective_data(:with_headers => true),
|
550
|
+
:labels => [
|
551
|
+
"test/mocks/200_response.json",
|
552
|
+
"test/mocks/200_response.xml"
|
553
|
+
]
|
554
|
+
|
539
555
|
|
540
556
|
assert_equal exp_diff.formatted, diff.formatted
|
541
557
|
end
|
data/test/test_path.rb
CHANGED
@@ -26,113 +26,6 @@ class TestPath < Test::Unit::TestCase
|
|
26
26
|
end
|
27
27
|
|
28
28
|
|
29
|
-
def test_each_data_item_hash
|
30
|
-
hash = {
|
31
|
-
:a => 1,
|
32
|
-
:b => 2,
|
33
|
-
:c => 3
|
34
|
-
}
|
35
|
-
|
36
|
-
keys = []
|
37
|
-
values = []
|
38
|
-
|
39
|
-
Kronk::Path.each_data_item hash do |key, val|
|
40
|
-
keys << key
|
41
|
-
values << val
|
42
|
-
end
|
43
|
-
|
44
|
-
assert_equal keys, (keys | hash.keys)
|
45
|
-
assert_equal values, (values | hash.values)
|
46
|
-
end
|
47
|
-
|
48
|
-
|
49
|
-
def test_each_data_item_array
|
50
|
-
ary = [:a, :b, :c]
|
51
|
-
|
52
|
-
keys = []
|
53
|
-
values = []
|
54
|
-
|
55
|
-
Kronk::Path.each_data_item ary do |key, val|
|
56
|
-
keys << key
|
57
|
-
values << val
|
58
|
-
end
|
59
|
-
|
60
|
-
assert_equal [2,1,0], keys
|
61
|
-
assert_equal ary.reverse, values
|
62
|
-
end
|
63
|
-
|
64
|
-
|
65
|
-
def test_match_data_item
|
66
|
-
assert Kronk::Path.match_data_item(:key, "key")
|
67
|
-
assert Kronk::Path.match_data_item("key", :key)
|
68
|
-
|
69
|
-
assert Kronk::Path.match_data_item(/key/, "foo_key")
|
70
|
-
assert !Kronk::Path.match_data_item("foo_key", /key/)
|
71
|
-
assert Kronk::Path.match_data_item(/key/, /key/)
|
72
|
-
|
73
|
-
assert Kronk::Path.match_data_item(Kronk::Path::ANY_VALUE, "foo_key")
|
74
|
-
assert !Kronk::Path.match_data_item("foo_key", Kronk::Path::ANY_VALUE)
|
75
|
-
|
76
|
-
assert Kronk::Path.match_data_item(1..3, 1)
|
77
|
-
assert !Kronk::Path.match_data_item(1, 1..3)
|
78
|
-
assert Kronk::Path.match_data_item(1..3, 1..3)
|
79
|
-
end
|
80
|
-
|
81
|
-
|
82
|
-
def test_find_match
|
83
|
-
keys = []
|
84
|
-
|
85
|
-
Kronk::Path.find_match @data, /key/ do |data, key|
|
86
|
-
keys << key.to_s
|
87
|
-
assert_equal @data, data
|
88
|
-
end
|
89
|
-
|
90
|
-
assert_equal ['key1', 'key2', 'key3'], keys.sort
|
91
|
-
end
|
92
|
-
|
93
|
-
|
94
|
-
def test_find_match_recursive
|
95
|
-
keys = []
|
96
|
-
data_points = []
|
97
|
-
|
98
|
-
Kronk::Path.find_match @data, :findme, ANY_VALUE, true do |data, key|
|
99
|
-
keys << key.to_s
|
100
|
-
data_points << data
|
101
|
-
end
|
102
|
-
|
103
|
-
assert_equal 3, keys.length
|
104
|
-
assert_equal 1, keys.uniq.length
|
105
|
-
assert_equal "findme", keys.first
|
106
|
-
|
107
|
-
assert_equal 3, data_points.length
|
108
|
-
assert data_points.include?(@data)
|
109
|
-
assert data_points.include?({:findme => "thing"})
|
110
|
-
assert data_points.include?({:findme => 123456})
|
111
|
-
end
|
112
|
-
|
113
|
-
|
114
|
-
def test_find_match_value
|
115
|
-
keys = []
|
116
|
-
data_points = []
|
117
|
-
|
118
|
-
Kronk::Path.find_match @data, ANY_VALUE, "findme" do |data, key|
|
119
|
-
keys << key.to_s
|
120
|
-
data_points << data
|
121
|
-
end
|
122
|
-
|
123
|
-
assert keys.empty?
|
124
|
-
assert data_points.empty?
|
125
|
-
|
126
|
-
Kronk::Path.find_match @data, ANY_VALUE, "findme", true do |data, key|
|
127
|
-
keys << key.to_s
|
128
|
-
data_points << data
|
129
|
-
end
|
130
|
-
|
131
|
-
assert_equal ['key1b'], keys
|
132
|
-
assert_equal [@data[:key1]], data_points
|
133
|
-
end
|
134
|
-
|
135
|
-
|
136
29
|
def test_find_wildcard
|
137
30
|
keys = []
|
138
31
|
data_points = []
|
@@ -206,61 +99,86 @@ class TestPath < Test::Unit::TestCase
|
|
206
99
|
end
|
207
100
|
|
208
101
|
|
209
|
-
def
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
assert_equal
|
225
|
-
assert_equal "2,4", Kronk::Path.parse_path_item("2,4\\")
|
226
|
-
end
|
227
|
-
|
228
|
-
|
229
|
-
def test_parse_path_item_anyval
|
230
|
-
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item("*")
|
231
|
-
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item("")
|
232
|
-
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item("**?*?*?")
|
233
|
-
assert_equal Kronk::Path::ANY_VALUE, Kronk::Path.parse_path_item(nil)
|
102
|
+
def test_pathed
|
103
|
+
expected = {
|
104
|
+
"/findme/0" => 123,
|
105
|
+
"/findme/1" => 456,
|
106
|
+
"/findme/2/findme" => 123456,
|
107
|
+
"/key1/key1a/0" => "foo",
|
108
|
+
"/key1/key1a/1" => "bar",
|
109
|
+
"/key1/key1a/2" => "foobar",
|
110
|
+
"/key1/key1a/3/findme" => "thing",
|
111
|
+
"/key1/key1b" => "findme",
|
112
|
+
"/key2" => "foobar",
|
113
|
+
"/key3/key3a/0" => "val1",
|
114
|
+
"/key3/key3a/1" => "val2",
|
115
|
+
"/key3/key3a/2" => "val3"
|
116
|
+
}
|
117
|
+
assert_equal expected, Kronk::Path.pathed(@data)
|
234
118
|
end
|
235
119
|
|
236
120
|
|
237
|
-
def
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
assert_equal(/\A(a|b(c|d))\Z/, Kronk::Path.parse_path_item("a|b(c|d)"))
|
245
|
-
|
246
|
-
assert_equal(/\A(a|b(c|d))\Z/i,
|
247
|
-
Kronk::Path.parse_path_item("a|b(c|d)", Regexp::IGNORECASE))
|
248
|
-
end
|
249
|
-
|
121
|
+
def test_pathed_esc
|
122
|
+
@data['findme'][2]['*thing?'] = {
|
123
|
+
".." => "parent",
|
124
|
+
"**" => "recurse",
|
125
|
+
"(hi|hey)" => "paren",
|
126
|
+
"more/here" => "path"
|
127
|
+
}
|
250
128
|
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
129
|
+
expected = {
|
130
|
+
"/findme/0" => 123,
|
131
|
+
"/findme/1" => 456,
|
132
|
+
"/findme/2/findme" => 123456,
|
133
|
+
|
134
|
+
"/findme/2/\\*thing\\?/\\.\\." => "parent",
|
135
|
+
"/findme/2/\\*thing\\?/\\*\\*" => "recurse",
|
136
|
+
"/findme/2/\\*thing\\?/\\(hi\\|hey\\)" => "paren",
|
137
|
+
"/findme/2/\\*thing\\?/more\\/here" => "path",
|
138
|
+
|
139
|
+
"/key1/key1a/0" => "foo",
|
140
|
+
"/key1/key1a/1" => "bar",
|
141
|
+
"/key1/key1a/2" => "foobar",
|
142
|
+
"/key1/key1a/3/findme" => "thing",
|
143
|
+
"/key1/key1b" => "findme",
|
144
|
+
"/key2" => "foobar",
|
145
|
+
"/key3/key3a/0" => "val1",
|
146
|
+
"/key3/key3a/1" => "val2",
|
147
|
+
"/key3/key3a/2" => "val3"
|
148
|
+
}
|
149
|
+
assert_equal expected, Kronk::Path.pathed(@data)
|
256
150
|
end
|
257
151
|
|
258
152
|
|
259
|
-
def
|
260
|
-
|
261
|
-
|
153
|
+
def test_pathed_not_esc
|
154
|
+
@data['findme'][2]['*thing?'] = {
|
155
|
+
".." => "parent",
|
156
|
+
"**" => "recurse",
|
157
|
+
"(hi|hey)" => "paren",
|
158
|
+
"more/here" => "path"
|
159
|
+
}
|
262
160
|
|
263
|
-
|
161
|
+
expected = {
|
162
|
+
"/findme/0" => 123,
|
163
|
+
"/findme/1" => 456,
|
164
|
+
"/findme/2/findme" => 123456,
|
165
|
+
|
166
|
+
"/findme/2/*thing?/.." => "parent",
|
167
|
+
"/findme/2/*thing?/**" => "recurse",
|
168
|
+
"/findme/2/*thing?/(hi|hey)" => "paren",
|
169
|
+
"/findme/2/*thing?/more/here" => "path",
|
170
|
+
|
171
|
+
"/key1/key1a/0" => "foo",
|
172
|
+
"/key1/key1a/1" => "bar",
|
173
|
+
"/key1/key1a/2" => "foobar",
|
174
|
+
"/key1/key1a/3/findme" => "thing",
|
175
|
+
"/key1/key1b" => "findme",
|
176
|
+
"/key2" => "foobar",
|
177
|
+
"/key3/key3a/0" => "val1",
|
178
|
+
"/key3/key3a/1" => "val2",
|
179
|
+
"/key3/key3a/2" => "val3"
|
180
|
+
}
|
181
|
+
assert_equal expected, Kronk::Path.pathed(@data, false)
|
264
182
|
end
|
265
183
|
|
266
184
|
|
@@ -272,9 +190,10 @@ class TestPath < Test::Unit::TestCase
|
|
272
190
|
end
|
273
191
|
|
274
192
|
expected = [
|
275
|
-
["path",
|
276
|
-
["to", "foo",
|
277
|
-
|
193
|
+
[Kronk::Path::Matcher.new(:key => "path"), false],
|
194
|
+
[Kronk::Path::Matcher.new(:key => "to", :value => "foo",
|
195
|
+
:recursive => true), false],
|
196
|
+
[Kronk::Path::Matcher.new(:key => "item"), true],
|
278
197
|
]
|
279
198
|
|
280
199
|
assert_equal expected, all_args
|
@@ -289,22 +208,22 @@ class TestPath < Test::Unit::TestCase
|
|
289
208
|
|
290
209
|
assert_path %w{path/to item/ i}, "path\\/to/item\\//i"
|
291
210
|
|
292
|
-
assert_path [/\
|
211
|
+
assert_path [/\Apath\/\.to\Z/i, /\Aitem\Z/i],
|
293
212
|
"path\\/.to/item", Regexp::IGNORECASE
|
294
213
|
|
295
|
-
assert_path ['path', /\
|
214
|
+
assert_path ['path', /\Ato|for\Z/, 'item'], "path/to|for/item"
|
296
215
|
end
|
297
216
|
|
298
217
|
|
299
218
|
def test_parse_path_str_value
|
300
219
|
assert_path ['path', ['to', 'foo'], 'item'], "path/to=foo/item"
|
301
|
-
assert_path ['path', [
|
220
|
+
assert_path ['path', ["*", 'foo'], 'item'], "path/*=foo/item"
|
302
221
|
assert_path ['path', [nil, 'foo'], 'item'], "path/=foo/item"
|
303
222
|
|
304
|
-
assert_path ['path', ['to', /\
|
223
|
+
assert_path ['path', ['to', /\Afoo|bar\Z/], 'item'],
|
305
224
|
"path/to=foo|bar/item"
|
306
225
|
|
307
|
-
assert_path [/\
|
226
|
+
assert_path [/\Apath\Z/i, [/\Ato\Z/i, /\Afoo\Z/i], /\Aitem\Z/i],
|
308
227
|
"path/to=foo/item", Regexp::IGNORECASE
|
309
228
|
end
|
310
229
|
|
@@ -312,15 +231,15 @@ class TestPath < Test::Unit::TestCase
|
|
312
231
|
def test_parse_path_str_recur
|
313
232
|
assert_path ['path', ['to', 'foo', true], 'item'], "path/**/to=foo/item"
|
314
233
|
assert_path [['path', nil, true], 'to', 'item'], "**/**/path/to/item"
|
315
|
-
assert_path ['path', 'to', 'item', [
|
316
|
-
assert_path ['path', [
|
234
|
+
assert_path ['path', 'to', 'item', ["*", nil, true]], "path/to/item/**/**"
|
235
|
+
assert_path ['path', ["*", 'foo', true], 'item'], "path/**=foo/item"
|
317
236
|
end
|
318
237
|
|
319
238
|
|
320
239
|
def test_parse_path_str_parent
|
321
240
|
assert_path ['path', PARENT, 'item'], "path/../item"
|
322
241
|
assert_path ['path', [PARENT, 'foo'], 'item'], "path/..=foo/item"
|
323
|
-
assert_path ['path', [
|
242
|
+
assert_path ['path', ["*", 'foo', true], 'item'], "path/**/..=foo/item"
|
324
243
|
assert_path ['path', [nil, 'foo', true], 'item'], "path/**/=foo/item"
|
325
244
|
assert_path ['path', ['item', nil, true]], "path/**/../item"
|
326
245
|
assert_path ['path', PARENT, ['item', nil, true]], "path/../**/item"
|
@@ -354,15 +273,13 @@ class TestPath < Test::Unit::TestCase
|
|
354
273
|
private
|
355
274
|
|
356
275
|
PARENT = Kronk::Path::PARENT
|
357
|
-
ANY_VALUE = Kronk::Path::ANY_VALUE
|
276
|
+
ANY_VALUE = Kronk::Path::Matcher::ANY_VALUE
|
358
277
|
|
359
278
|
def assert_path match, path, regexp_opt=nil
|
360
279
|
match.map! do |i|
|
361
280
|
i = [i] unless Array === i
|
362
|
-
i[0]
|
363
|
-
|
364
|
-
i[2] ||= false
|
365
|
-
i
|
281
|
+
Kronk::Path::Matcher.new :key => i[0], :value => i[1],
|
282
|
+
:recursive => i[2], :regex_opts => regexp_opt
|
366
283
|
end
|
367
284
|
|
368
285
|
assert_equal match, Kronk::Path.parse_path_str(path, regexp_opt)
|
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'test/test_helper'
|
2
|
+
|
3
|
+
class TestPathMatch < Test::Unit::TestCase
|
4
|
+
|
5
|
+
def setup
|
6
|
+
@pmatch = Kronk::Path::PathMatch.new %w{path to resource}
|
7
|
+
@pmatch.matches = %w{this is 4 foo}
|
8
|
+
end
|
9
|
+
|
10
|
+
|
11
|
+
def test_new
|
12
|
+
assert_equal %w{this is 4 foo}, @pmatch.matches
|
13
|
+
assert_equal %w{path to resource}, @pmatch
|
14
|
+
end
|
15
|
+
|
16
|
+
|
17
|
+
def test_dup
|
18
|
+
new_match = @pmatch.dup
|
19
|
+
assert_equal new_match, @pmatch
|
20
|
+
assert_not_equal @pmatch.matches.object_id, new_match.matches.object_id
|
21
|
+
assert_equal %w{this is 4 foo}, @pmatch.matches
|
22
|
+
assert_equal %w{this is 4 foo}, new_match.matches
|
23
|
+
end
|
24
|
+
|
25
|
+
|
26
|
+
def test_make_path
|
27
|
+
path = @pmatch.make_path "/%3/2/path/%4_%1"
|
28
|
+
assert_equal %w{4 2 path foo_this}, path
|
29
|
+
end
|
30
|
+
|
31
|
+
|
32
|
+
def test_make_path_bad_token
|
33
|
+
path = @pmatch.make_path "/%%3/2/path/%4_%1"
|
34
|
+
assert_equal %w{4 2 path foo_this}, path
|
35
|
+
end
|
36
|
+
|
37
|
+
|
38
|
+
def test_make_path_escape
|
39
|
+
path = @pmatch.make_path "/\\%3/2\\/path/%4_%1"
|
40
|
+
assert_equal %w{%3 2/path foo_this}, path
|
41
|
+
|
42
|
+
path = @pmatch.make_path "/\\\\%3/2/path/%4_%1/bar"
|
43
|
+
assert_equal %w{\4 2 path foo_this bar}, path
|
44
|
+
end
|
45
|
+
|
46
|
+
|
47
|
+
def test_make_path_escape_token_num
|
48
|
+
path = @pmatch.make_path "/%3\\1/2/path/%4_%1"
|
49
|
+
assert_equal %w{41 2 path foo_this}, path
|
50
|
+
|
51
|
+
path = @pmatch.make_path "/%\\31/2/path/%4_%1"
|
52
|
+
assert_equal %w{31 2 path foo_this}, path
|
53
|
+
end
|
54
|
+
|
55
|
+
|
56
|
+
def test_make_path_bad_token_num
|
57
|
+
path = @pmatch.make_path "/%31/2/path/%4_%1"
|
58
|
+
assert_equal ["", "2", "path", "foo_this"], path
|
59
|
+
end
|
60
|
+
end
|