MuranoCLI 3.2.0.beta.9 → 3.2.1.pre.beta.3

Sign up to get free protection for your applications and to get access to all the features.
Files changed (80) hide show
  1. checksums.yaml +4 -4
  2. data/.rubocop.yml +3 -0
  3. data/Rakefile +5 -0
  4. data/dockers/README.rst +7 -0
  5. data/dockers/RELEASE.rst +6 -3
  6. data/dockers/docker-test.sh +45 -17
  7. data/docs/completions/murano_completion-bash +211 -86
  8. data/lib/MrMurano/Account.rb +72 -4
  9. data/lib/MrMurano/Business.rb +163 -2
  10. data/lib/MrMurano/Commander-Entry.rb +1 -2
  11. data/lib/MrMurano/Config.rb +19 -18
  12. data/lib/MrMurano/Content.rb +26 -19
  13. data/lib/MrMurano/Gateway.rb +51 -10
  14. data/lib/MrMurano/ReCommander.rb +1 -1
  15. data/lib/MrMurano/Solution-Services.rb +80 -35
  16. data/lib/MrMurano/Solution-Users.rb +1 -0
  17. data/lib/MrMurano/SyncRoot.rb +10 -3
  18. data/lib/MrMurano/SyncUpDown-Core.rb +47 -36
  19. data/lib/MrMurano/SyncUpDown-Item.rb +46 -14
  20. data/lib/MrMurano/SyncUpDown.rb +22 -20
  21. data/lib/MrMurano/Webservice-Endpoint.rb +20 -18
  22. data/lib/MrMurano/Webservice-File.rb +63 -20
  23. data/lib/MrMurano/commands/business.rb +14 -1
  24. data/lib/MrMurano/commands/child.rb +148 -0
  25. data/lib/MrMurano/commands/devices.rb +298 -149
  26. data/lib/MrMurano/commands/element.rb +2 -1
  27. data/lib/MrMurano/commands/globals.rb +3 -0
  28. data/lib/MrMurano/commands/network.rb +152 -33
  29. data/lib/MrMurano/commands/sync.rb +2 -2
  30. data/lib/MrMurano/commands.rb +1 -0
  31. data/lib/MrMurano/verbosing.rb +13 -2
  32. data/lib/MrMurano/version.rb +1 -1
  33. data/spec/Account_spec.rb +43 -11
  34. data/spec/Content_spec.rb +5 -3
  35. data/spec/GatewayBase_spec.rb +1 -1
  36. data/spec/GatewayDevice_spec.rb +47 -8
  37. data/spec/GatewayResource_spec.rb +1 -1
  38. data/spec/GatewaySettings_spec.rb +1 -1
  39. data/spec/HttpAuthed_spec.rb +17 -3
  40. data/spec/ProjectFile_spec.rb +59 -23
  41. data/spec/Setting_spec.rb +2 -1
  42. data/spec/Solution-ServiceConfig_spec.rb +1 -1
  43. data/spec/Solution-ServiceEventHandler_spec.rb +27 -20
  44. data/spec/Solution-ServiceModules_spec.rb +7 -5
  45. data/spec/Solution-UsersRoles_spec.rb +7 -1
  46. data/spec/Solution_spec.rb +9 -1
  47. data/spec/SyncRoot_spec.rb +5 -5
  48. data/spec/SyncUpDown_spec.rb +262 -211
  49. data/spec/Verbosing_spec.rb +49 -8
  50. data/spec/Webservice-Cors_spec.rb +10 -1
  51. data/spec/Webservice-Endpoint_spec.rb +84 -65
  52. data/spec/Webservice-File_spec.rb +16 -11
  53. data/spec/Webservice-Setting_spec.rb +7 -1
  54. data/spec/_workspace.rb +9 -0
  55. data/spec/cmd_business_spec.rb +5 -10
  56. data/spec/cmd_common.rb +67 -32
  57. data/spec/cmd_config_spec.rb +9 -14
  58. data/spec/cmd_content_spec.rb +15 -26
  59. data/spec/cmd_cors_spec.rb +9 -12
  60. data/spec/cmd_device_spec.rb +31 -45
  61. data/spec/cmd_domain_spec.rb +12 -10
  62. data/spec/cmd_element_spec.rb +18 -17
  63. data/spec/cmd_exchange_spec.rb +1 -4
  64. data/spec/cmd_init_spec.rb +56 -72
  65. data/spec/cmd_keystore_spec.rb +17 -26
  66. data/spec/cmd_link_spec.rb +13 -17
  67. data/spec/cmd_password_spec.rb +9 -10
  68. data/spec/cmd_setting_application_spec.rb +95 -68
  69. data/spec/cmd_setting_product_spec.rb +59 -37
  70. data/spec/cmd_status_spec.rb +46 -84
  71. data/spec/cmd_syncdown_application_spec.rb +28 -50
  72. data/spec/cmd_syncdown_both_spec.rb +44 -93
  73. data/spec/cmd_syncdown_unit_spec.rb +858 -0
  74. data/spec/cmd_syncup_spec.rb +21 -56
  75. data/spec/cmd_token_spec.rb +0 -3
  76. data/spec/cmd_usage_spec.rb +15 -10
  77. data/spec/dry_run_formatter.rb +1 -0
  78. data/spec/fixtures/dumped_config +4 -4
  79. data/spec/spec_helper.rb +3 -0
  80. metadata +4 -2
