MrMurano 1.11.3 → 1.12.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (53) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/Gemfile +2 -0
  4. data/README.markdown +12 -14
  5. data/Rakefile +2 -2
  6. data/TODO.taskpaper +8 -6
  7. data/docs/demo.md +109 -0
  8. data/lib/MrMurano/Account.rb +6 -3
  9. data/lib/MrMurano/Config.rb +13 -37
  10. data/lib/MrMurano/Product-1P-Device.rb +2 -0
  11. data/lib/MrMurano/Product-Resources.rb +5 -4
  12. data/lib/MrMurano/Product.rb +3 -3
  13. data/lib/MrMurano/Solution-File.rb +1 -2
  14. data/lib/MrMurano/Solution-ServiceConfig.rb +11 -1
  15. data/lib/MrMurano/Solution-Services.rb +24 -7
  16. data/lib/MrMurano/Solution-Users.rb +6 -4
  17. data/lib/MrMurano/SyncUpDown.rb +67 -28
  18. data/lib/MrMurano/commands/config.rb +4 -1
  19. data/lib/MrMurano/commands/exportImport.rb +3 -0
  20. data/lib/MrMurano/hash.rb +2 -0
  21. data/lib/MrMurano/http.rb +3 -3
  22. data/lib/MrMurano/verbosing.rb +9 -3
  23. data/lib/MrMurano/version.rb +1 -1
  24. data/spec/Account_spec.rb +104 -0
  25. data/spec/Config_spec.rb +202 -57
  26. data/spec/Http_spec.rb +204 -0
  27. data/spec/MakePretties_spec.rb +35 -0
  28. data/spec/Mock_spec.rb +13 -20
  29. data/spec/ProductBase_spec.rb +2 -0
  30. data/spec/ProductContent_spec.rb +77 -12
  31. data/spec/ProductResources_spec.rb +235 -0
  32. data/spec/Product_1P_Device_spec.rb +62 -0
  33. data/spec/Product_1P_RPC_spec.rb +2 -0
  34. data/spec/Product_spec.rb +18 -8
  35. data/spec/Solution-Cors_spec.rb +28 -1
  36. data/spec/Solution-Endpoint_spec.rb +250 -33
  37. data/spec/Solution-File_spec.rb +210 -0
  38. data/spec/Solution-ServiceConfig_spec.rb +2 -0
  39. data/spec/Solution-ServiceDevice_spec.rb +174 -0
  40. data/spec/Solution-ServiceEventHandler_spec.rb +134 -1
  41. data/spec/Solution-ServiceModules_spec.rb +317 -64
  42. data/spec/Solution-UsersRoles_spec.rb +207 -0
  43. data/spec/Solution_spec.rb +90 -0
  44. data/spec/SyncRoot_spec.rb +52 -46
  45. data/spec/SyncUpDown_spec.rb +364 -0
  46. data/spec/Verbosing_spec.rb +279 -0
  47. data/spec/_workspace.rb +27 -0
  48. data/spec/fixtures/dumped_config +47 -0
  49. data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
  50. data/spec/fixtures/product_spec_files/lightbulb.yaml +2 -0
  51. data/spec/fixtures/roles-three.yaml +11 -0
  52. data/spec/spec_helper.rb +9 -0
  53. metadata +26 -2
