MuranoCLI 2.0.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.
Files changed (151) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +28 -0
  3. data/.rspec +2 -0
  4. data/.travis.yml +21 -0
  5. data/Gemfile +27 -0
  6. data/LICENSE.txt +19 -0
  7. data/MuranoCLI.gemspec +50 -0
  8. data/MuranoCLI.iss +50 -0
  9. data/README.markdown +208 -0
  10. data/Rakefile +188 -0
  11. data/TODO.taskpaper +122 -0
  12. data/bin/mr +8 -0
  13. data/bin/murano +84 -0
  14. data/docs/demo.md +109 -0
  15. data/lib/MrMurano/Account.rb +211 -0
  16. data/lib/MrMurano/Config-Migrate.rb +47 -0
  17. data/lib/MrMurano/Config.rb +286 -0
  18. data/lib/MrMurano/Mock.rb +63 -0
  19. data/lib/MrMurano/Product-1P-Device.rb +145 -0
  20. data/lib/MrMurano/Product-Resources.rb +195 -0
  21. data/lib/MrMurano/Product.rb +358 -0
  22. data/lib/MrMurano/ProjectFile.rb +349 -0
  23. data/lib/MrMurano/Solution-Cors.rb +46 -0
  24. data/lib/MrMurano/Solution-Endpoint.rb +177 -0
  25. data/lib/MrMurano/Solution-File.rb +150 -0
  26. data/lib/MrMurano/Solution-ServiceConfig.rb +140 -0
  27. data/lib/MrMurano/Solution-Services.rb +326 -0
  28. data/lib/MrMurano/Solution-Users.rb +129 -0
  29. data/lib/MrMurano/Solution.rb +59 -0
  30. data/lib/MrMurano/SubCmdGroupContext.rb +49 -0
  31. data/lib/MrMurano/SyncUpDown.rb +565 -0
  32. data/lib/MrMurano/commands/assign.rb +57 -0
  33. data/lib/MrMurano/commands/businessList.rb +45 -0
  34. data/lib/MrMurano/commands/completion.rb +152 -0
  35. data/lib/MrMurano/commands/config.rb +67 -0
  36. data/lib/MrMurano/commands/content.rb +130 -0
  37. data/lib/MrMurano/commands/cors.rb +30 -0
  38. data/lib/MrMurano/commands/domain.rb +17 -0
  39. data/lib/MrMurano/commands/gb.rb +33 -0
  40. data/lib/MrMurano/commands/init.rb +138 -0
  41. data/lib/MrMurano/commands/keystore.rb +157 -0
  42. data/lib/MrMurano/commands/logs.rb +78 -0
  43. data/lib/MrMurano/commands/mock.rb +63 -0
  44. data/lib/MrMurano/commands/password.rb +88 -0
  45. data/lib/MrMurano/commands/postgresql.rb +41 -0
  46. data/lib/MrMurano/commands/product.rb +14 -0
  47. data/lib/MrMurano/commands/productCreate.rb +39 -0
  48. data/lib/MrMurano/commands/productDelete.rb +33 -0
  49. data/lib/MrMurano/commands/productDevice.rb +84 -0
  50. data/lib/MrMurano/commands/productDeviceIdCmds.rb +86 -0
  51. data/lib/MrMurano/commands/productList.rb +45 -0
  52. data/lib/MrMurano/commands/productWrite.rb +27 -0
  53. data/lib/MrMurano/commands/show.rb +80 -0
  54. data/lib/MrMurano/commands/solution.rb +14 -0
  55. data/lib/MrMurano/commands/solutionCreate.rb +39 -0
  56. data/lib/MrMurano/commands/solutionDelete.rb +34 -0
  57. data/lib/MrMurano/commands/solutionList.rb +45 -0
  58. data/lib/MrMurano/commands/status.rb +92 -0
  59. data/lib/MrMurano/commands/sync.rb +60 -0
  60. data/lib/MrMurano/commands/timeseries.rb +115 -0
  61. data/lib/MrMurano/commands/tsdb.rb +271 -0
  62. data/lib/MrMurano/commands/usage.rb +23 -0
  63. data/lib/MrMurano/commands/zshcomplete.erb +112 -0
  64. data/lib/MrMurano/commands.rb +32 -0
  65. data/lib/MrMurano/hash.rb +20 -0
  66. data/lib/MrMurano/http.rb +153 -0
  67. data/lib/MrMurano/makePretty.rb +75 -0
  68. data/lib/MrMurano/schema/pf-v1.0.0.yaml +114 -0
  69. data/lib/MrMurano/schema/sf-v0.2.0.yaml +77 -0
  70. data/lib/MrMurano/schema/sf-v0.3.0.yaml +78 -0
  71. data/lib/MrMurano/template/mock.erb +9 -0
  72. data/lib/MrMurano/template/projectFile.murano.erb +81 -0
  73. data/lib/MrMurano/verbosing.rb +99 -0
  74. data/lib/MrMurano/version.rb +4 -0
  75. data/lib/MrMurano.rb +20 -0
  76. data/spec/Account-Passwords_spec.rb +242 -0
  77. data/spec/Account_spec.rb +272 -0
  78. data/spec/ConfigFile_spec.rb +50 -0
  79. data/spec/ConfigMigrate_spec.rb +89 -0
  80. data/spec/Config_spec.rb +409 -0
  81. data/spec/Http_spec.rb +204 -0
  82. data/spec/MakePretties_spec.rb +118 -0
  83. data/spec/Mock_spec.rb +53 -0
  84. data/spec/ProductBase_spec.rb +113 -0
  85. data/spec/ProductContent_spec.rb +162 -0
  86. data/spec/ProductResources_spec.rb +329 -0
  87. data/spec/Product_1P_Device_spec.rb +202 -0
  88. data/spec/Product_1P_RPC_spec.rb +175 -0
  89. data/spec/Product_spec.rb +153 -0
  90. data/spec/ProjectFile_spec.rb +324 -0
  91. data/spec/Solution-Cors_spec.rb +164 -0
  92. data/spec/Solution-Endpoint_spec.rb +581 -0
  93. data/spec/Solution-File_spec.rb +212 -0
  94. data/spec/Solution-ServiceConfig_spec.rb +202 -0
  95. data/spec/Solution-ServiceDevice_spec.rb +176 -0
  96. data/spec/Solution-ServiceEventHandler_spec.rb +385 -0
  97. data/spec/Solution-ServiceModules_spec.rb +465 -0
  98. data/spec/Solution-UsersRoles_spec.rb +207 -0
  99. data/spec/Solution_spec.rb +92 -0
  100. data/spec/SyncRoot_spec.rb +83 -0
  101. data/spec/SyncUpDown_spec.rb +495 -0
  102. data/spec/Verbosing_spec.rb +279 -0
  103. data/spec/_workspace.rb +27 -0
  104. data/spec/cmd_assign_spec.rb +51 -0
  105. data/spec/cmd_business_spec.rb +59 -0
  106. data/spec/cmd_common.rb +72 -0
  107. data/spec/cmd_config_spec.rb +68 -0
  108. data/spec/cmd_content_spec.rb +71 -0
  109. data/spec/cmd_cors_spec.rb +50 -0
  110. data/spec/cmd_device_spec.rb +96 -0
  111. data/spec/cmd_domain_spec.rb +32 -0
  112. data/spec/cmd_init_spec.rb +30 -0
  113. data/spec/cmd_keystore_spec.rb +97 -0
  114. data/spec/cmd_password_spec.rb +62 -0
  115. data/spec/cmd_status_spec.rb +239 -0
  116. data/spec/cmd_syncdown_spec.rb +86 -0
  117. data/spec/cmd_syncup_spec.rb +62 -0
  118. data/spec/cmd_usage_spec.rb +36 -0
  119. data/spec/fixtures/.mrmuranorc +9 -0
  120. data/spec/fixtures/ProjectFiles/invalid.yaml +9 -0
  121. data/spec/fixtures/ProjectFiles/only_meta.yaml +24 -0
  122. data/spec/fixtures/ProjectFiles/with_routes.yaml +27 -0
  123. data/spec/fixtures/SolutionFiles/0.2.0.json +20 -0
  124. data/spec/fixtures/SolutionFiles/0.2.0_invalid.json +18 -0
  125. data/spec/fixtures/SolutionFiles/0.2.json +21 -0
  126. data/spec/fixtures/SolutionFiles/0.3.0.json +20 -0
  127. data/spec/fixtures/SolutionFiles/0.3.0_invalid.json +19 -0
  128. data/spec/fixtures/SolutionFiles/0.3.json +20 -0
  129. data/spec/fixtures/SolutionFiles/basic.json +20 -0
  130. data/spec/fixtures/SolutionFiles/secret.json +6 -0
  131. data/spec/fixtures/configfile +9 -0
  132. data/spec/fixtures/dumped_config +42 -0
  133. data/spec/fixtures/mrmuranorc_deleted_bob +8 -0
  134. data/spec/fixtures/mrmuranorc_tool_bob +3 -0
  135. data/spec/fixtures/product_spec_files/example.exoline.spec.yaml +116 -0
  136. data/spec/fixtures/product_spec_files/example.murano.spec.yaml +14 -0
  137. data/spec/fixtures/product_spec_files/gwe.exoline.spec.yaml +21 -0
  138. data/spec/fixtures/product_spec_files/gwe.murano.spec.yaml +16 -0
  139. data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
  140. data/spec/fixtures/product_spec_files/lightbulb.yaml +14 -0
  141. data/spec/fixtures/roles-three.yaml +11 -0
  142. data/spec/fixtures/syncable_content/assets/icon.png +0 -0
  143. data/spec/fixtures/syncable_content/assets/index.html +0 -0
  144. data/spec/fixtures/syncable_content/assets/js/script.js +0 -0
  145. data/spec/fixtures/syncable_content/modules/table_util.lua +58 -0
  146. data/spec/fixtures/syncable_content/routes/manyRoutes.lua +11 -0
  147. data/spec/fixtures/syncable_content/routes/singleRoute.lua +5 -0
  148. data/spec/fixtures/syncable_content/services/devdata.lua +18 -0
  149. data/spec/fixtures/syncable_content/services/timers.lua +4 -0
  150. data/spec/spec_helper.rb +119 -0
  151. metadata +498 -0