@@ -65,14 +65,19 @@ RSpec.describe MrMurano::Verbose do
65
65
  end
66
66
 
67
67
  it 'takes Array' do
68
+ stdout_saved = $stdout
68
69
  $stdout = StringIO.new
69
70
 
70
71
  @tst.tabularize([[1, 2, 3, 4, 5, 6, 7], [10, 20, 30, 40, 50, 60, 70]])
71
72
 
72
- expect($stdout.string).to eq("1,2,3,4,5,6,7\n10,20,30,40,50,60,70\n")
73
+ expect($stdout.string).to eq(
74
+ %("1","2","3","4","5","6","7"\n"10","20","30","40","50","60","70"\n)
75
+ )
76
+ $stdout = stdout_saved
73
77
  end
74
78
 
75
79
  it 'ducks to_a' do
80
+ stdout_saved = $stdout
76
81
  $stdout = StringIO.new
77
82
 
78
83
  class DuckToATest
@@ -82,10 +87,12 @@ RSpec.describe MrMurano::Verbose do
82
87
  end
83
88
  @tst.tabularize(DuckToATest.new)
84
89
 
85
- expect($stdout.string).to eq("12\n13\n")
90
+ expect($stdout.string).to eq(%("12"\n"13"\n))
91
+ $stdout = stdout_saved
86
92
  end
87
93
 
88
94
  it 'ducks each' do
95
+ stdout_saved = $stdout
89
96
  $stdout = StringIO.new
90
97
 
91
98
  class DuckEachTest
@@ -96,7 +103,9 @@ RSpec.describe MrMurano::Verbose do
96
103
  end
97
104
  @tst.tabularize(DuckEachTest.new)
98
105
 
99
- expect($stdout.string).to eq("22\n44\n")
106
+ expect($stdout.string).to eq(%("22"\n"44"\n))
107
+
108
+ $stdout = stdout_saved
100
109
  end
101
110
 
102
111
  context 'takes Hash' do
@@ -106,11 +115,26 @@ RSpec.describe MrMurano::Verbose do
106
115
  title: 'Test output',
107
116
  rows: [[1, 2, 3], [10, 20, 30]],
108
117
  }
118
+ @stdout_saved = $stdout
109
119
  $stdout = StringIO.new
110
120
  end
121
+
122
+ after(:example) do
123
+ $stdout = @stdout_saved
124
+ end
125
+
111
126
  it 'has all' do
112
127
  @tst.tabularize(@hsh)
113
- expect($stdout.string).to eq("one,two,three\n1,2,3\n10,20,30\n")
128
+ expect($stdout.string).to eq(
129
+ %("one","two","three"\n"1","2","3"\n"10","20","30"\n)
130
+ )
131
+ end
132
+
133
+ it 'not quoted' do
134
+ @tst.tabularize(@hsh, no_quotes: true)
135
+ expect($stdout.string).to eq(
136
+ %(one,two,three\n1,2,3\n10,20,30\n)
137
+ )
114
138
  end