@@ -0,0 +1,279 @@
1
+ require 'highline/import'
2
+ require 'MrMurano/version'
3
+ require 'MrMurano/hash'
4
+ require 'MrMurano/verbosing'
5
+ require 'MrMurano/Config'
6
+ require '_workspace'
7
+
8
+ class VTst
9
+ include MrMurano::Verbose
10
+ def initialize
11
+ @token = nil
12
+ end
13
+ end
14
+ RSpec.describe MrMurano::Verbose do
15
+ include_context "WORKSPACE"
16
+
17
+ before(:example) do
18
+ $cfg = MrMurano::Config.new
19
+ $cfg.load
20
+ @tst = VTst.new
21
+ end
22
+
23
+ it "verboses" do
24
+ $cfg['tool.verbose'] = true
25
+ expect($terminal).to receive(:say).with('hello').once
26
+ @tst.verbose "hello"
27
+ end
28
+
29
+ it "is quiet" do
30
+ expect($terminal).to_not receive(:say)
31
+ @tst.verbose "hello"
32
+ end
33
+
34
+ it "debugs" do
35
+ $cfg['tool.debug'] = true
36
+ expect($terminal).to receive(:say).with('hello').once
37
+ @tst.debug "hello"
38
+ end
39
+
40
+ it "warns" do
41
+ expect($stderr).to receive(:puts).with("\e[33mhello\e[0m").once
42
+ @tst.warning "hello"
43
+ end
44
+
45
+ it "errors" do
46
+ expect($stderr).to receive(:puts).with("\e[31mhello\e[0m").once
47
+ @tst.error "hello"
48
+ end
49
+
50
+ context "tabularize" do
51
+ context "generating CSV" do
52
+ before(:example) do
53
+ $cfg['tool.outformat'] = 'csv'
54
+ end
55
+
56
+ it "takes Array" do
57
+ $stdout = StringIO.new
58
+
59
+ @tst.tabularize([[1,2,3,4,5,6,7],[10,20,30,40,50,60,70]])
60
+
61
+ expect($stdout.string).to eq("1,2,3,4,5,6,7\n10,20,30,40,50,60,70\n")
62
+ end
63
+
64
+ it "ducks to_a" do
65
+ $stdout = StringIO.new
66
+
67
+ class DuckToATest
68
+ def to_a
69
+ [[12],[13]]
70
+ end
71
+ end
72
+ @tst.tabularize(DuckToATest.new)
73
+
74
+ expect($stdout.string).to eq("12\n13\n")
75
+ end
76
+
77
+ it "ducks each" do
78
+ $stdout = StringIO.new
79
+
80
+ class DuckEachTest
81
+ def each(&block)
82
+ yield [22]
83
+ yield [44]
84
+ end
85
+ end
86
+ @tst.tabularize(DuckEachTest.new)
87
+
88
+ expect($stdout.string).to eq("22\n44\n")
89
+ end
90
+
91
+ context "takes Hash" do
92
+ before(:example) do
93
+ @hsh = {
94
+ :headers => [:one, :two, :three],
95
+ :title => "Test output",
96
+ :rows => [[1,2,3], [10,20,30]]
97
+ }
98
+ $stdout = StringIO.new
99
+ end
100
+ it "has all" do
101
+ @tst.tabularize(@hsh)
102
+ expect($stdout.string).to eq("one,two,three\n1,2,3\n10,20,30\n")
103
+ end
104
+
105
+ it "is empty" do
106
+ @tst.tabularize({})
107
+ expect($stdout.string).to eq("\n")
108
+ end
109
+
110
+ it "no headers" do
111
+ @hsh.delete :headers
112
+ @tst.tabularize(@hsh)
113
+ expect($stdout.string).to eq("1,2,3\n10,20,30\n")
114
+ end
115
+
116
+ it "no title" do
117
+ @hsh.delete :title
118
+ @tst.tabularize(@hsh)
119
+ expect($stdout.string).to eq("one,two,three\n1,2,3\n10,20,30\n")
120
+ end
121
+
122
+ it "no rows" do
123
+ @hsh.delete :rows
124
+ @tst.tabularize(@hsh)
125
+ expect($stdout.string).to eq("one,two,three\n\n")
126
+ end
127
+ end
128
+
129
+ it "errors if it can't" do
130
+ $stdout = StringIO.new
131
+ expect(@tst).to receive(:error).with("Don't know how to tabularize data.").once
132
+ @tst.tabularize(12)
133
+ end
134
+
135
+ it "takes Array, to custom stream" do
136
+ $stdout = StringIO.new
137
+ outer = StringIO.new
138
+
139
+ @tst.tabularize([[1,2,3,4,5,6,7],[10,20,30,40,50,60,70]], outer)
140
+
141
+ expect(outer.string).to eq("1,2,3,4,5,6,7\n10,20,30,40,50,60,70\n")
142
+ expect($stdout.string).to eq('')
143
+ end
144
+ end
145
+
146
+ context "generating a table" do
147
+ it "takes Array" do
148
+ $stdout = StringIO.new
149
+ @tst.tabularize([[1,2,3,4,5,6,7],[10,20,30,40,50,60,70]])
150
+ expect($stdout.string).to eq(
151
+ %{+----+----+----+----+----+----+----+
152
+ | 1 | 2 | 3 | 4 | 5 | 6 | 7 |
153
+ | 10 | 20 | 30 | 40 | 50 | 60 | 70 |
154
+ +----+----+----+----+----+----+----+
155
+ }.gsub(/^\s+/,'')
156
+ )
157
+ end
158
+
159
+ context "takes Hash" do
160
+ before(:example) do
161
+ @hsh = {
162
+ :headers => [:one, :two, :three],
163
+ :title => "Test output",
164
+ :rows => [[1,2,3], [10,20,30]]
165
+ }
166
+ $stdout = StringIO.new
167
+ end
168
+ it "has all" do
169
+ @tst.tabularize(@hsh)
170
+ expect($stdout.string).to eq(
171
+ %{+-----+-----+-------+
172
+ | Test output |
173
+ +-----+-----+-------+
174
+ | one | two | three |
175
+ +-----+-----+-------+
176
+ | 1 | 2 | 3 |
177
+ | 10 | 20 | 30 |
178
+ +-----+-----+-------+
179
+ }.gsub(/^\s+/,'')
180
+ )
181
+ end
182
+
183
+ it "is empty" do
184
+ @tst.tabularize({})
185
+ expect($stdout.string).to eq("++\n++\n")
186
+ end
187
+
188
+ it "no headers" do
189
+ @hsh.delete :headers
190
+ @tst.tabularize(@hsh)
191
+ expect($stdout.string).to eq(
192
+ %{+----+----+----+
193
+ | Test output |
194
+ +----+----+----+
195
+ | 1 | 2 | 3 |
196
+ | 10 | 20 | 30 |
197
+ +----+----+----+
198
+ }.gsub(/^\s+/,'')
199
+ )
200
+ end
201
+
202
+ it "no title" do
203
+ @hsh.delete :title
204
+ @tst.tabularize(@hsh)
205
+ expect($stdout.string).to eq(
206
+ %{+-----+-----+-------+
207
+ | one | two | three |
208
+ +-----+-----+-------+
209
+ | 1 | 2 | 3 |
210
+ | 10 | 20 | 30 |
211
+ +-----+-----+-------+
212
+ }.gsub(/^\s+/,'')
213
+ )
214
+ end
215
+
216
+ it "no rows" do
217
+ @hsh.delete :rows
218
+ @tst.tabularize(@hsh)
219
+ expect($stdout.string).to eq(
220
+ %{+-----+-----+-------+
221
+ | Test output |
222
+ +-----+-----+-------+
223
+ | one | two | three |
224
+ +-----+-----+-------+
225
+ +-----+-----+-------+
226
+ }
227
+ )
228
+ end
229
+ end
230
+ end
231
+ end
232
+
233
+ context "outf" do
234
+ before(:example) do
235
+ @data = {
236
+ :one => "three",
237
+ :two => [ { :one => 3 }, { :one => 4} ]
238
+ }
239
+ $stdout = StringIO.new
240
+ end
241
+
242
+ it "outputs yaml" do
243
+ $cfg['tool.outformat'] = 'yaml'
244
+ @tst.outf(@data)
245
+ expect($stdout.string).to eq("---\none: three\ntwo:\n- one: 3\n- one: 4\n")
246
+ end
247
+
248
+ it "outputs json" do
249
+ $cfg['tool.outformat'] = 'json'
250
+ @tst.outf(@data)
251
+ expect($stdout.string).to eq("{\"one\":\"three\",\"two\":[{\"one\":3},{\"one\":4}]}\n")
252
+ end
253
+
254
+ it "outputs ruby" do
255
+ $cfg['tool.outformat'] = 'pp'
256
+ @tst.outf(@data)
257
+ expect($stdout.string).to eq("{:one=>\"three\", :two=>[{:one=>3}, {:one=>4}]}\n")
258
+ end
259
+
260
+ it "outputs as String" do
261
+ @tst.outf(@data)
262
+ expect($stdout.string).to eq("{:one=>\"three\", :two=>[{:one=>3}, {:one=>4}]}\n")
263
+ end
264
+
265
+ it "outputs as Array" do
266
+ @tst.outf([1,2,3,4,5])
267
+ expect($stdout.string).to eq("1\n2\n3\n4\n5\n")
268
+ end
269
+
270
+ it "returns to block" do
271
+ @tst.outf(@data) do |dd, ios|
272
+ ios.puts "pop"
273
+ end
274
+ expect($stdout.string).to eq("pop\n")
275
+ end
276
+ end
277
+
278
+ end
279
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,27 @@
1
+ require 'pathname'
2
+ require 'fileutils'
3
+ require 'tmpdir'
4
+
5
+ RSpec.shared_context "WORKSPACE" do
6
+
7
+ around(:example) do |ex|
8
+ @testdir = Pathname.new(Dir.pwd).realpath
9
+ Dir.mktmpdir do |hdir|
10
+ @tmpdir = hdir
11
+ saved_home = ENV['HOME']
12
+ # Set ENV to override output of Dir.home
13
+ ENV['HOME'] = File.join(hdir, 'home')
14
+ FileUtils.mkpath(ENV['HOME'])
15
+ Dir.chdir(hdir) do
16
+ @projectDir = File.join(ENV['HOME'], 'work', 'project')
17
+ FileUtils.mkpath(@projectDir)
18
+ Dir.chdir(@projectDir) do
19
+ ex.run
20
+ end
21
+ end
22
+ ENV['HOME'] = saved_home
23
+ end
24
+ end
25
+ end
26
+
27
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,47 @@
1
+ [tool]
2
+ verbose = false
3
+ debug = false
4
+ dry = false
5
+ fullerror = false
6
+ outformat = best
7
+
8
+ [net]
9
+ host = bizapi.hosted.exosite.io
10
+
11
+ [location]
12
+ base = <%= File.realpath(@projectDir) %>
13
+ files = files
14
+ endpoints = endpoints
15
+ modules = modules
16
+ eventhandlers = eventhandlers
17
+ roles = roles.yaml
18
+ users = users.yaml
19
+ cors = cors.yaml
20
+ specs = specs
21
+
22
+ [sync]
23
+ bydefault = files
24
+
25
+ [files]
26
+ default_page = index.html
27
+ searchFor = **/*
28
+ ignoring =
29
+
30
+ [endpoints]
31
+ searchFor = *.lua */*.lua
32
+ ignoring = *_test.lua *_spec.lua .*
33
+
34
+ [eventhandler]
35
+ searchFor = *.lua */*.lua
36
+ ignoring = *_test.lua *_spec.lua .*
37
+ skiplist = websocket webservice device.service_call
38
+
39
+ [modules]
40
+ searchFor = *.lua */*.lua
41
+ ignoring = *_test.lua *_spec.lua .*
42
+
43
+ [product]
44
+ spec = resources.yaml
45
+
46
+ [diff]
47
+ cmd = <%= Gem.win_platform? ? 'fc' : 'diff -u' %>
@@ -0,0 +1,11 @@
1
+ ---
2
+ resources:
3
+ - alias: temperature
4
+ format: float
5
+ initial: 0
6
+ - alias: uptime
7
+ format: integer
8
+ initial: 0
9
+ - alias: humidity
10
+ format: float
11
+ initial: 0
@@ -1,3 +1,5 @@
1
+ ---
2
+ resources:
1
3
  - alias: state
