MrMurano 1.11.3 → 1.12.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +2 -0
- data/README.markdown +12 -14
- data/Rakefile +2 -2
- data/TODO.taskpaper +8 -6
- data/docs/demo.md +109 -0
- data/lib/MrMurano/Account.rb +6 -3
- data/lib/MrMurano/Config.rb +13 -37
- data/lib/MrMurano/Product-1P-Device.rb +2 -0
- data/lib/MrMurano/Product-Resources.rb +5 -4
- data/lib/MrMurano/Product.rb +3 -3
- data/lib/MrMurano/Solution-File.rb +1 -2
- data/lib/MrMurano/Solution-ServiceConfig.rb +11 -1
- data/lib/MrMurano/Solution-Services.rb +24 -7
- data/lib/MrMurano/Solution-Users.rb +6 -4
- data/lib/MrMurano/SyncUpDown.rb +67 -28
- data/lib/MrMurano/commands/config.rb +4 -1
- data/lib/MrMurano/commands/exportImport.rb +3 -0
- data/lib/MrMurano/hash.rb +2 -0
- data/lib/MrMurano/http.rb +3 -3
- data/lib/MrMurano/verbosing.rb +9 -3
- data/lib/MrMurano/version.rb +1 -1
- data/spec/Account_spec.rb +104 -0
- data/spec/Config_spec.rb +202 -57
- data/spec/Http_spec.rb +204 -0
- data/spec/MakePretties_spec.rb +35 -0
- data/spec/Mock_spec.rb +13 -20
- data/spec/ProductBase_spec.rb +2 -0
- data/spec/ProductContent_spec.rb +77 -12
- data/spec/ProductResources_spec.rb +235 -0
- data/spec/Product_1P_Device_spec.rb +62 -0
- data/spec/Product_1P_RPC_spec.rb +2 -0
- data/spec/Product_spec.rb +18 -8
- data/spec/Solution-Cors_spec.rb +28 -1
- data/spec/Solution-Endpoint_spec.rb +250 -33
- data/spec/Solution-File_spec.rb +210 -0
- data/spec/Solution-ServiceConfig_spec.rb +2 -0
- data/spec/Solution-ServiceDevice_spec.rb +174 -0
- data/spec/Solution-ServiceEventHandler_spec.rb +134 -1
- data/spec/Solution-ServiceModules_spec.rb +317 -64
- data/spec/Solution-UsersRoles_spec.rb +207 -0
- data/spec/Solution_spec.rb +90 -0
- data/spec/SyncRoot_spec.rb +52 -46
- data/spec/SyncUpDown_spec.rb +364 -0
- data/spec/Verbosing_spec.rb +279 -0
- data/spec/_workspace.rb +27 -0
- data/spec/fixtures/dumped_config +47 -0
- data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
- data/spec/fixtures/product_spec_files/lightbulb.yaml +2 -0
- data/spec/fixtures/roles-three.yaml +11 -0
- data/spec/spec_helper.rb +9 -0
- metadata +26 -2
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'MrMurano/version'
|
2
2
|
require 'MrMurano/Solution-Endpoint'
|
3
3
|
require 'tempfile'
|
4
|
+
require '_workspace'
|
4
5
|
|
5
6
|
RSpec.describe MrMurano::Endpoint do
|
7
|
+
include_context "WORKSPACE"
|
6
8
|
before(:example) do
|
7
9
|
$cfg = MrMurano::Config.new
|
8
10
|
$cfg.load
|
@@ -107,6 +109,51 @@ RSpec.describe MrMurano::Endpoint do
|
|
107
109
|
expect(ret).to eq(body)
|
108
110
|
end
|
109
111
|
|
112
|
+
it "returns empty content type" do
|
113
|
+
body = [{:id=>"9K0",
|
114
|
+
:method=>"websocket",
|
115
|
+
:path=>"/api/v1/bar",
|
116
|
+
:content_type=>"",
|
117
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n\n",
|
118
|
+
},
|
119
|
+
{:id=>"B76",
|
120
|
+
:method=>"websocket",
|
121
|
+
:path=>"/api/v1/foo/{id}",
|
122
|
+
:content_type=>"image/png",
|
123
|
+
:script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
|
124
|
+
}]
|
125
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
|
126
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
127
|
+
'Content-Type'=>'application/json'}).
|
128
|
+
to_return(body: body.to_json)
|
129
|
+
|
130
|
+
ret = @srv.list()
|
131
|
+
body.first.merge!({:content_type=>'application/json'})
|
132
|
+
expect(ret).to eq(body)
|
133
|
+
end
|
134
|
+
|
135
|
+
it "returns missing content type" do
|
136
|
+
body = [{:id=>"9K0",
|
137
|
+
:method=>"websocket",
|
138
|
+
:path=>"/api/v1/bar",
|
139
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n\n",
|
140
|
+
},
|
141
|
+
{:id=>"B76",
|
142
|
+
:method=>"websocket",
|
143
|
+
:path=>"/api/v1/foo/{id}",
|
144
|
+
:content_type=>"image/png",
|
145
|
+
:script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
|
146
|
+
}]
|
147
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
|
148
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
149
|
+
'Content-Type'=>'application/json'}).
|
150
|
+
to_return(body: body.to_json)
|
151
|
+
|
152
|
+
ret = @srv.list()
|
153
|
+
body.first.merge!({:content_type=>'application/json'})
|
154
|
+
expect(ret).to eq(body)
|
155
|
+
end
|
156
|
+
|
110
157
|
end
|
111
158
|
|
112
159
|
|
@@ -127,6 +174,25 @@ RSpec.describe MrMurano::Endpoint do
|
|
127
174
|
expect(ret).to eq(body[:script])
|
128
175
|
end
|
129
176
|
|
177
|
+
it "yields" do
|
178
|
+
body = {:id=>"9K0",
|
179
|
+
:method=>"websocket",
|
180
|
+
:path=>"/api/v1/bar",
|
181
|
+
:content_type=>"application/json",
|
182
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
|
183
|
+
}
|
184
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
185
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
186
|
+
'Content-Type'=>'application/json'}).
|
187
|
+
to_return(body: body.to_json)
|
188
|
+
|
189
|
+
ret = nil
|
190
|
+
@srv.fetch('9K0') do |sc|
|
191
|
+
ret = sc
|
192
|
+
end
|
193
|
+
expect(ret).to eq(body[:script])
|
194
|
+
end
|
195
|
+
|
130
196
|
it "missing headers" do
|
131
197
|
body = {:id=>"9K0",
|
132
198
|
:method=>"websocket",
|
@@ -202,55 +268,79 @@ RSpec.describe MrMurano::Endpoint do
|
|
202
268
|
expect(ret).to eq({})
|
203
269
|
end
|
204
270
|
|
205
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
271
|
+
context "uploads" do
|
272
|
+
around(:example) do |ex|
|
273
|
+
Tempfile.open('foo') do |tio|
|
274
|
+
tio << %{-- lua code is here
|
275
|
+
function foo(bar)
|
276
|
+
return bar + 1
|
277
|
+
end
|
278
|
+
}
|
279
|
+
tio.close
|
280
|
+
@tio_ = tio
|
281
|
+
ex.run
|
282
|
+
end
|
283
|
+
end
|
210
284
|
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
285
|
+
it "over old version" do
|
286
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
287
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
288
|
+
'Content-Type'=>'application/json'}).
|
289
|
+
to_return(body: "")
|
290
|
+
|
291
|
+
ret = @srv.upload(@tio_.path, {:id=>"9K0",
|
292
|
+
:method=>"websocket",
|
293
|
+
:path=>"/api/v1/bar",
|
294
|
+
:content_type=>"application/json",
|
295
|
+
}, true)
|
296
|
+
expect(ret)
|
215
297
|
end
|
216
|
-
}
|
217
|
-
tio.close
|
218
298
|
|
219
|
-
|
299
|
+
it "when nothing is there" do
|
300
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
301
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
302
|
+
'Content-Type'=>'application/json'}).
|
303
|
+
to_return(status: 404)
|
304
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/").
|
305
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
306
|
+
'Content-Type'=>'application/json'}).
|
307
|
+
to_return(body: "")
|
308
|
+
|
309
|
+
ret = @srv.upload(@tio_.path, {:id=>"9K0",
|
220
310
|
:method=>"websocket",
|
221
311
|
:path=>"/api/v1/bar",
|
222
312
|
:content_type=>"application/json",
|
223
|
-
},
|
313
|
+
}, false)
|
224
314
|
expect(ret)
|
225
315
|
end
|
226
|
-
end
|
227
316
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/").
|
234
|
-
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
235
|
-
'Content-Type'=>'application/json'}).
|
236
|
-
to_return(body: "")
|
317
|
+
it "without an itemkey" do
|
318
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/").
|
319
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
320
|
+
'Content-Type'=>'application/json'}).
|
321
|
+
to_return(body: "")
|
237
322
|
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
323
|
+
ret = @srv.upload(@tio_.path, {:method=>"websocket",
|
324
|
+
:path=>"/api/v1/bar",
|
325
|
+
:content_type=>"application/json",
|
326
|
+
}, false)
|
327
|
+
expect(ret)
|
242
328
|
end
|
243
|
-
}
|
244
|
-
tio.close
|
245
329
|
|
246
|
-
|
330
|
+
it "Handles others errors" do
|
331
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
332
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
333
|
+
'Content-Type'=>'application/json'}).
|
334
|
+
to_return(status: 502, body: "{}")
|
335
|
+
|
336
|
+
expect(@srv).to receive(:error).and_return(nil)
|
337
|
+
ret = @srv.upload(@tio_.path, {:id=>"9K0",
|
247
338
|
:method=>"websocket",
|
248
339
|
:path=>"/api/v1/bar",
|
249
340
|
:content_type=>"application/json",
|
250
|
-
},
|
341
|
+
}, true)
|
251
342
|
expect(ret)
|
252
343
|
end
|
253
|
-
|
254
344
|
end
|
255
345
|
|
256
346
|
context "compares" do
|
@@ -308,7 +398,134 @@ RSpec.describe MrMurano::Endpoint do
|
|
308
398
|
end
|
309
399
|
end
|
310
400
|
|
311
|
-
|
401
|
+
context "Lookup functions" do
|
402
|
+
it "gets local name" do
|
403
|
+
ret = @srv.tolocalname({ :method=>'get', :path=>'one/two/three' }, nil)
|
404
|
+
expect(ret).to eq('one-two-three.get.lua')
|
405
|
+
end
|
406
|
+
|
407
|
+
it "gets synckey" do
|
408
|
+
ret = @srv.synckey({ :method=>'get', :path=>'one/two/three' })
|
409
|
+
expect(ret).to eq("GET_one/two/three")
|
410
|
+
end
|
411
|
+
|
412
|
+
it "gets searchfor" do
|
413
|
+
$cfg['endpoints.searchFor'] = %{a b c/**/d/*.bob}
|
414
|
+
ret = @srv.searchFor
|
415
|
+
expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
|
416
|
+
end
|
417
|
+
|
418
|
+
it "gets ignoring" do
|
419
|
+
$cfg['endpoints.ignoring'] = %{a b c/**/d/*.bob}
|
420
|
+
ret = @srv.ignoring
|
421
|
+
expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
|
422
|
+
end
|
423
|
+
end
|
424
|
+
|
425
|
+
context "toRemoteItem" do
|
426
|
+
it "reads one" do
|
427
|
+
Tempfile.open("foo") do |tio|
|
428
|
+
tio << %{--#ENDPOINT GET /one/two
|
429
|
+
return request
|
430
|
+
|
431
|
+
}.gsub(/^\s+/,'')
|
432
|
+
tio.close
|
433
|
+
|
434
|
+
ret = @srv.toRemoteItem(nil, tio.path)
|
435
|
+
e = {:method=>"GET",
|
436
|
+
:path=>"/one/two",
|
437
|
+
:content_type=>"application/json",
|
438
|
+
:local_path=>Pathname.new(tio.path),
|
439
|
+
:line=>0,
|
440
|
+
:script=>"--#ENDPOINT GET /one/two\nreturn request\n",
|
441
|
+
:line_end=>2
|
442
|
+
}
|
443
|
+
expect(ret).to eq([e])
|
444
|
+
end
|
445
|
+
end
|
446
|
+
|
447
|
+
it "reads many" do
|
448
|
+
Tempfile.open("foo") do |tio|
|
449
|
+
tio << %{--#ENDPOINT GET /one/two
|
450
|
+
return request
|
451
|
+
--#ENDPOINT PUT /one/two
|
452
|
+
return request
|
453
|
+
|
454
|
+
--#ENDPOINT DELETE /three/two
|
455
|
+
return request
|
456
|
+
}.gsub(/^\s+/,'')
|
457
|
+
tio.close
|
458
|
+
|
459
|
+
ret = @srv.toRemoteItem(nil, tio.path)
|
460
|
+
|
461
|
+
expect(ret).to eq([
|
462
|
+
{
|
463
|
+
:method=>"GET",
|
464
|
+
:path=>"/one/two",
|
465
|
+
:content_type=>"application/json",
|
466
|
+
:local_path=>Pathname.new(tio.path),
|
467
|
+
:line=>0,
|
468
|
+
:script=>"--#ENDPOINT GET /one/two\nreturn request\n",
|
469
|
+
:line_end=>2
|
470
|
+
},
|
471
|
+
{
|
472
|
+
:method=>"PUT",
|
473
|
+
:path=>"/one/two",
|
474
|
+
:content_type=>"application/json",
|
475
|
+
:local_path=>Pathname.new(tio.path),
|
476
|
+
:line=>2,
|
477
|
+
:script=>"--#ENDPOINT PUT /one/two\nreturn request\n",
|
478
|
+
:line_end=>4
|
479
|
+
},
|
480
|
+
{
|
481
|
+
:method=>"DELETE",
|
482
|
+
:path=>"/three/two",
|
483
|
+
:content_type=>"application/json",
|
484
|
+
:local_path=>Pathname.new(tio.path),
|
485
|
+
:line=>4,
|
486
|
+
:script=>"--#ENDPOINT DELETE /three/two\nreturn request\n",
|
487
|
+
:line_end=>6
|
488
|
+
}
|
489
|
+
])
|
490
|
+
end
|
491
|
+
end
|
492
|
+
|
493
|
+
it "skips all when no header found" do
|
494
|
+
Tempfile.open("foo") do |tio|
|
495
|
+
tio << %{
|
496
|
+
return request
|
497
|
+
|
498
|
+
}.gsub(/^\s+/,'')
|
499
|
+
tio.close
|
500
|
+
|
501
|
+
ret = @srv.toRemoteItem(nil, tio.path)
|
502
|
+
expect(ret).to eq([])
|
503
|
+
end
|
504
|
+
end
|
505
|
+
|
506
|
+
it "skips junk at begining" do
|
507
|
+
Tempfile.open("foo") do |tio|
|
508
|
+
tio << %{
|
509
|
+
return flex
|
510
|
+
--#ENDPOINT GET /one/two
|
511
|
+
return request
|
512
|
+
|
513
|
+
}.gsub(/^\s+/,'')
|
514
|
+
tio.close
|
515
|
+
|
516
|
+
ret = @srv.toRemoteItem(nil, tio.path)
|
517
|
+
e = {:method=>"GET",
|
518
|
+
:path=>"/one/two",
|
519
|
+
:content_type=>"application/json",
|
520
|
+
:local_path=>Pathname.new(tio.path),
|
521
|
+
:line=>1,
|
522
|
+
:script=>"--#ENDPOINT GET /one/two\nreturn request\n",
|
523
|
+
:line_end=>3
|
524
|
+
}
|
525
|
+
expect(ret).to eq([e])
|
526
|
+
end
|
527
|
+
end
|
528
|
+
end
|
312
529
|
|
313
530
|
end
|
314
531
|
# vim: set ai et sw=2 ts=2 :
|
@@ -0,0 +1,210 @@
|
|
1
|
+
require 'MrMurano/version'
|
2
|
+
require 'MrMurano/Solution-File'
|
3
|
+
require '_workspace'
|
4
|
+
|
5
|
+
RSpec.describe MrMurano::File do
|
6
|
+
include_context "WORKSPACE"
|
7
|
+
before(:example) do
|
8
|
+
$cfg = MrMurano::Config.new
|
9
|
+
$cfg.load
|
10
|
+
$cfg['net.host'] = 'bizapi.hosted.exosite.io'
|
11
|
+
$cfg['solution.id'] = 'XYZ'
|
12
|
+
|
13
|
+
@srv = MrMurano::File.new
|
14
|
+
allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "initializes" do
|
18
|
+
uri = @srv.endPoint('/')
|
19
|
+
expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/")
|
20
|
+
end
|
21
|
+
|
22
|
+
it "lists" do
|
23
|
+
body = [
|
24
|
+
{:path=>"/",
|
25
|
+
:mime_type=>"text/html",
|
26
|
+
:checksum=>"f535dad52b2877a49717a034b4eee5ff1cdb8a18"},
|
27
|
+
{:path=>"/batteryMeter.svg",
|
28
|
+
:mime_type=>"image/svg+xml",
|
29
|
+
:checksum=>"06a1aab86ba8cb9b3f2913c673d4aa243c553494"},
|
30
|
+
{:path=>"/meter.html",
|
31
|
+
:mime_type=>"text/html",
|
32
|
+
:checksum=>"82e12125c2f1324bbf7bd64bf187f3334416117e"}
|
33
|
+
]
|
34
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file").
|
35
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
36
|
+
'Content-Type'=>'application/json'}).
|
37
|
+
to_return(body: body.to_json)
|
38
|
+
|
39
|
+
ret = @srv.list()
|
40
|
+
expect(ret).to eq(body)
|
41
|
+
end
|
42
|
+
|
43
|
+
it "removes" do
|
44
|
+
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/index.html").
|
45
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
46
|
+
'Content-Type'=>'application/json'}).
|
47
|
+
to_return(status: 200)
|
48
|
+
ret = @srv.remove('index.html')
|
49
|
+
expect(ret).to eq({})
|
50
|
+
end
|
51
|
+
|
52
|
+
context "fetches" do
|
53
|
+
it "gets an error" do
|
54
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
|
55
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
56
|
+
'Content-Type'=>'application/json'}).
|
57
|
+
to_return(status: 404, body: "nope")
|
58
|
+
saved = $stderr
|
59
|
+
$stderr = StringIO.new
|
60
|
+
ret = @srv.fetch('/bob')
|
61
|
+
expect(ret).to be_nil
|
62
|
+
expect($stderr.string).to eq("\e[31mRequest Failed: 404: nope\e[0m\n")
|
63
|
+
$stderr = saved
|
64
|
+
end
|
65
|
+
|
66
|
+
it "gets $stdout" do
|
67
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
|
68
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
69
|
+
'Content-Type'=>'application/json'}).
|
70
|
+
to_return(status: 200, body: "nope")
|
71
|
+
saved = $stdout
|
72
|
+
$stdout = StringIO.new
|
73
|
+
ret = @srv.fetch('/bob')
|
74
|
+
expect(ret).to be_nil
|
75
|
+
expect($stdout.string).to eq("nope")
|
76
|
+
$stdout = saved
|
77
|
+
end
|
78
|
+
|
79
|
+
it "gets to block" do
|
80
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/file/bob").
|
81
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
82
|
+
'Content-Type'=>'application/json'}).
|
83
|
+
to_return(status: 200, body: "nope")
|
84
|
+
got = ""
|
85
|
+
ret = @srv.fetch('/bob') {|chunk| got << chunk}
|
86
|
+
expect(ret).to be_nil
|
87
|
+
expect(got).to eq("nope")
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
context "uploads" do
|
92
|
+
before(:example) do
|
93
|
+
FileUtils.mkpath(@projectDir + '/files')
|
94
|
+
@lp = Pathname.new(@projectDir + '/files/one.text')
|
95
|
+
@lp.open('w') {|io| io << %{Just some text}}
|
96
|
+
@lp = @lp.realpath
|
97
|
+
end
|
98
|
+
|
99
|
+
it "an item" do
|
100
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
|
101
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
102
|
+
'Content-Type'=>%r{multipart/form-data; boundary=.*}},
|
103
|
+
)
|
104
|
+
|
105
|
+
@srv.upload(@lp, {:path=>'/one.text'}, false)
|
106
|
+
end
|
107
|
+
|
108
|
+
it "gets an error" do
|
109
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
|
110
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
111
|
+
'Content-Type'=>%r{multipart/form-data; boundary=.*}},
|
112
|
+
).
|
113
|
+
to_return(status: 401, body: "nope")
|
114
|
+
|
115
|
+
saved = $stderr
|
116
|
+
$stderr = StringIO.new
|
117
|
+
@srv.upload(@lp, {:path=>'/one.text'}, false)
|
118
|
+
expect($stderr.string).to eq("\e[31mRequest Failed: 401: nope\e[0m\n")
|
119
|
+
$stderr = saved
|
120
|
+
end
|
121
|
+
|
122
|
+
it "an item with curl debug" do
|
123
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text").
|
124
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
125
|
+
'Content-Type'=>%r{multipart/form-data; boundary=.*}},
|
126
|
+
)
|
127
|
+
$cfg['tool.curldebug'] = true
|
128
|
+
saved = $stdout
|
129
|
+
$stdout = StringIO.new
|
130
|
+
@srv.upload(@lp, {:path=>'/one.text'}, false)
|
131
|
+
expect($stdout.string).to match(%r{^curl -s -H 'Authorization: token TTTTTTTTTT'.*-X PUT 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/fileupload/one.text' -F file=@.*$})
|
132
|
+
$stdout = saved
|
133
|
+
end
|
134
|
+
end
|
135
|
+
|
136
|
+
context "compares" do
|
137
|
+
before(:example) do
|
138
|
+
@iA = {:path=>"/api/v1/bar",
|
139
|
+
:mime_type=>"application/json",
|
140
|
+
:checksum=>'12',
|
141
|
+
}
|
142
|
+
@iB = {:path=>"/api/v1/bar",
|
143
|
+
:mime_type=>"application/json",
|
144
|
+
:checksum=>'12',
|
145
|
+
}
|
146
|
+
end
|
147
|
+
it "equal" do
|
148
|
+
ret = @srv.docmp(@iA, @iB)
|
149
|
+
expect(ret).to be false
|
150
|
+
end
|
151
|
+
it "different mime" do
|
152
|
+
iA = @iA.merge({:mime_type=>'text/plain'})
|
153
|
+
ret = @srv.docmp(iA, @iB)
|
154
|
+
expect(ret).to be true
|
155
|
+
end
|
156
|
+
it "different checksum" do
|
157
|
+
iA = @iA.merge({:checksum=>'4352'})
|
158
|
+
ret = @srv.docmp(iA, @iB)
|
159
|
+
expect(ret).to be true
|
160
|
+
end
|
161
|
+
end
|
162
|
+
|
163
|
+
context "Lookup functions" do
|
164
|
+
it "gets local name" do
|
165
|
+
ret = @srv.tolocalname({:path=>'/one/two/three.html'}, :path)
|
166
|
+
expect(ret).to eq('/one/two/three.html')
|
167
|
+
end
|
168
|
+
|
169
|
+
it "gets default_page local name" do
|
170
|
+
ret = @srv.tolocalname({:path=>'/'}, :path)
|
171
|
+
expect(ret).to eq('index.html')
|
172
|
+
end
|
173
|
+
|
174
|
+
it "gets synckey" do
|
175
|
+
ret = @srv.synckey({:path=>'/one/two/three'})
|
176
|
+
expect(ret).to eq("/one/two/three")
|
177
|
+
end
|
178
|
+
|
179
|
+
it "gets searchfor" do
|
180
|
+
$cfg['files.searchFor'] = %{a b c/**/d/*.bob}
|
181
|
+
ret = @srv.searchFor
|
182
|
+
expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
|
183
|
+
end
|
184
|
+
|
185
|
+
it "gets ignoring" do
|
186
|
+
$cfg['files.ignoring'] = %{a b c/**/d/*.bob}
|
187
|
+
ret = @srv.ignoring
|
188
|
+
expect(ret).to eq(["a", "b", "c/**/d/*.bob"])
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "toRemoteItem" do
|
193
|
+
before(:example) do
|
194
|
+
FileUtils.mkpath(@projectDir + '/files')
|
195
|
+
@lp = Pathname.new(@projectDir + '/files/one.text')
|
196
|
+
@lp.open('w') {|io| io << %{Just some text}}
|
197
|
+
@lp = @lp.realpath
|
198
|
+
end
|
199
|
+
it "gets item" do
|
200
|
+
prj = Pathname.new(@projectDir).realpath
|
201
|
+
ret = @srv.toRemoteItem(prj, @lp)
|
202
|
+
expect(ret).to eq({
|
203
|
+
:path=>"/files/one.text",
|
204
|
+
:mime_type=>"application/octet-stream",
|
205
|
+
:checksum=>"d1af3dadf08479a1d43b282f95d61dda8efda5e7"
|
206
|
+
})
|
207
|
+
end
|
208
|
+
end
|
209
|
+
end
|
210
|
+
# vim: set ai et sw=2 ts=2 :
|