115
139
 
116
140
  it 'is empty' do
@@ -121,43 +145,48 @@ RSpec.describe MrMurano::Verbose do
121
145
  it 'no headers' do
122
146
  @hsh.delete :headers
123
147
  @tst.tabularize(@hsh)
124
- expect($stdout.string).to eq("1,2,3\n10,20,30\n")
148
+ expect($stdout.string).to eq(%("1","2","3"\n"10","20","30"\n))
125
149
  end
126
150
 
127
151
  it 'no title' do
128
152
  @hsh.delete :title
129
153
  @tst.tabularize(@hsh)
130
- expect($stdout.string).to eq("one,two,three\n1,2,3\n10,20,30\n")
154
+ expect($stdout.string).to eq(%("one","two","three"\n"1","2","3"\n"10","20","30"\n))
131
155
  end
132
156
 
133
157
  it 'no rows' do
134
158
  @hsh.delete :rows
135
159
  @tst.tabularize(@hsh)
136
- expect($stdout.string).to eq("one,two,three\n\n")
160
+ expect($stdout.string).to eq(%("one","two","three"\n\n))
137
161
  end
138
162
  end
139
163
 
140
164
  it "errors if it can't" do
165
+ stdout_saved = $stdout
141
166
  $stdout = StringIO.new
142
167
  # 2017-07-03: [lb] converted to class func.
143
168
  #expect(@tst).to receive(:error).with(MrMurano::Verbose::TABULARIZE_DATA_FORMAT_ERROR).once
144
169
  expect(MrMurano::Verbose).to receive(:error).with(MrMurano::Verbose::TABULARIZE_DATA_FORMAT_ERROR).once
145
170
  @tst.tabularize(12)
171
+ $stdout = stdout_saved
146
172
  end
147
173
 
148
174
  it 'takes Array, to custom stream' do
175
+ stdout_saved = $stdout
149
176
  $stdout = StringIO.new
150
177
  outer = StringIO.new
151
178
 
152
179
  @tst.tabularize([[1, 2, 3, 4, 5, 6, 7], [10, 20, 30, 40, 50, 60, 70]], outer)
153
180
 
154
- expect(outer.string).to eq("1,2,3,4,5,6,7\n10,20,30,40,50,60,70\n")
181
+ expect(outer.string).to eq(%("1","2","3","4","5","6","7"\n"10","20","30","40","50","60","70"\n))
155
182
  expect($stdout.string).to eq('')
183
+ $stdout = stdout_saved
156
184
  end
157
185
  end
158
186
 
159
187
  context 'generating a table' do
160
188
  it 'takes Array' do
189
+ stdout_saved = $stdout
161
190
  $stdout = StringIO.new
162
191
  @tst.tabularize([[1, 2, 3, 4, 5, 6, 7], [10, 20, 30, 40, 50, 60, 70]])
163
192
  expect($stdout.string).to eq(
@@ -167,6 +196,7 @@ RSpec.describe MrMurano::Verbose do
167
196
  +----+----+----+----+----+----+----+
168
197
  ).gsub(/^\s+/, '')
169
198
  )
199
+ $stdout = stdout_saved
170
200
  end
171
201
 
172
202
  context 'takes Hash' do
@@ -176,8 +206,14 @@ RSpec.describe MrMurano::Verbose do
176
206
  title: 'Test output',
177
207
  rows: [[1, 2, 3], [10, 20, 30]],
178
208
  }
209
+ @stdout_saved = $stdout
179
210
  $stdout = StringIO.new
180
211
  end
212
+
213
+ after(:example) do
214
+ $stdout = @stdout_saved
215
+ end
216
+
181
217
  it 'has all' do
182
218
  @tst.tabularize(@hsh)
183
219
  expect($stdout.string).to eq(
@@ -249,9 +285,14 @@ RSpec.describe MrMurano::Verbose do
249
285
  one: 'three',
250
286
  two: [{ one: 3 }, { one: 4 }],
251
287
  }