2
4
  format: integer
3
5
  initial: 0
@@ -0,0 +1,11 @@
1
+ ---
2
+ - role_id: guest
3
+ parameter:
4
+ - name: did
5
+ - role_id: admin
6
+ parameter:
7
+ - name: enabled
8
+ - role_id: owns
9
+ parameter:
10
+ - name: did
11
+
data/spec/spec_helper.rb CHANGED
@@ -15,6 +15,15 @@
15
15
  # The `.rspec` file also contains a few flags that are not defaults but that
16
16
  # users commonly want.
17
17
  #
18
+ require 'simplecov'
19
+ SimpleCov.start do
20
+ add_group "Specs", "spec/.*"
21
+ add_group "Solution", "lib/MrMurano/Solution.*"
22
+ add_group "Product", "lib/MrMurano/Product.*"
23
+
24
+ track_files "lib/MrMurano/*.rb"
25
+ end
26
+
18
27
  require 'webmock/rspec'
19
28
 
20
29
  # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: MrMurano
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.11.3
4
+ version: 1.12.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Michael Conrad Tadpol Tilstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-12-21 00:00:00.000000000 Z
11
+ date: 2017-01-05 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: commander
@@ -199,6 +199,7 @@ files:
199
199
  - Rakefile
200
200
  - TODO.taskpaper