@@ -0,0 +1,324 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Config'
3
+ require 'MrMurano/ProjectFile'
4
+ require '_workspace'
5
+ require 'fileutils'
6
+ #require 'tempfile'
7
+ #require 'erb'
8
+
9
+ RSpec.describe MrMurano::ProjectFile do
10
+
11
+ context "Basics " do
12
+ include_context "WORKSPACE"
13
+ before(:example) do
14
+ $cfg = MrMurano::Config.new
15
+ $cfg.load
16
+ $cfg['user.name'] = 'bob@builder.co'
17
+ $project = nil
18
+ end
19
+
20
+ context "No files to load" do
21
+ context "Defaults" do
22
+ before(:example) do
23
+ @pjf = MrMurano::ProjectFile.new
24
+ #@pjf.load
25
+ end
26
+ it "Info" do
27
+ expect(@pjf.get('info.name')).to eq('project')
28
+ expect(@pjf.get('info.summary')).to eq('One line summary of project')
29
+ expect(@pjf.get('info.description')).to eq("In depth description of project\n\nWith lots of details.")
30
+ expect(@pjf.get('info.authors')).to eq(['bob@builder.co'])
31
+ expect(@pjf.get('info.version')).to eq('1.0.0')
32
+ end
33
+
34
+ it "Assets" do
35
+ # Because defaults before load() are all nil, the default_value_for method
36
+ # is called.
37
+ expect(@pjf).to receive(:default_value_for).with('assets.location').and_return('here')
38
+ expect(@pjf.get('assets.location')).to eq('here')
39
+
40
+ expect(@pjf).to receive(:default_value_for).with('assets.include').and_return(['here'])
41
+ expect(@pjf.get('assets.include')).to eq(['here'])
42
+
43
+ expect(@pjf).to receive(:default_value_for).with('assets.exclude').and_return(['here'])
44
+ expect(@pjf.get('assets.exclude')).to eq(['here'])
45
+
46
+ expect(@pjf).to receive(:default_value_for).with('assets.default_page').and_return('here')
47
+ expect(@pjf.get('assets.default_page')).to eq('here')
48
+ end
49
+
50
+ it "Modules" do
51
+ # Because defaults before load() are all nil, the default_value_for method
52
+ # is called.
53
+ expect(@pjf).to receive(:default_value_for).with('modules.location').and_return('here')
54
+ expect(@pjf.get('modules.location')).to eq('here')
55
+
56
+ expect(@pjf).to receive(:default_value_for).with('modules.include').and_return(['here'])
57
+ expect(@pjf.get('modules.include')).to eq(['here'])
58
+
59
+ expect(@pjf).to receive(:default_value_for).with('modules.exclude').and_return(['here'])
60
+ expect(@pjf.get('modules.exclude')).to eq(['here'])
61
+ end
62
+
63
+ it "Routes" do
64
+ # Because defaults before load() are all nil, the default_value_for method
65
+ # is called.
66
+ expect(@pjf).to receive(:default_value_for).with('routes.location').and_return('here')
67
+ expect(@pjf.get('routes.location')).to eq('here')
68
+
69
+ expect(@pjf).to receive(:default_value_for).with('routes.include').and_return(['here'])
70
+ expect(@pjf.get('routes.include')).to eq(['here'])
71
+
72
+ expect(@pjf).to receive(:default_value_for).with('routes.exclude').and_return(['here'])
73
+ expect(@pjf.get('routes.exclude')).to eq(['here'])
74
+ end
75
+
76
+ it "Services" do
77
+ # Because defaults before load() are all nil, the default_value_for method
78
+ # is called.
79
+ expect(@pjf).to receive(:default_value_for).with('services.location').and_return('here')
80
+ expect(@pjf.get('services.location')).to eq('here')
81
+
82
+ expect(@pjf).to receive(:default_value_for).with('services.include').and_return(['here'])
83
+ expect(@pjf.get('services.include')).to eq(['here'])
84
+
85
+ expect(@pjf).to receive(:default_value_for).with('services.exclude').and_return(['here'])
86
+ expect(@pjf.get('services.exclude')).to eq(['here'])
87
+ end
88
+ end
89
+
90
+ context "Bad Keys" do
91
+ before(:example) do
92
+ @pjf = MrMurano::ProjectFile.new
93
+ end
94
+ it "Empty" do
95
+ expect{@pjf.get('')}.to raise_error("Empty key")
96
+ end
97
+ it "No dot" do
98
+ expect{@pjf.get('info')}.to raise_error("Missing dot")
99
+ end
100
+ it "Undefined key" do
101
+ expect{@pjf.get('info.bob')}.to raise_error("no member 'bob' in struct")
102
+ end
103
+ it "Undefined section" do
104
+ expect{@pjf.get('sob.include')}.to raise_error(NameError)
105
+ end
106
+ it "Missing key" do
107
+ expect{@pjf.get('info.')}.to raise_error("Missing key")
108
+ end
109
+ it "Missing section" do
110
+ expect{@pjf.get('.include')}.to raise_error("no member '' in struct")
111
+ end
112
+ end
113
+
114
+ context "default_value_for mapping" do
115
+ before(:example) do
116
+ @pjf = MrMurano::ProjectFile.new
117
+ end
118
+
119
+ it "returns nil for unmapped key." do
120
+ expect(@pjf.default_value_for('foooood')).to be_nil
121
+ end
122
+
123
+ it "hits $cfg if mapped key" do
124
+ expect($cfg).to receive(:get).with('location.endpoints').and_return('beef')
125
+ expect(@pjf.default_value_for('routes.location')).to eq('beef')
126
+ end
127
+
128
+ it "returns array for split values" do
129
+ expect($cfg).to receive(:get).with('endpoints.searchFor').and_return('beef')
130
+ expect(@pjf.default_value_for('routes.include')).to eq(['beef'])
131
+
132
+ expect($cfg).to receive(:get).with('endpoints.searchFor').and_return('beef and potatoes')
133
+ expect(@pjf.default_value_for('routes.include')).to eq(['beef','and','potatoes'])
134
+ end
135
+ end
136
+ end
137
+
138
+ context "Calling load" do
139
+ before(:example) do
140
+ @pjf = MrMurano::ProjectFile.new
141
+ end
142
+
143
+ context "load just meta" do
144
+ before(:example) do
145
+ src = File.join(@testdir, 'spec/fixtures/ProjectFiles/only_meta.yaml')
146
+ dst = File.join(@projectDir, 'meta.murano')
147
+ FileUtils.copy(src, dst)
148
+ @pjf.load
149
+ end
150
+ it "has the name" do
151
+ expect(@pjf.get('info.name')).to eq('tested')
152
+ end
153
+ it "has version" do
154
+ expect(@pjf.get('info.version')).to eq('1.56.12')
155
+ end
156
+
157
+ it "fails back to $cfg" do
158
+ expect(@pjf).to receive(:default_value_for).with('routes.include').and_return(['here'])
159
+ expect(@pjf.get('routes.include')).to eq(['here'])
160
+ end
161
+ end
162
+
163
+ context "load custom routes" do
164
+ before(:example) do
165
+ src = File.join(@testdir, 'spec/fixtures/ProjectFiles/with_routes.yaml')
166
+ dst = File.join(@projectDir, 'meta.murano')
167
+ FileUtils.copy(src, dst)
168
+ @pjf.load
169
+ end
170
+ it "has the name" do
171
+ expect(@pjf.get('info.name')).to eq('tested')
172
+ end
173
+ it "has version" do
174
+ expect(@pjf.get('info.version')).to eq('1.56.12')
175
+ end
176
+ it "does not fail back to $cfg" do
177
+ expect(@pjf).to_not receive(:default_value_for)
178
+ expect(@pjf.get('routes.include')).to eq(['custom_api.lua'])
179
+ end
180
+ end
181
+
182
+ it "reports validation errors" do
183
+ src = File.join(@testdir, 'spec/fixtures/ProjectFiles/invalid.yaml')
184
+ dst = File.join(@projectDir, 'meta.murano')
185
+ FileUtils.copy(src, dst)
186
+
187
+ saved = $stderr
188
+ $stderr = StringIO.new
189
+ expect(@pjf.load).to eq(-5)
190
+ expect($stderr.string).to match(%r{The property '#/info' did not contain a required property of 'description'})
191
+ $stderr = saved
192
+ end
193
+
194
+ end
195
+ end
196
+
197
+ context "Solutionfile 0.2.0" do
198
+ include_context "WORKSPACE"
199
+ before(:example) do
200
+ $cfg = MrMurano::Config.new
201
+ $cfg.load
202
+ $cfg['user.name'] = 'bob@builder.co'
203
+ $project = nil
204
+ @pjf = MrMurano::ProjectFile.new
205
+ end
206
+
207
+ it "Reports validation errors" do
208
+ src = File.join(@testdir, 'spec/fixtures/SolutionFiles/0.2.0_invalid.json')
209
+ dst = File.join(@projectDir, 'Solutionfile.json')
210
+ FileUtils.copy(src, dst)
211
+ saved = $stderr
212
+ $stderr = StringIO.new
213
+ @pjf.load
214
+ expect($stderr.string).to match(%r{The property '#/' did not contain a required property of 'custom_api'})
215
+ $stderr = saved
216
+ end
217
+
218
+ it "loads with truncated version" do
219
+ src = File.join(@testdir, 'spec/fixtures/SolutionFiles/0.2.json')
220
+ dst = File.join(@projectDir, 'Solutionfile.json')
221
+ FileUtils.copy(src, dst)
222
+ saved = $stderr
223
+ $stderr = StringIO.new
224
+ @pjf.load
225
+ expect($stderr.string).to eq('')
226
+ $stderr = saved
227
+ end
228
+
229
+ context "loads" do
230
+ before(:example) do
231
+ src = File.join(@testdir, 'spec/fixtures/SolutionFiles/0.2.0.json')
232
+ dst = File.join(@projectDir, 'Solutionfile.json')
233
+ FileUtils.copy(src, dst)
234
+ @pjf.load
235
+ end
236
+ it "defines assets" do
237
+ expect(@pjf.get('assets.default_page')).to eq('index.html')
238
+ expect(@pjf.get('assets.location')).to eq('public')
239
+ expect(@pjf.get('assets.include')).to eq(['**/*'])
240
+ end
241
+
242
+ it "defines routes" do
243
+ expect(@pjf['routes.location']).to eq ('.')
244
+ expect(@pjf.get('routes.include')).to eq(['sample_api.lua'])
245
+ end
246
+
247
+ it "defines modules" do
248
+ expect(@pjf['modules.location']).to eq ('.')
249
+ expect(@pjf['modules.include']).to match_array(["modules/debug.lua", "modules/listen.lua", "modules/util.lua"])
250
+ end
251
+
252
+ it "defines services" do
253
+ expect(@pjf['services.location']).to eq ('.')
254
+ expect(@pjf['services.include']).to match_array(["event_handler/product.lua", "event_handler/timer.lua"])
255
+ end
256
+
257
+ end
258
+ end
259
+
260
+ context "Solutionfile 0.3.0" do
261
+ include_context "WORKSPACE"
262
+ before(:example) do
263
+ $cfg = MrMurano::Config.new
264
+ $cfg.load
265
+ $cfg['user.name'] = 'bob@builder.co'
266
+ $project = nil
267
+ @pjf = MrMurano::ProjectFile.new
268
+ end
269
+
270
+ it "Reports validation errors" do
271
+ src = File.join(@testdir, 'spec/fixtures/SolutionFiles/0.3.0_invalid.json')
272
+ dst = File.join(@projectDir, 'Solutionfile.json')
273
+ FileUtils.copy(src, dst)
274
+ saved = $stderr
275
+ $stderr = StringIO.new
276
+ @pjf.load
277
+ expect($stderr.string).to match(%r{The property '#/' did not contain a required property of 'routes'})
278
+ $stderr = saved
279
+ end
280
+
281
+ it "loads with truncated version" do
282
+ src = File.join(@testdir, 'spec/fixtures/SolutionFiles/0.3.json')
283
+ dst = File.join(@projectDir, 'Solutionfile.json')
284
+ FileUtils.copy(src, dst)
285
+ saved = $stderr
286
+ $stderr = StringIO.new
287
+ @pjf.load
288
+ expect($stderr.string).to eq('')
289
+ $stderr = saved
290
+ end
291
+
292
+ context "loads" do
293
+ before(:example) do
294
+ src = File.join(@testdir, 'spec/fixtures/SolutionFiles/0.3.0.json')
295
+ dst = File.join(@projectDir, 'Solutionfile.json')
296
+ FileUtils.copy(src, dst)
297
+ @pjf.load
298
+ end
299
+ it "defines assets" do
300
+ expect(@pjf.get('assets.default_page')).to eq('index.html')
301
+ expect(@pjf.get('assets.location')).to eq('public')
302
+ expect(@pjf.get('assets.include')).to eq(['**/*'])
303
+ end
304
+
305
+ it "defines routes" do
306
+ expect(@pjf['routes.location']).to eq ('.')
307
+ expect(@pjf.get('routes.include')).to eq(['sample_api.lua'])
308
+ end
309
+
310
+ it "defines modules" do
311
+ expect(@pjf['modules.location']).to eq ('.')
312
+ expect(@pjf['modules.include']).to match_array(["modules/debug.lua", "modules/listen.lua", "modules/util.lua"])
313
+ end
314
+
315
+ it "defines services" do
316
+ expect(@pjf['services.location']).to eq ('.')
317
+ expect(@pjf['services.include']).to match_array(["event_handler/product.lua", "event_handler/timer.lua"])
318
+ end
319
+
320
+ end
321
+ end
322
+ end
323
+
324
+ # vim: set ai et sw=2 ts=2 :
@@ -0,0 +1,164 @@
1
+ require 'MrMurano/version'
2
+ require 'MrMurano/Solution-Cors'
3
+ require 'MrMurano/ProjectFile'
4
+ require 'tempfile'
5
+ require 'yaml'
6
+ require '_workspace'
7
+
8
+ RSpec.describe MrMurano::Cors do
9
+ include_context "WORKSPACE"
10
+ before(:example) do
11
+ MrMurano::SyncRoot.reset
12
+ $cfg = MrMurano::Config.new
13
+ $cfg.load
14
+ $cfg['net.host'] = 'bizapi.hosted.exosite.io'
15
+ $cfg['solution.id'] = 'XYZ'
16
+
17
+ @srv = MrMurano::Cors.new
18
+ allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
19
+ end
20
+
21
+ it "initializes" do
22
+ uri = @srv.endPoint('/')
23
+ expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors/")
24
+ end
25
+
26
+ context "when server gives string" do
27
+ context "fetches" do
28
+ it "as a hash" do
29
+ cors = {:origin=>true,
30
+ :methods=>["HEAD","GET","POST","PUT","DELETE","OPTIONS","PATCH"],
31
+ :headers=>["Content-Type","Cookie","Authorization"],
32
+ :credentials=>true}
33
+ body = {:cors=>cors.to_json}
34
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
35
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
36
+ 'Content-Type'=>'application/json'}).
37
+ to_return(body: body.to_json)
38
+
39
+ ret = @srv.fetch()
40
+ expect(ret).to eq(cors)
41
+ end
42
+ it "as a block" do
43
+ cors = {:origin=>true,
44
+ :methods=>["HEAD","GET","POST","PUT","DELETE","OPTIONS","PATCH"],
45
+ :headers=>["Content-Type","Cookie","Authorization"],
46
+ :credentials=>true}
47
+ body = {:cors=>cors.to_json}
48
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
49
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
50
+ 'Content-Type'=>'application/json'}).
51
+ to_return(body: body.to_json)
52
+
53
+ ret = ''
54
+ loops = 0
55
+ @srv.fetch() do |chunk|
56
+ loops += 1
57
+ ret << chunk
58
+ expect(loops).to be <= 1
59
+ end
60
+ expect(ret).to eq(Hash.transform_keys_to_strings(cors).to_yaml)
61
+ end
62
+ end
63
+ end
64
+
65
+ context "when server gives object" do
66
+ context "fetches" do
67
+ it "as a hash" do
68
+ cors = {:origin=>true,
69
+ :methods=>["HEAD","GET","POST","PUT","DELETE","OPTIONS","PATCH"],
70
+ :headers=>["Content-Type","Cookie","Authorization"],
71
+ :credentials=>true}
72
+ body = cors
73
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
74
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
75
+ 'Content-Type'=>'application/json'}).
76
+ to_return(body: body.to_json)
77
+
78
+ ret = @srv.fetch()
79
+ expect(ret).to eq(cors)
80
+ end
81
+ it "as a block" do
82
+ cors = {:origin=>true,
83
+ :methods=>["HEAD","GET","POST","PUT","DELETE","OPTIONS","PATCH"],
84
+ :headers=>["Content-Type","Cookie","Authorization"],
85
+ :credentials=>true}
86
+ body = cors
87
+ stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
88
+ with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
89
+ 'Content-Type'=>'application/json'}).
90
+ to_return(body: body.to_json)
91
+
92
+ ret = ''
93
+ loops = 0
94
+ @srv.fetch() do |chunk|
95
+ loops += 1
96
+ ret << chunk
97
+ expect(loops).to be <= 1
98
+ end
99
+ expect(ret).to eq(Hash.transform_keys_to_strings(cors).to_yaml)
100
+ end
101
+ end
102
+ end
103
+
104
+ context "uploads" do
105
+ before(:example) do
106
+ $project = MrMurano::ProjectFile.new
107
+ $project.load
108
+ @cors = {:origin=>true,
109
+ :methods=>["HEAD","GET","POST","PUT","DELETE","OPTIONS","PATCH"],
110
+ :headers=>["Content-Type","Cookie","Authorization"],
111
+ :credentials=>true}
112
+ end
113
+ it "specified file" do
114
+ File.open(File.join(@projectDir, 'bob.yaml'), 'w'){|io| io << @cors.to_yaml}
115
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
116
+ with(:body=>@cors.to_json,
117
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
118
+ 'Content-Type'=>'application/json'}).
119
+ to_return(body: "")
120
+
121
+ ret = @srv.upload('bob.yaml')
122
+ expect(ret).to eq({})
123
+ end
124
+
125
+ it "file in $project" do
126
+ File.open(File.join(@projectDir, 'bob.yaml'), 'w'){|io| io << @cors.to_yaml}
127
+ $project['routes.cors'] = 'bob.yaml'
128
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
129
+ with(:body=>@cors.to_json,
130
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
131
+ 'Content-Type'=>'application/json'}).
132
+ to_return(body: "")
133
+
134
+ ret = @srv.upload()
135
+ expect(ret).to eq({})
136
+ end
137
+
138
+ it "file defaults thru $project" do
139
+ File.open(File.join(@projectDir, 'cors.yaml'), 'w'){|io| io << @cors.to_yaml}
140
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
141
+ with(:body=>@cors.to_json,
142
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
143
+ 'Content-Type'=>'application/json'}).
144
+ to_return(body: "")
145
+
146
+ ret = @srv.upload()
147
+ expect(ret).to eq({})
148
+ end
149
+
150
+ it "cors in $project" do
151
+ $project['routes.cors'] = @cors
152
+ stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/cors").
153
+ with(:body=>@cors.to_json,
154
+ :headers=>{'Authorization'=>'token TTTTTTTTTT',
155
+ 'Content-Type'=>'application/json'}).
156
+ to_return(body: "")
157
+
158
+ ret = @srv.upload()
159
+ expect(ret).to eq({})
160
+ end
161
+ end
162
+
163
+ end
164
+ # vim: set ai et sw=2 ts=2 :