288
+ @stdout_saved = $stdout
252
289
  $stdout = StringIO.new
253
290
  end
254
291
 
292
+ after(:example) do
293
+ $stdout = @stdout_saved
294
+ end
295
+
255
296
  it 'outputs yaml' do
256
297
  $cfg['tool.outformat'] = 'yaml'
257
298
  @tst.outf(@data)
@@ -6,7 +6,9 @@
6
6
  # Unauthorized copying of this file is strictly prohibited.
7
7
 
8
8
  require 'tempfile'
9
+ require 'webmock'
9
10
  require 'yaml'
11
+
10
12
  require 'MrMurano/version'
11
13
  require 'MrMurano/HttpAuthed'
12
14
  require 'MrMurano/ProjectFile'
@@ -17,8 +19,8 @@ require 'HttpAuthed_spec'
17
19
 
18
20
  RSpec.describe MrMurano::Webservice::Cors do
19
21
  include_context 'WORKSPACE'
22
+
20
23
  before(:example) do
21
- MrMurano::SyncRoot.instance.reset
22
24
  $cfg = MrMurano::Config.new
23
25
  $cfg.load
24
26
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
@@ -31,6 +33,10 @@ RSpec.describe MrMurano::Webservice::Cors do
31
33
  @base_uri = 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors'
32
34
  end
33
35
 
36
+ after(:example) do
37
+ WebMock.reset!
38
+ end
39
+
34
40
  it 'initializes' do
35
41
  uri = @srv.endpoint('/')
36
42
  expect(uri.to_s).to eq("#{@base_uri}/")
@@ -58,6 +64,7 @@ RSpec.describe MrMurano::Webservice::Cors do
58
64
  ret = @srv.fetch
59
65
  expect(ret).to eq(cors)
60
66
  end
67
+
61
68
  it 'as a block' do
62
69
  cors = {
63
70
  origin: true,
@@ -109,6 +116,7 @@ RSpec.describe MrMurano::Webservice::Cors do
109
116
  ret = @srv.fetch
110
117
  expect(ret).to eq(cors)
111
118
  end
119
+
112
120
  it 'as a block' do
113
121
  cors = {
114
122
  origin: true,
@@ -149,6 +157,7 @@ RSpec.describe MrMurano::Webservice::Cors do
149
157
  credentials: true,
150
158
  }
151
159
  end
160
+
152
161
  it 'specified file' do
153
162
  File.open(File.join(@project_dir, 'bob.yaml'), 'w') { |io| io << @cors.to_yaml }
154
163
  stub_request(
@@ -16,11 +16,18 @@ require 'HttpAuthed_spec'
16
16
 
17
17
  RSpec.describe MrMurano::Webservice::Endpoint do
18
18
  include_context 'WORKSPACE'
19
+
19
20
  before(:example) do
20
21
  $cfg = MrMurano::Config.new
21
22
  $cfg.load
22
23
  $project = MrMurano::ProjectFile.new
23
24
  $project.load
25
+
26
+ @pswd = create_instance_double_passwords
27
+ allow(@pswd).to receive(:get).and_return('built')
28
+
29
+ $cfg['user.name'] = 'bob'
30
+
24
31
  $cfg['net.host'] = 'bizapi.hosted.exosite.io'
25
32
  $cfg['application.id'] = 'XYZ'
26
33
  stub_request_email_password
@@ -46,16 +53,21 @@ RSpec.describe MrMurano::Webservice::Endpoint do
46
53
  content_type: 'application/json',
47
54
  script: "--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n\n",
48
55
  },
49
- { id: 'B76',
56
+ {
57
+ id: 'B76',
50
58
  method: 'websocket',
51
59
  path: '/api/v1/foo/{id}',
52
60
  content_type: 'application/json',
53
- script: "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n", },
61
+ script: "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
62
+ },
54
63
  ]
55
64
  stub_request(:get, @base_uri)