201
201
  - bin/mr
202
+ - docs/demo.md
202
203
  - lib/MrMurano.rb
203
204
  - lib/MrMurano/Account.rb
204
205
  - lib/MrMurano/Config.rb
@@ -259,6 +260,7 @@ files:
259
260
  - spec/Account_spec.rb
260
261
  - spec/ConfigFile_spec.rb
261
262
  - spec/Config_spec.rb
263
+ - spec/Http_spec.rb
262
264
  - spec/MakePretties_spec.rb
263
265
  - spec/Mock_spec.rb
264
266
  - spec/ProductBase_spec.rb
@@ -269,22 +271,32 @@ files:
269
271
  - spec/Product_spec.rb
270
272
  - spec/Solution-Cors_spec.rb
271
273
  - spec/Solution-Endpoint_spec.rb
274
+ - spec/Solution-File_spec.rb
272
275
  - spec/Solution-ServiceConfig_spec.rb
276
+ - spec/Solution-ServiceDevice_spec.rb
273
277
  - spec/Solution-ServiceEventHandler_spec.rb
274
278
  - spec/Solution-ServiceModules_spec.rb
279
+ - spec/Solution-UsersRoles_spec.rb
280
+ - spec/Solution_spec.rb
275
281
  - spec/SyncRoot_spec.rb
