wabur 0.1.0d2 → 0.2.0d1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +19 -16
- data/lib/wab/controller.rb +155 -106
- data/lib/wab/data.rb +8 -0
- data/lib/wab/errors.rb +13 -0
- data/lib/wab/impl/data.rb +49 -18
- data/lib/wab/impl/shell.rb +1 -1
- data/lib/wab/io/call.rb +23 -0
- data/lib/wab/io/engine.rb +118 -0
- data/lib/wab/io/shell.rb +141 -0
- data/lib/wab/io.rb +13 -0
- data/lib/wab/shell.rb +93 -16
- data/lib/wab/version.rb +1 -1
- data/lib/wab.rb +2 -1
- data/test/data_test.rb +6 -7
- data/test/impl_test.rb +1 -4
- data/test/ioshell_test.rb +461 -0
- data/test/tests.rb +12 -0
- metadata +13 -4
@@ -0,0 +1,461 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << __dir__
|
5
|
+
$: << File.join(File.dirname(File.expand_path(__dir__)), 'lib')
|
6
|
+
|
7
|
+
require 'minitest'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
|
10
|
+
require 'wab/impl'
|
11
|
+
require 'wab/io'
|
12
|
+
|
13
|
+
|
14
|
+
class IoEngineTest < Minitest::Test
|
15
|
+
|
16
|
+
class MirrorController < ::WAB::Controller
|
17
|
+
def initialize(shell)
|
18
|
+
super
|
19
|
+
end
|
20
|
+
|
21
|
+
def handle(data)
|
22
|
+
data
|
23
|
+
end
|
24
|
+
|
25
|
+
def create(path, query, data)
|
26
|
+
super
|
27
|
+
end
|
28
|
+
|
29
|
+
def read(path, query)
|
30
|
+
super
|
31
|
+
end
|
32
|
+
|
33
|
+
def update(path, query, data)
|
34
|
+
super
|
35
|
+
end
|
36
|
+
|
37
|
+
def delete(path, query)
|
38
|
+
super
|
39
|
+
end
|
40
|
+
|
41
|
+
end # MirrorController
|
42
|
+
|
43
|
+
def test_default_controller
|
44
|
+
run_fork_test([
|
45
|
+
[{
|
46
|
+
rid: 'rid-mirror',
|
47
|
+
api: 1,
|
48
|
+
body:{
|
49
|
+
kind: 'sample',
|
50
|
+
num: 7,
|
51
|
+
},
|
52
|
+
},
|
53
|
+
{rid:'rid-mirror', api:2, body:{kind:"sample", num:7}}]
|
54
|
+
])
|
55
|
+
end
|
56
|
+
|
57
|
+
def test_create
|
58
|
+
run_fork_test([
|
59
|
+
[{
|
60
|
+
rid: 'rid-create',
|
61
|
+
api: 1,
|
62
|
+
body:{
|
63
|
+
op: 'NEW',
|
64
|
+
path: [ 'sample' ],
|
65
|
+
content: {
|
66
|
+
kind: 'sample',
|
67
|
+
num: 7,
|
68
|
+
},
|
69
|
+
},
|
70
|
+
},
|
71
|
+
{rid: '1', api: 3, body:{ insert:{ kind: 'sample', num: 7}}}],
|
72
|
+
[{
|
73
|
+
rid: '1',
|
74
|
+
api: 4,
|
75
|
+
body:{
|
76
|
+
ref: 123,
|
77
|
+
code: 0,
|
78
|
+
},
|
79
|
+
},
|
80
|
+
{rid: 'rid-create', api: 2, body:{ ref: 123, code: 0 }}]
|
81
|
+
])
|
82
|
+
end
|
83
|
+
|
84
|
+
def test_create_with_where
|
85
|
+
run_fork_test([
|
86
|
+
[{
|
87
|
+
rid: 'rid-create-where',
|
88
|
+
api: 1,
|
89
|
+
body:{
|
90
|
+
op: 'NEW',
|
91
|
+
path: [ 'sample' ],
|
92
|
+
query: {
|
93
|
+
id: 12345
|
94
|
+
},
|
95
|
+
content: {
|
96
|
+
kind: 'sample',
|
97
|
+
id: 12345,
|
98
|
+
num: 7,
|
99
|
+
},
|
100
|
+
},
|
101
|
+
},
|
102
|
+
{
|
103
|
+
rid: '1',
|
104
|
+
api: 3,
|
105
|
+
body:{
|
106
|
+
where: ['AND', ['EQ', 'kind', "'sample"],['EQ', 'id', 12345]],
|
107
|
+
insert:{ kind: 'sample', id: 12345, num: 7}
|
108
|
+
}
|
109
|
+
}],
|
110
|
+
[{
|
111
|
+
rid: '1',
|
112
|
+
api: 4,
|
113
|
+
body:{
|
114
|
+
ref: 123,
|
115
|
+
code: 0,
|
116
|
+
},
|
117
|
+
},
|
118
|
+
{rid: 'rid-create-where', api: 2, body:{ ref: 123, code: 0 }}]
|
119
|
+
])
|
120
|
+
end
|
121
|
+
|
122
|
+
def test_create_error
|
123
|
+
run_fork_test([
|
124
|
+
[{
|
125
|
+
rid: 'rid-create',
|
126
|
+
api: 1,
|
127
|
+
body:{
|
128
|
+
op: 'NEW',
|
129
|
+
path: [ 'sample' ],
|
130
|
+
content: {
|
131
|
+
kind: 'sample',
|
132
|
+
num: 7,
|
133
|
+
},
|
134
|
+
},
|
135
|
+
},
|
136
|
+
{rid: '1', api: 3, body:{ insert:{ kind: 'sample', num: 7}}}],
|
137
|
+
[{
|
138
|
+
rid: '1',
|
139
|
+
api: 4,
|
140
|
+
body:{
|
141
|
+
ref: 123,
|
142
|
+
code: -1,
|
143
|
+
error: "something went wrong"
|
144
|
+
},
|
145
|
+
},
|
146
|
+
{rid: 'rid-create', api: 2, body:{ code: -1, error: "error on sample create. something went wrong" }}]
|
147
|
+
])
|
148
|
+
end
|
149
|
+
|
150
|
+
def test_read_by_id
|
151
|
+
run_fork_test([
|
152
|
+
[{
|
153
|
+
rid: 'rid-read-id',
|
154
|
+
api: 1,
|
155
|
+
body:{
|
156
|
+
op: 'GET',
|
157
|
+
path: [ 'sample', '12345' ]
|
158
|
+
},
|
159
|
+
},
|
160
|
+
{
|
161
|
+
rid: '1',
|
162
|
+
api: 3,
|
163
|
+
body:{
|
164
|
+
where: 12345,
|
165
|
+
select: '$'
|
166
|
+
}
|
167
|
+
}],
|
168
|
+
[{
|
169
|
+
rid: '1',
|
170
|
+
api: 4,
|
171
|
+
body:{
|
172
|
+
code: 0,
|
173
|
+
results:{
|
174
|
+
kind: 'sample',
|
175
|
+
id: 12345,
|
176
|
+
num: 7,
|
177
|
+
}
|
178
|
+
}
|
179
|
+
},
|
180
|
+
{rid: 'rid-read-id', api: 2, body:{ code: 0, results:[{ id: 12345, data: { kind: 'sample', id: 12345, num: 7}}]}}]
|
181
|
+
])
|
182
|
+
end
|
183
|
+
|
184
|
+
def test_read_by_attrs
|
185
|
+
run_fork_test([
|
186
|
+
[{
|
187
|
+
rid: 'rid-read-attrs',
|
188
|
+
api: 1,
|
189
|
+
body:{
|
190
|
+
op: 'GET',
|
191
|
+
path: [ 'sample' ],
|
192
|
+
query: {
|
193
|
+
id: 12345
|
194
|
+
}
|
195
|
+
}
|
196
|
+
},
|
197
|
+
{
|
198
|
+
rid: '1',
|
199
|
+
api: 3,
|
200
|
+
body:{
|
201
|
+
where: ['AND', ['EQ', 'kind', "'sample"],['EQ', 'id', 12345]],
|
202
|
+
select: { id: '$ref', data: '$' }
|
203
|
+
}
|
204
|
+
}],
|
205
|
+
[{
|
206
|
+
rid: '1',
|
207
|
+
api: 4,
|
208
|
+
body:{
|
209
|
+
code: 0,
|
210
|
+
results:[{
|
211
|
+
id: 12345,
|
212
|
+
data: {
|
213
|
+
kind: 'sample',
|
214
|
+
id: 12345,
|
215
|
+
num: 7,
|
216
|
+
}
|
217
|
+
}]
|
218
|
+
}
|
219
|
+
},
|
220
|
+
{
|
221
|
+
rid: 'rid-read-attrs',
|
222
|
+
api: 2,
|
223
|
+
body: {
|
224
|
+
code: 0,
|
225
|
+
results:[{
|
226
|
+
id: 12345,
|
227
|
+
data: {
|
228
|
+
kind: 'sample',
|
229
|
+
id: 12345,
|
230
|
+
num: 7,
|
231
|
+
}
|
232
|
+
}]
|
233
|
+
}
|
234
|
+
}]
|
235
|
+
])
|
236
|
+
end
|
237
|
+
|
238
|
+
def test_read_list
|
239
|
+
run_fork_test([
|
240
|
+
[{
|
241
|
+
rid: 'rid-read-list',
|
242
|
+
api: 1,
|
243
|
+
body:{
|
244
|
+
op: 'GET',
|
245
|
+
path: [ 'sample' ]
|
246
|
+
}
|
247
|
+
},
|
248
|
+
{
|
249
|
+
rid: '1',
|
250
|
+
api: 3,
|
251
|
+
body:{
|
252
|
+
where: ['EQ', 'kind', "'sample"],
|
253
|
+
select: { id: '$ref', data: '$' }
|
254
|
+
}
|
255
|
+
}],
|
256
|
+
[{
|
257
|
+
rid: '1',
|
258
|
+
api: 4,
|
259
|
+
body:{
|
260
|
+
code: 0,
|
261
|
+
results:[ 12345 ]
|
262
|
+
}
|
263
|
+
},
|
264
|
+
{
|
265
|
+
rid: 'rid-read-list',
|
266
|
+
api: 2,
|
267
|
+
body: {
|
268
|
+
code: 0,
|
269
|
+
results:[ 12345 ]
|
270
|
+
}
|
271
|
+
}]
|
272
|
+
])
|
273
|
+
end
|
274
|
+
|
275
|
+
def test_update_by_id
|
276
|
+
run_fork_test([
|
277
|
+
[{
|
278
|
+
rid: 'rid-update-id',
|
279
|
+
api: 1,
|
280
|
+
body:{
|
281
|
+
op: 'MOD',
|
282
|
+
path: [ 'sample', '12345' ],
|
283
|
+
content: {
|
284
|
+
kind: 'sample',
|
285
|
+
id: 12345,
|
286
|
+
num: 7,
|
287
|
+
}
|
288
|
+
}
|
289
|
+
},
|
290
|
+
{
|
291
|
+
rid: '1',
|
292
|
+
api: 3,
|
293
|
+
body:{
|
294
|
+
where: 12345,
|
295
|
+
update: { kind: 'sample', id: 12345, num: 7}
|
296
|
+
}
|
297
|
+
}],
|
298
|
+
[{
|
299
|
+
rid: '1',
|
300
|
+
api: 4,
|
301
|
+
body:{
|
302
|
+
code: 0,
|
303
|
+
updated: [ 12345 ]
|
304
|
+
}
|
305
|
+
},
|
306
|
+
{rid: 'rid-update-id', api: 2, body:{ code: 0, updated: [12345] }}]
|
307
|
+
])
|
308
|
+
end
|
309
|
+
|
310
|
+
def test_update_by_attrs
|
311
|
+
run_fork_test([
|
312
|
+
[{
|
313
|
+
rid: 'rid-update-attrs',
|
314
|
+
api: 1,
|
315
|
+
body:{
|
316
|
+
op: 'MOD',
|
317
|
+
path: [ 'sample' ],
|
318
|
+
query: {
|
319
|
+
id: 12345
|
320
|
+
},
|
321
|
+
content: {
|
322
|
+
kind: 'sample',
|
323
|
+
id: 12345,
|
324
|
+
num: 7,
|
325
|
+
}
|
326
|
+
}
|
327
|
+
},
|
328
|
+
{
|
329
|
+
rid: '1',
|
330
|
+
api: 3,
|
331
|
+
body:{
|
332
|
+
where: ['AND', ['EQ', 'kind', "'sample"],['EQ', 'id', 12345]],
|
333
|
+
update: { kind: 'sample', id: 12345, num: 7}
|
334
|
+
}
|
335
|
+
}],
|
336
|
+
[{
|
337
|
+
rid: '1',
|
338
|
+
api: 4,
|
339
|
+
body:{
|
340
|
+
code: 0,
|
341
|
+
updated: [ 12345 ]
|
342
|
+
}
|
343
|
+
},
|
344
|
+
{rid: 'rid-update-attrs', api: 2, body:{ code: 0, updated: [12345] }}]
|
345
|
+
])
|
346
|
+
end
|
347
|
+
|
348
|
+
def test_delete_by_id
|
349
|
+
run_fork_test([
|
350
|
+
[{
|
351
|
+
rid: 'rid-delete-id',
|
352
|
+
api: 1,
|
353
|
+
body:{
|
354
|
+
op: 'DEL',
|
355
|
+
path: [ 'sample', '12345' ]
|
356
|
+
}
|
357
|
+
},
|
358
|
+
{
|
359
|
+
rid: '1',
|
360
|
+
api: 3,
|
361
|
+
body:{
|
362
|
+
where: 12345,
|
363
|
+
delete: nil
|
364
|
+
}
|
365
|
+
}],
|
366
|
+
[{
|
367
|
+
rid: '1',
|
368
|
+
api: 4,
|
369
|
+
body:{
|
370
|
+
code: 0,
|
371
|
+
deleted: [ 12345 ]
|
372
|
+
}
|
373
|
+
},
|
374
|
+
{rid: 'rid-delete-id', api: 2, body:{ code: 0, deleted: [12345] }}]
|
375
|
+
])
|
376
|
+
end
|
377
|
+
|
378
|
+
def test_delete_by_attrs
|
379
|
+
run_fork_test([
|
380
|
+
[{
|
381
|
+
rid: 'rid-delete-attrs',
|
382
|
+
api: 1,
|
383
|
+
body:{
|
384
|
+
op: 'DEL',
|
385
|
+
path: [ 'sample' ],
|
386
|
+
query: {
|
387
|
+
id: 12345
|
388
|
+
}
|
389
|
+
}
|
390
|
+
},
|
391
|
+
{
|
392
|
+
rid: '1',
|
393
|
+
api: 3,
|
394
|
+
body:{
|
395
|
+
where: ['AND', ['EQ', 'kind', "'sample"],['EQ', 'id', 12345]],
|
396
|
+
delete: nil
|
397
|
+
}
|
398
|
+
}],
|
399
|
+
[{
|
400
|
+
rid: '1',
|
401
|
+
api: 4,
|
402
|
+
body:{
|
403
|
+
code: 0,
|
404
|
+
deleted: [ 12345 ]
|
405
|
+
}
|
406
|
+
},
|
407
|
+
{rid: 'rid-delete-attrs', api: 2, body:{ code: 0, deleted: [12345] }}]
|
408
|
+
])
|
409
|
+
end
|
410
|
+
|
411
|
+
# Fork and create a shell in the child. For each pair in the script send the
|
412
|
+
# first message and wait for the second. Compare second for test success of
|
413
|
+
# failure.
|
414
|
+
def run_fork_test(script)
|
415
|
+
# Windows does not support fork
|
416
|
+
return if RbConfig::CONFIG['host_os'] =~ /(mingw|mswin)/
|
417
|
+
|
418
|
+
to_r, to_w = IO.pipe
|
419
|
+
from_r, from_w = IO.pipe
|
420
|
+
|
421
|
+
if fork.nil? # child
|
422
|
+
$stdin = to_r
|
423
|
+
to_w.close
|
424
|
+
$stdout = from_w
|
425
|
+
from_r.close
|
426
|
+
|
427
|
+
shell = ::WAB::IO::Shell.new(1, 'kind', 0)
|
428
|
+
shell.register_controller(nil, MirrorController.new(shell))
|
429
|
+
shell.start
|
430
|
+
|
431
|
+
Process.exit(0)
|
432
|
+
else
|
433
|
+
to_r.close
|
434
|
+
from_w.close
|
435
|
+
|
436
|
+
# Shell#data should be called instead but for this test a shell is not
|
437
|
+
# desired.
|
438
|
+
script.each { |pair|
|
439
|
+
to_w.puts(::WAB::Impl::Data.new(pair[0], false).json)
|
440
|
+
to_w.flush
|
441
|
+
|
442
|
+
reply = nil
|
443
|
+
Oj.strict_load(from_r, symbol_keys: true) { |msg| reply = msg; break }
|
444
|
+
|
445
|
+
# remove backtrace if an error
|
446
|
+
bt = nil
|
447
|
+
if !reply.nil? && !reply[:body].nil?
|
448
|
+
bt = reply[:body].delete(:backtrace)
|
449
|
+
end
|
450
|
+
begin
|
451
|
+
assert_equal(pair[1], reply)
|
452
|
+
rescue Exception => e
|
453
|
+
puts
|
454
|
+
puts bt
|
455
|
+
raise e
|
456
|
+
end
|
457
|
+
}
|
458
|
+
end
|
459
|
+
end
|
460
|
+
|
461
|
+
end
|
data/test/tests.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# encoding: UTF-8
|
3
|
+
|
4
|
+
$: << File.dirname(__FILE__)
|
5
|
+
$: << File.join(File.dirname(File.dirname(File.expand_path(__FILE__))), 'lib')
|
6
|
+
|
7
|
+
require 'minitest'
|
8
|
+
require 'minitest/autorun'
|
9
|
+
|
10
|
+
require 'impl_test'
|
11
|
+
|
12
|
+
require 'ioshell_test'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: wabur
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0d1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Ohler
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-
|
11
|
+
date: 2017-08-10 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: oj
|
@@ -73,17 +73,22 @@ extensions: []
|
|
73
73
|
extra_rdoc_files:
|
74
74
|
- README.md
|
75
75
|
- pages/Architecture.md
|
76
|
-
- pages/Plan.md
|
77
76
|
- pages/Goals.md
|
77
|
+
- pages/Plan.md
|
78
78
|
files:
|
79
79
|
- LICENSE
|
80
80
|
- README.md
|
81
81
|
- lib/wab.rb
|
82
82
|
- lib/wab/controller.rb
|
83
83
|
- lib/wab/data.rb
|
84
|
+
- lib/wab/errors.rb
|
84
85
|
- lib/wab/impl.rb
|
85
86
|
- lib/wab/impl/data.rb
|
86
87
|
- lib/wab/impl/shell.rb
|
88
|
+
- lib/wab/io.rb
|
89
|
+
- lib/wab/io/call.rb
|
90
|
+
- lib/wab/io/engine.rb
|
91
|
+
- lib/wab/io/shell.rb
|
87
92
|
- lib/wab/model.rb
|
88
93
|
- lib/wab/shell.rb
|
89
94
|
- lib/wab/uuid.rb
|
@@ -94,6 +99,8 @@ files:
|
|
94
99
|
- pages/Plan.md
|
95
100
|
- test/data_test.rb
|
96
101
|
- test/impl_test.rb
|
102
|
+
- test/ioshell_test.rb
|
103
|
+
- test/tests.rb
|
97
104
|
homepage: http://github.com/ohler55/wabur
|
98
105
|
licenses:
|
99
106
|
- MIT
|
@@ -124,5 +131,7 @@ signing_key:
|
|
124
131
|
specification_version: 4
|
125
132
|
summary: Web Application Builder
|
126
133
|
test_files:
|
127
|
-
- test/impl_test.rb
|
128
134
|
- test/data_test.rb
|
135
|
+
- test/impl_test.rb
|
136
|
+
- test/ioshell_test.rb
|
137
|
+
- test/tests.rb
|