56
- .with(headers: { 'Authorization' => 'token TTTTTTTTTT',
57
- 'Content-Type' => 'application/json', })
58
- .to_return(body: body.to_json)
65
+ .with(
66
+ headers: {
67
+ 'Authorization' => 'token TTTTTTTTTT',
68
+ 'Content-Type' => 'application/json',
69
+ }
70
+ ).to_return(body: body.to_json)
59
71
 
60
72
  ret = @srv.list
61
73
  expect(ret).to eq(body)
@@ -471,26 +483,29 @@ RSpec.describe MrMurano::Webservice::Endpoint do
471
483
  end
472
484
  end
473
485
 
474
- context 'to_remote_item' do
486
+ context 'to_remote_items' do
475
487
  it 'reads one' do
476
488
  Tempfile.open('foo') do |tio|
477
489
  tio << %(--#ENDPOINT GET /one/two
478
490
  return request
479
491
 
480
- ).gsub(/^\s+/, '')
492
+ ).gsub(/^ +/, '')
481
493
  tio.close
482
494
 
483
- ret = @srv.to_remote_item(nil, tio.path)
484
- e = {
485
- method: 'GET',
486
- path: '/one/two',
487
- content_type: 'application/json',
488
- local_path: Pathname.new(tio.path),
489
- line_beg: 0,
490
- script: "--#ENDPOINT GET /one/two\nreturn request\n",
491
- line_end: 2,
492
- }
493
- expect(ret).to eq([e])
495
+ want = [
496
+ {
497
+ content_type: 'application/json',
498
+ header: '--#ENDPOINT GET /one/two',
499
+ line_beg: 1,
500
+ line_end: 3,
501
+ local_path: Pathname.new(tio.path),
502
+ method: 'GET',
503
+ path: '/one/two',
504
+ script: "return request\n\n",
505
+ },
506
+ ]
507
+ ret = @srv.to_remote_items(nil, tio.path)
508
+ expect(ret.collect(&:to_h)).to eq(want)
494
509
  end
495
510
  end
496
511
 
@@ -503,42 +518,43 @@ RSpec.describe MrMurano::Webservice::Endpoint do
503
518
 
504
519
  --#ENDPOINT DELETE /three/two
505
520
  return request
506
- ).gsub(/^\s+/, '')
521
+ ).gsub(/^ +/, '')
507
522
  tio.close
508
523
 
509
- ret = @srv.to_remote_item(nil, tio.path)
510
-
511
- expect(ret).to eq(
512
- [
513
- {
514
- method: 'GET',
515
- path: '/one/two',
516
- content_type: 'application/json',
517
- local_path: Pathname.new(tio.path),
518
- line_beg: 0,
519
- script: "--#ENDPOINT GET /one/two\nreturn request\n",
520
- line_end: 2,
521
- },
522
- {
523
- method: 'PUT',
524
- path: '/one/two',
525
- content_type: 'application/json',
526
- local_path: Pathname.new(tio.path),
527
- line_beg: 2,
528
- script: "--#ENDPOINT PUT /one/two\nreturn request\n",
529
- line_end: 4,
530
- },
531
- {
532
- method: 'DELETE',
533
- path: '/three/two',
534
- content_type: 'application/json',
535
- local_path: Pathname.new(tio.path),
536
- line_beg: 4,
537
- script: "--#ENDPOINT DELETE /three/two\nreturn request\n",
538
- line_end: 6,
539
- },
540
- ]
541
- )
524
+ want = [
525
+ {
526
+ content_type: 'application/json',
527
+ header: '--#ENDPOINT GET /one/two',
528
+ line_beg: 1,
529
+ line_end: 2,
530
+ local_path: Pathname.new(tio.path),
531
+ method: 'GET',
532
+ path: '/one/two',
533
+ script: "return request\n",
534
+ },
535
+ {
536
+ content_type: 'application/json',
537
+ header: '--#ENDPOINT PUT /one/two',
538
+ line_beg: 3,
539
+ line_end: 5,
540
+ local_path: Pathname.new(tio.path),
541
+ method: 'PUT',
542
+ path: '/one/two',
543
+ script: "return request\n\n",
544
+ },
545
+ {
546
+ content_type: 'application/json',
547
+ header: '--#ENDPOINT DELETE /three/two',
548
+ line_beg: 6,
549
+ line_end: 7,
550
+ local_path: Pathname.new(tio.path),
551
+ method: 'DELETE',
552
+ path: '/three/two',
553
+ script: "return request\n",
554
+ },
555
+ ]
556
+ ret = @srv.to_remote_items(nil, tio.path)
557
+ expect(ret.collect(&:to_h)).to eq(want)
542
558
  end
543
559
  end
544
560
 
@@ -550,8 +566,8 @@ RSpec.describe MrMurano::Webservice::Endpoint do
550
566
  ).gsub(/^\s+/, '')
551
567
  tio.close
552
568
 
553
- ret = @srv.to_remote_item(nil, tio.path)
554
- expect(ret).to eq([])
569
+ ret = @srv.to_remote_items(nil, tio.path)
570
+ expect(ret.collect(&:to_h)).to eq([])
555
571
  end
556
572
  end
557
573
 
@@ -565,17 +581,20 @@ RSpec.describe MrMurano::Webservice::Endpoint do
565
581
  ).gsub(/^\s+/, '')
566
582
  tio.close
567
583
 
568
- ret = @srv.to_remote_item(nil, tio.path)
569
- e = {
570
- method: 'GET',
571
- path: '/one/two',
572
- content_type: 'application/json',
573
- local_path: Pathname.new(tio.path),
574
- line_beg: 1,
575
- script: "--#ENDPOINT GET /one/two\nreturn request\n",
576
- line_end: 3,
577
- }
578
- expect(ret).to eq([e])
584
+ want = [
585
+ {
586
+ content_type: 'application/json',
587
+ header: '--#ENDPOINT GET /one/two',
588
+ line_beg: 2,
589
+ line_end: 3,
590
+ local_path: Pathname.new(tio.path),
591
+ method: 'GET',
592
+ path: '/one/two',
593
+ script: "return request\n",
594
+ },
595
+ ]
596
+ ret = @srv.to_remote_items(nil, tio.path)
597
+ expect(ret.collect(&:to_h)).to eq(want)
579
598
  end
580
599
  end
581
600
  end
@@ -251,25 +251,30 @@ RSpec.describe MrMurano::Webservice::File do
251
251
  end
252
252
  end
253
253
 
254
- context 'to_remote_item' do
254
+ context 'to_remote_items' do
255
255
  before(:example) do
256
256
  FileUtils.mkpath(@project_dir + '/files')
257
257
  @lp = Pathname.new(@project_dir + '/files/one.text')
258
258
  @lp.open('w') { |io| io << %(Just some text) }
259
259
  @lp = @lp.realpath
260
260
  end
261
+
261
262
  it 'gets item' do
262
263
  prj = Pathname.new(@project_dir).realpath
263
- ret = @srv.to_remote_item(prj, @lp)
264
- expect(ret).to eq(
265
- path: '/files/one.text',
266
- mime_type: 'text/plain',
267
- # 2018-04-16: Did backend change from SHA1 to MD5 hash function?
268
- # You can calculate this with `sha1sum one.text`
269
- #checksum: 'd1af3dadf08479a1d43b282f95d61dda8efda5e7'
270
- # You can calculate this with `md5sum one.text`
271
- checksum: 'e9ea4a5be73a09f541ad0b611083f0df'
272
- )
264
+ want = [
265
+ MrMurano::Webservice::File::FileItem.new(
266
+ path: '/files/one.text',
267
+ mime_type: 'text/plain',
268
+ # 2018-04-16: Did backend change from SHA1 to MD5 hash function?
269
+ # You can calculate this with `sha1sum one.text`
270
+ #checksum: 'd1af3dadf08479a1d43b282f95d61dda8efda5e7'
271
+ # You can calculate this with `md5sum one.text`
272
+ checksum: 'e9ea4a5be73a09f541ad0b611083f0df',
273
+ size: %(Just some text).length,
274
+ ),
275
+ ]
276
+ ret = @srv.to_remote_items(prj, @lp)
277
+ expect(ret).to eq(want)
273
278
  end
274
279
  end
275
280
  end