MuranoCLI 3.0.2 → 3.0.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +30 -59
- data/Gemfile +9 -3
- data/MuranoCLI.gemspec +11 -4
- data/bin/murano +2 -90
- data/lib/MrMurano.rb +5 -1
- data/lib/MrMurano/{spec_commander.rb → Commander-Entry.rb} +1 -2
- data/lib/MrMurano/Solution.rb +12 -15
- data/lib/MrMurano/SolutionId.rb +1 -5
- data/lib/MrMurano/SyncAllowed.rb +2 -2
- data/lib/MrMurano/SyncUpDown.rb +6 -3
- data/lib/MrMurano/progress.rb +11 -2
- data/lib/MrMurano/verbosing.rb +3 -2
- data/lib/MrMurano/version.rb +2 -2
- data/spec/Account-Passwords_spec.rb +34 -48
- data/spec/Account_spec.rb +58 -63
- data/spec/Business_spec.rb +151 -139
- data/spec/ConfigFile_spec.rb +15 -11
- data/spec/ConfigMigrate_spec.rb +23 -12
- data/spec/Config_spec.rb +57 -54
- data/spec/Content_spec.rb +233 -201
- data/spec/GatewayBase_spec.rb +35 -27
- data/spec/GatewayDevice_spec.rb +149 -149
- data/spec/GatewayResource_spec.rb +115 -102
- data/spec/GatewaySettings_spec.rb +69 -62
- data/spec/Http_spec.rb +66 -56
- data/spec/MakePretties_spec.rb +82 -73
- data/spec/Mock_spec.rb +38 -29
- data/spec/ProjectFile_spec.rb +118 -106
- data/spec/Setting_spec.rb +24 -15
- data/spec/Solution-ServiceConfig_spec.rb +168 -140
- data/spec/Solution-ServiceEventHandler_spec.rb +186 -188
- data/spec/Solution-ServiceModules_spec.rb +314 -232
- data/spec/Solution-UsersRoles_spec.rb +136 -86
- data/spec/Solution_spec.rb +78 -50
- data/spec/SyncRoot_spec.rb +26 -24
- data/spec/SyncUpDown_spec.rb +268 -249
- data/spec/Verbosing_spec.rb +95 -93
- data/spec/Webservice-Cors_spec.rb +141 -95
- data/spec/Webservice-Endpoint_spec.rb +382 -346
- data/spec/Webservice-File_spec.rb +148 -109
- data/spec/Webservice-Setting_spec.rb +47 -41
- data/spec/cmd_business_spec.rb +17 -17
- data/spec/cmd_common.rb +27 -7
- data/spec/cmd_config_spec.rb +31 -20
- data/spec/cmd_content_spec.rb +80 -68
- data/spec/cmd_cors_spec.rb +11 -5
- data/spec/cmd_device_spec.rb +16 -14
- data/spec/cmd_domain_spec.rb +10 -8
- data/spec/cmd_exchange_spec.rb +3 -3
- data/spec/cmd_init_spec.rb +100 -101
- data/spec/cmd_keystore_spec.rb +17 -12
- data/spec/cmd_link_spec.rb +22 -37
- data/spec/cmd_password_spec.rb +11 -7
- data/spec/cmd_setting_application_spec.rb +47 -33
- data/spec/cmd_setting_product_spec.rb +32 -27
- data/spec/cmd_status_spec.rb +125 -114
- data/spec/cmd_syncdown_spec.rb +70 -65
- data/spec/cmd_syncup_spec.rb +19 -15
- data/spec/cmd_usage_spec.rb +14 -10
- metadata +29 -15
@@ -1,3 +1,10 @@
|
|
1
|
+
# Last Modified: 2017.09.12 /coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2016-2017 Exosite LLC.
|
5
|
+
# License: MIT. See LICENSE.txt.
|
6
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
7
|
+
|
1
8
|
require 'fileutils'
|
2
9
|
require 'MrMurano/version'
|
3
10
|
require 'MrMurano/Gateway'
|
@@ -6,7 +13,7 @@ require 'MrMurano/SyncRoot'
|
|
6
13
|
require '_workspace'
|
7
14
|
|
8
15
|
RSpec.describe MrMurano::Gateway::Resources do
|
9
|
-
include_context
|
16
|
+
include_context 'WORKSPACE'
|
10
17
|
before(:example) do
|
11
18
|
MrMurano::SyncRoot.instance.reset
|
12
19
|
$cfg = MrMurano::Config.new
|
@@ -17,87 +24,89 @@ RSpec.describe MrMurano::Gateway::Resources do
|
|
17
24
|
$project.load
|
18
25
|
|
19
26
|
@gw = MrMurano::Gateway::Resources.new
|
20
|
-
allow(@gw).to receive(:token).and_return(
|
27
|
+
allow(@gw).to receive(:token).and_return('TTTTTTTTTT')
|
21
28
|
end
|
22
29
|
|
23
|
-
it
|
30
|
+
it 'initializes' do
|
24
31
|
uri = @gw.endpoint('/')
|
25
|
-
expect(uri.to_s).to eq(
|
32
|
+
expect(uri.to_s).to eq('https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/')
|
26
33
|
end
|
27
34
|
|
28
|
-
it
|
35
|
+
it 'lists' do
|
29
36
|
resources = [
|
30
|
-
{:
|
31
|
-
{:
|
32
|
-
{:
|
37
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
38
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'fuzz' },
|
39
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
33
40
|
]
|
34
|
-
body = { :
|
35
|
-
:
|
36
|
-
:
|
37
|
-
:
|
38
|
-
}}
|
39
|
-
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
40
|
-
to_return(:body
|
41
|
+
body = { resources: {
|
42
|
+
bob: { format: 'string', unit: 'c', settable: true },
|
43
|
+
fuzz: { format: 'string', unit: 'c', settable: true },
|
44
|
+
gruble: { format: 'string', unit: 'bits', settable: true },
|
45
|
+
}, }
|
46
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
47
|
+
.to_return(body: body.to_json)
|
41
48
|
|
42
49
|
ret = @gw.list
|
43
50
|
expect(ret).to eq(resources)
|
44
51
|
end
|
45
52
|
|
46
|
-
it
|
53
|
+
it 'uploads all' do
|
47
54
|
res_before = [
|
48
|
-
{:
|
49
|
-
{:
|
50
|
-
{:
|
55
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
56
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'fuzz' },
|
57
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
51
58
|
]
|
52
59
|
res_after = {
|
53
|
-
:
|
54
|
-
:
|
55
|
-
:
|
60
|
+
bob: { format: 'string', unit: 'c', settable: true },
|
61
|
+
fuzz: { format: 'string', unit: 'c', settable: true },
|
62
|
+
gruble: { format: 'string', unit: 'bits', settable: true },
|
56
63
|
}
|
57
|
-
stub_request(:patch, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
58
|
-
with(:
|
64
|
+
stub_request(:patch, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
65
|
+
.with(body: { resources: res_after }.to_json)
|
59
66
|
|
60
67
|
ret = @gw.upload_all(res_before)
|
61
68
|
expect(ret).to eq({})
|
62
69
|
end
|
63
70
|
|
64
|
-
context
|
71
|
+
context 'compares' do
|
65
72
|
before(:example) do
|
66
|
-
@
|
67
|
-
@
|
73
|
+
@i_a = { format: 'string', unit: 'c', settable: true, alias: 'bob' }
|
74
|
+
@i_b = { format: 'string', unit: 'c', settable: true, alias: 'bob' }
|
68
75
|
end
|
69
|
-
it
|
70
|
-
ret = @gw.docmp(@
|
76
|
+
it 'Are equal' do
|
77
|
+
ret = @gw.docmp(@i_a, @i_b)
|
71
78
|
expect(ret).to eq(false)
|
72
79
|
end
|
73
80
|
end
|
74
81
|
|
75
|
-
context
|
76
|
-
it
|
82
|
+
context 'Lookup functions' do
|
83
|
+
it 'local path is into' do
|
77
84
|
ret = @gw.tolocalpath('bob', 'rich')
|
78
85
|
expect(ret).to eq('bob')
|
79
86
|
end
|
80
87
|
|
81
|
-
it
|
82
|
-
ret = @gw.synckey(
|
83
|
-
expect(ret).to eq(
|
88
|
+
it 'gets synckey' do
|
89
|
+
ret = @gw.synckey(alias: 'bob')
|
90
|
+
expect(ret).to eq('bob')
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
87
|
-
context
|
88
|
-
it
|
94
|
+
context 'local items' do
|
95
|
+
it 'succeeds' do
|
89
96
|
resfile = Pathname.new('resources.yaml')
|
90
97
|
src = File.join(@testdir, 'spec', 'fixtures', 'gateway_resource_files', 'resources.yaml')
|
91
98
|
FileUtils.copy(src, resfile.to_path)
|
92
99
|
ret = @gw.localitems(resfile)
|
93
|
-
expect(ret).to eq(
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
100
|
+
expect(ret).to eq(
|
101
|
+
[
|
102
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
103
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'fuzz' },
|
104
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
105
|
+
]
|
106
|
+
)
|
98
107
|
end
|
99
108
|
|
100
|
-
it
|
109
|
+
it 'missing file' do
|
101
110
|
resfile = Pathname.new('resources.yaml')
|
102
111
|
saved = $stderr
|
103
112
|
$stderr = StringIO.new
|
@@ -123,9 +132,9 @@ RSpec.describe MrMurano::Gateway::Resources do
|
|
123
132
|
src = File.join(@testdir, 'spec', 'fixtures', 'gateway_resource_files', 'resources.notyaml')
|
124
133
|
FileUtils.copy(src, resfile.to_path)
|
125
134
|
#expect{ @gw.localitems(resfile) }.to raise_error(JSON::Schema::ValidationError)
|
126
|
-
expect
|
135
|
+
expect do
|
127
136
|
@gw.localitems(resfile)
|
128
|
-
|
137
|
+
end.to raise_error(SystemExit).and output("\e[31mThere is an error in the config file, resources.yaml\e[0m\n\e[31m\"The property '#/' of type Array did not match the following type: object\"\e[0m\n").to_stderr
|
129
138
|
end
|
130
139
|
|
131
140
|
it "isn't valid" do
|
@@ -133,58 +142,63 @@ RSpec.describe MrMurano::Gateway::Resources do
|
|
133
142
|
src = File.join(@testdir, 'spec', 'fixtures', 'gateway_resource_files', 'resources.notyaml')
|
134
143
|
FileUtils.copy(src, resfile.to_path)
|
135
144
|
#expect{ @gw.localitems(resfile) }.to raise_error(JSON::Schema::ValidationError)
|
136
|
-
expect
|
145
|
+
expect do
|
137
146
|
@gw.localitems(resfile)
|
138
|
-
|
147
|
+
end.to raise_error(SystemExit).and output("\e[31mThere is an error in the config file, resources.yaml\e[0m\n\e[31m\"The property '#/' of type Array did not match the following type: object\"\e[0m\n").to_stderr
|
139
148
|
end
|
140
149
|
end
|
141
150
|
|
142
|
-
context
|
151
|
+
context 'syncup' do
|
143
152
|
before(:example) do
|
144
|
-
expect(@gw).to receive(:list).once.and_return(
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
153
|
+
expect(@gw).to receive(:list).once.and_return(
|
154
|
+
[
|
155
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
156
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'fuzz' },
|
157
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
158
|
+
]
|
159
|
+
)
|
149
160
|
end
|
150
|
-
it
|
151
|
-
expect(@gw).to receive(:upload_all).with(
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
161
|
+
it 'removes keys' do
|
162
|
+
expect(@gw).to receive(:upload_all).with(
|
163
|
+
[
|
164
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
165
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
166
|
+
]
|
167
|
+
)
|
156
168
|
@gw.syncup_before
|
157
169
|
@gw.remove('fuzz')
|
158
170
|
@gw.syncup_after
|
159
171
|
end
|
160
172
|
|
161
|
-
it
|
162
|
-
expect(@gw).to receive(:upload_all).with(
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
173
|
+
it 'adds keys' do
|
174
|
+
expect(@gw).to receive(:upload_all).with(
|
175
|
+
[
|
176
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
177
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'fuzz' },
|
178
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
179
|
+
{ format: 'number', unit: 'bibs', settable: false, alias: 'greeble' },
|
180
|
+
]
|
181
|
+
)
|
169
182
|
@gw.syncup_before
|
170
|
-
@gw.upload(nil, {:
|
183
|
+
@gw.upload(nil, { format: 'number', unit: 'bibs', settable: false, alias: 'greeble' }, nil)
|
171
184
|
@gw.syncup_after
|
172
185
|
end
|
173
186
|
|
174
|
-
it
|
175
|
-
expect(@gw).to receive(:upload_all).with(
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
187
|
+
it 'replaces keys' do
|
188
|
+
expect(@gw).to receive(:upload_all).with(
|
189
|
+
[
|
190
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
191
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
192
|
+
{ format: 'number', unit: 'bibs', settable: false, alias: 'fuzz' },
|
193
|
+
]
|
194
|
+
)
|
181
195
|
@gw.syncup_before
|
182
|
-
@gw.upload(nil, {:
|
196
|
+
@gw.upload(nil, { format: 'number', unit: 'bibs', settable: false, alias: 'fuzz' }, nil)
|
183
197
|
@gw.syncup_after
|
184
198
|
end
|
185
199
|
end
|
186
200
|
|
187
|
-
context
|
201
|
+
context 'syncdown' do
|
188
202
|
before(:example) do
|
189
203
|
# 2017-07-05: [lb] not sure what I had to add this just now;
|
190
204
|
# this test had been working fine... I added a check for
|
@@ -201,66 +215,65 @@ RSpec.describe MrMurano::Gateway::Resources do
|
|
201
215
|
|
202
216
|
expect(@gw).to receive(:locallist).once.and_return(
|
203
217
|
[
|
204
|
-
{:
|
205
|
-
{:
|
206
|
-
{:
|
218
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'bob' },
|
219
|
+
{ format: 'string', unit: 'c', settable: true, alias: 'fuzz' },
|
220
|
+
{ format: 'string', unit: 'bits', settable: true, alias: 'gruble' },
|
207
221
|
],
|
208
222
|
# 2017-07-05: [lb] also had to remove this check.
|
209
223
|
# locallist returns a single array, not two of them!
|
210
224
|
#[],
|
211
225
|
)
|
212
226
|
|
213
|
-
@io = instance_double(
|
227
|
+
@io = instance_double('IO')
|
214
228
|
@p = instance_double('Pathname')
|
215
229
|
expect(@p).to receive(:dirname).and_return(resfile.dirname)
|
216
230
|
expect(@p).to receive(:extname).and_return(resfile.extname)
|
217
231
|
expect(@p).to receive(:open).and_yield(@io)
|
218
232
|
end
|
219
|
-
it
|
233
|
+
it 'removes keys' do
|
220
234
|
expect(@io).to receive(:write) do |args|
|
221
235
|
fy = YAML.load(args)
|
222
|
-
expect(fy).to eq(
|
223
|
-
'bob'=>{'format'=>
|
224
|
-
'gruble'=>{'format'=>
|
225
|
-
|
236
|
+
expect(fy).to eq(
|
237
|
+
'bob' => { 'format' => 'string', 'unit' => 'c', 'settable' => true },
|
238
|
+
'gruble' => { 'format' => 'string', 'unit' => 'bits', 'settable' => true }
|
239
|
+
)
|
226
240
|
end
|
227
241
|
|
228
242
|
@gw.syncdown_before
|
229
|
-
@gw.removelocal(@p,
|
243
|
+
@gw.removelocal(@p, alias: 'fuzz')
|
230
244
|
@gw.syncdown_after(@p)
|
231
245
|
end
|
232
246
|
|
233
|
-
it
|
247
|
+
it 'adds keys' do
|
234
248
|
expect(@io).to receive(:write) do |args|
|
235
249
|
fy = YAML.load(args)
|
236
|
-
expect(fy).to eq(
|
237
|
-
'bob'=>{'format'=>
|
238
|
-
'gruble'=>{'format'=>
|
239
|
-
'fuzz'=>{'format'=>
|
240
|
-
'greeble'=>{'format'=>
|
241
|
-
|
250
|
+
expect(fy).to eq(
|
251
|
+
'bob' => { 'format' => 'string', 'unit' => 'c', 'settable' => true },
|
252
|
+
'gruble' => { 'format' => 'string', 'unit' => 'bits', 'settable' => true },
|
253
|
+
'fuzz' => { 'format' => 'string', 'unit' => 'c', 'settable' => true },
|
254
|
+
'greeble' => { 'format' => 'number', 'unit' => 'bibs', 'settable' => false }
|
255
|
+
)
|
242
256
|
end
|
243
257
|
|
244
258
|
@gw.syncdown_before
|
245
|
-
@gw.download(@p,
|
259
|
+
@gw.download(@p, format: 'number', unit: 'bibs', settable: false, alias: 'greeble')
|
246
260
|
@gw.syncdown_after(@p)
|
247
261
|
end
|
248
262
|
|
249
|
-
it
|
263
|
+
it 'replaces keys' do
|
250
264
|
expect(@io).to receive(:write) do |args|
|
251
265
|
fy = YAML.load(args)
|
252
|
-
expect(fy).to eq(
|
253
|
-
'bob'=>{'format'=>
|
254
|
-
'gruble'=>{'format'=>
|
255
|
-
'fuzz'=>{'format'=>
|
256
|
-
|
266
|
+
expect(fy).to eq(
|
267
|
+
'bob' => { 'format' => 'string', 'unit' => 'c', 'settable' => true },
|
268
|
+
'gruble' => { 'format' => 'string', 'unit' => 'bits', 'settable' => true },
|
269
|
+
'fuzz' => { 'format' => 'number', 'unit' => 'bibs', 'settable' => false }
|
270
|
+
)
|
257
271
|
end
|
258
272
|
|
259
273
|
@gw.syncdown_before
|
260
|
-
@gw.download(@p,
|
274
|
+
@gw.download(@p, format: 'number', unit: 'bibs', settable: false, alias: 'fuzz')
|
261
275
|
@gw.syncdown_after(@p)
|
262
276
|
end
|
263
277
|
end
|
264
278
|
end
|
265
279
|
|
266
|
-
# vim: set ai et sw=2 ts=2 :
|
@@ -1,3 +1,10 @@
|
|
1
|
+
# Last Modified: 2017.09.12 /coding: utf-8
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
# Copyright © 2016-2017 Exosite LLC.
|
5
|
+
# License: MIT. See LICENSE.txt.
|
6
|
+
# vim:tw=0:ts=2:sw=2:et:ai
|
7
|
+
|
1
8
|
require 'fileutils'
|
2
9
|
require 'MrMurano/version'
|
3
10
|
require 'MrMurano/Gateway'
|
@@ -5,7 +12,7 @@ require 'MrMurano/SyncRoot'
|
|
5
12
|
require '_workspace'
|
6
13
|
|
7
14
|
RSpec.describe MrMurano::Gateway::Settings do
|
8
|
-
include_context
|
15
|
+
include_context 'WORKSPACE'
|
9
16
|
before(:example) do
|
10
17
|
MrMurano::SyncRoot.instance.reset
|
11
18
|
$cfg = MrMurano::Config.new
|
@@ -14,107 +21,107 @@ RSpec.describe MrMurano::Gateway::Settings do
|
|
14
21
|
$cfg['product.id'] = 'XYZ'
|
15
22
|
|
16
23
|
@gw = MrMurano::Gateway::Settings.new
|
17
|
-
allow(@gw).to receive(:token).and_return(
|
24
|
+
allow(@gw).to receive(:token).and_return('TTTTTTTTTT')
|
18
25
|
|
19
26
|
@infoblob = {
|
20
|
-
:
|
21
|
-
:
|
22
|
-
:
|
23
|
-
:
|
24
|
-
:
|
25
|
-
|
26
|
-
:
|
27
|
-
|
28
|
-
:
|
29
|
-
:
|
30
|
-
:
|
31
|
-
:
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
}
|
27
|
+
name: 'XXXXXXXX',
|
28
|
+
protocol: { name: 'onep', devmode: false },
|
29
|
+
description: 'XXXXXXXX',
|
30
|
+
identity_format: {
|
31
|
+
prefix: '', type: 'opaque', options: { casing: 'mixed', length: 0 },
|
32
|
+
},
|
33
|
+
fqdn: 'XXXXXXXX.m2.exosite-staging.io',
|
34
|
+
provisioning: {
|
35
|
+
auth_type: 'token',
|
36
|
+
enabled: true,
|
37
|
+
generate_identity: true,
|
38
|
+
presenter_identity: true,
|
39
|
+
ip_whitelisting: { enabled: false, allowed: [] },
|
40
|
+
},
|
41
|
+
resources: {
|
42
|
+
bob: { format: 'string', unit: 'c', settable: true },
|
43
|
+
fuzz: { format: 'string', unit: 'c', settable: true },
|
44
|
+
gruble: { format: 'string', unit: 'bits', settable: true },
|
45
|
+
},
|
37
46
|
}
|
38
47
|
end
|
39
48
|
|
40
|
-
it
|
49
|
+
it 'initializes' do
|
41
50
|
uri = @gw.endpoint('/')
|
42
|
-
expect(uri.to_s).to eq(
|
51
|
+
expect(uri.to_s).to eq('https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2/')
|
43
52
|
end
|
44
53
|
|
45
|
-
context
|
46
|
-
context
|
47
|
-
it
|
48
|
-
stub_request(:get,
|
49
|
-
with(:
|
50
|
-
to_return(:
|
54
|
+
context 'protocol' do
|
55
|
+
context 'reads' do
|
56
|
+
it 'data' do
|
57
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
58
|
+
.with(headers: { 'Authorization' => 'token TTTTTTTTTT', 'Content-Type' => 'application/json' })
|
59
|
+
.to_return(status: 200, body: @infoblob.to_json, headers: {})
|
51
60
|
|
52
61
|
ret = @gw.protocol
|
53
62
|
expect(ret).to eq(@infoblob[:protocol])
|
54
63
|
end
|
55
64
|
|
56
|
-
it
|
57
|
-
stub_request(:get,
|
58
|
-
with(:
|
59
|
-
to_return(:
|
65
|
+
it 'returns empty if not Hash' do
|
66
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
67
|
+
.with(headers: { 'Authorization' => 'token TTTTTTTTTT', 'Content-Type' => 'application/json' })
|
68
|
+
.to_return(status: 200, body: ['bob'].to_json, headers: {})
|
60
69
|
|
61
70
|
ret = @gw.protocol
|
62
71
|
expect(ret).to eq({})
|
63
72
|
end
|
64
73
|
|
65
|
-
it
|
74
|
+
it 'returns empty if missing protocol' do
|
66
75
|
foo = @infoblob.dup
|
67
76
|
foo.delete :protocol
|
68
|
-
stub_request(:get,
|
69
|
-
with(:
|
70
|
-
to_return(:
|
77
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
78
|
+
.with(headers: { 'Authorization' => 'token TTTTTTTTTT', 'Content-Type' => 'application/json' })
|
79
|
+
.to_return(status: 200, body: foo.to_json, headers: {})
|
71
80
|
|
72
81
|
ret = @gw.protocol
|
73
82
|
expect(ret).to eq({})
|
74
83
|
end
|
75
84
|
|
76
|
-
it
|
85
|
+
it 'returns empty if protocol not Hash' do
|
77
86
|
foo = @infoblob.dup
|
78
|
-
foo[:protocol] =
|
79
|
-
stub_request(:get,
|
80
|
-
with(:
|
81
|
-
to_return(:
|
87
|
+
foo[:protocol] = 'bob'
|
88
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
89
|
+
.with(headers: { 'Authorization' => 'token TTTTTTTTTT', 'Content-Type' => 'application/json' })
|
90
|
+
.to_return(status: 200, body: foo.to_json, headers: {})
|
82
91
|
|
83
92
|
ret = @gw.protocol
|
84
93
|
expect(ret).to eq({})
|
85
94
|
end
|
86
95
|
end
|
87
|
-
context
|
88
|
-
it
|
89
|
-
newvalues = {:
|
90
|
-
stub_request(:patch,
|
91
|
-
with(:
|
92
|
-
|
93
|
-
|
94
|
-
to_return(:
|
95
|
-
|
96
|
-
ret = @gw.protocol=(newvalues)
|
96
|
+
context 'writes' do
|
97
|
+
it 'data' do
|
98
|
+
newvalues = { name: 'twelve', devmode: true }
|
99
|
+
stub_request(:patch, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
100
|
+
.with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
101
|
+
'Content-Type' => 'application/json', },
|
102
|
+
body: { protocol: newvalues }.to_json)
|
103
|
+
.to_return(status: 200, headers: {})
|
104
|
+
|
105
|
+
ret = @gw.protocol = (newvalues)
|
97
106
|
expect(ret).to eq(newvalues)
|
98
107
|
end
|
99
108
|
|
100
|
-
it
|
101
|
-
expect{ @gw.protocol=('foo') }.to raise_error
|
109
|
+
it 'raises when not Hash' do
|
110
|
+
expect { @gw.protocol = ('foo') }.to raise_error 'Not Hash'
|
102
111
|
end
|
103
112
|
|
104
|
-
it
|
105
|
-
newvalues = {:
|
106
|
-
stub_request(:patch,
|
107
|
-
with(:
|
108
|
-
|
109
|
-
|
110
|
-
to_return(:
|
113
|
+
it 'strips extra keys' do
|
114
|
+
newvalues = { name: 'twelve', devmode: true, auth: 'yes', bob: :built }
|
115
|
+
stub_request(:patch, 'https://bizapi.hosted.exosite.io/api:1/service/XYZ/device2')
|
116
|
+
.with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
117
|
+
'Content-Type' => 'application/json', },
|
118
|
+
body: { protocol: { name: 'twelve', devmode: true } }.to_json)
|
119
|
+
.to_return(status: 200, headers: {})
|
111
120
|
|
112
|
-
ret = @gw.protocol=(newvalues)
|
121
|
+
ret = @gw.protocol = (newvalues)
|
113
122
|
expect(ret).to eq(newvalues)
|
114
123
|
end
|
115
124
|
end
|
116
125
|
end
|
117
|
-
|
118
126
|
end
|
119
127
|
|
120
|
-
# vim: set ai et sw=2 ts=2 :
|