282
+ - spec/SyncUpDown_spec.rb
283
+ - spec/Verbosing_spec.rb
284
+ - spec/_workspace.rb
276
285
  - spec/cmd_common.rb
277
286
  - spec/cmd_config_spec.rb
278
287
  - spec/cmd_init_spec.rb
279
288
  - spec/fixtures/.mrmuranorc
280
289
  - spec/fixtures/configfile
290
+ - spec/fixtures/dumped_config
281
291
  - spec/fixtures/mrmuranorc_deleted_bob
282
292
  - spec/fixtures/mrmuranorc_tool_bob
283
293
  - spec/fixtures/product_spec_files/example.exoline.spec.yaml
284
294
  - spec/fixtures/product_spec_files/example.murano.spec.yaml
285
295
  - spec/fixtures/product_spec_files/gwe.exoline.spec.yaml
286
296
  - spec/fixtures/product_spec_files/gwe.murano.spec.yaml
297
+ - spec/fixtures/product_spec_files/lightbulb-no-state.yaml
287
298
  - spec/fixtures/product_spec_files/lightbulb.yaml
299
+ - spec/fixtures/roles-three.yaml
288
300
  - spec/spec_helper.rb
289
301
  homepage: https://github.com/exosite/MrMurano
290
302
  licenses:
@@ -315,6 +327,7 @@ test_files:
315
327
  - spec/Account_spec.rb
316
328
  - spec/ConfigFile_spec.rb
317
329
  - spec/Config_spec.rb
330
+ - spec/Http_spec.rb
318
331
  - spec/MakePretties_spec.rb
319
332
  - spec/Mock_spec.rb
320
333
  - spec/ProductBase_spec.rb
@@ -325,20 +338,31 @@ test_files:
325
338
  - spec/Product_spec.rb
326
339
  - spec/Solution-Cors_spec.rb
327
340
  - spec/Solution-Endpoint_spec.rb
341
+ - spec/Solution-File_spec.rb
328
342
  - spec/Solution-ServiceConfig_spec.rb
343
+ - spec/Solution-ServiceDevice_spec.rb
329
344
  - spec/Solution-ServiceEventHandler_spec.rb
330
345
  - spec/Solution-ServiceModules_spec.rb
346
+ - spec/Solution-UsersRoles_spec.rb
347
+ - spec/Solution_spec.rb
331
348
  - spec/SyncRoot_spec.rb
349
+ - spec/SyncUpDown_spec.rb
350
+ - spec/Verbosing_spec.rb
351
+ - spec/_workspace.rb
332
352
  - spec/cmd_common.rb
333
353
  - spec/cmd_config_spec.rb
334
354
  - spec/cmd_init_spec.rb
335
355
  - spec/fixtures/.mrmuranorc
336
356
  - spec/fixtures/configfile
357
+ - spec/fixtures/dumped_config
337
358
  - spec/fixtures/mrmuranorc_deleted_bob
338
359
  - spec/fixtures/mrmuranorc_tool_bob
339
360
  - spec/fixtures/product_spec_files/example.exoline.spec.yaml
340
361
  - spec/fixtures/product_spec_files/example.murano.spec.yaml
341
362
  - spec/fixtures/product_spec_files/gwe.exoline.spec.yaml
342
363
  - spec/fixtures/product_spec_files/gwe.murano.spec.yaml
364
+ - spec/fixtures/product_spec_files/lightbulb-no-state.yaml
343
365
  - spec/fixtures/product_spec_files/lightbulb.yaml
366
+ - spec/fixtures/roles-three.yaml
344
367
  - spec/spec_helper.rb
368
+ has_rdoc: