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,4 +1,4 @@
|
|
1
|
-
# Last Modified: 2017.
|
1
|
+
# Last Modified: 2017.09.12 /coding: utf-8
|
2
2
|
# frozen_string_literal: true
|
3
3
|
|
4
4
|
# Copyright © 2016-2017 Exosite LLC.
|
@@ -12,7 +12,7 @@ require 'MrMurano/Solution-Services'
|
|
12
12
|
require '_workspace'
|
13
13
|
|
14
14
|
RSpec.describe MrMurano::EventHandler do
|
15
|
-
include_context
|
15
|
+
include_context 'WORKSPACE'
|
16
16
|
before(:example) do
|
17
17
|
$cfg = MrMurano::Config.new
|
18
18
|
$cfg.load
|
@@ -28,49 +28,49 @@ RSpec.describe MrMurano::EventHandler do
|
|
28
28
|
# the only different is if it uses application.id or product.id.
|
29
29
|
@srv = MrMurano::EventHandlerSolnApp.new
|
30
30
|
#@srv = MrMurano::EventHandlerSolnPrd.new
|
31
|
-
allow(@srv).to receive(:token).and_return(
|
31
|
+
allow(@srv).to receive(:token).and_return('TTTTTTTTTT')
|
32
32
|
end
|
33
33
|
|
34
|
-
it
|
34
|
+
it 'initializes' do
|
35
35
|
uri = @srv.endpoint('/')
|
36
|
-
expect(uri.to_s).to eq(
|
36
|
+
expect(uri.to_s).to eq('https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/')
|
37
37
|
end
|
38
38
|
|
39
|
-
it
|
39
|
+
it 'lists' do
|
40
40
|
body = {
|
41
41
|
items: [
|
42
42
|
{
|
43
|
-
id:
|
44
|
-
name:
|
45
|
-
alias:
|
46
|
-
solution_id:
|
47
|
-
service:
|
48
|
-
event:
|
49
|
-
created_at:
|
50
|
-
updated_at:
|
43
|
+
id: '9K0',
|
44
|
+
name: 'debug',
|
45
|
+
alias: 'XYZ_debug',
|
46
|
+
solution_id: 'XYZ',
|
47
|
+
service: 'device',
|
48
|
+
event: 'datapoint',
|
49
|
+
created_at: '2016-07-07T19:16:19.479Z',
|
50
|
+
updated_at: '2016-09-12T13:26:55.868Z',
|
51
51
|
},
|
52
52
|
],
|
53
53
|
total: 1,
|
54
54
|
}
|
55
|
-
stub_request(:get,
|
56
|
-
with(headers: {
|
57
|
-
|
58
|
-
|
59
|
-
|
55
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler')
|
56
|
+
.with(headers: {
|
57
|
+
'Authorization' => 'token TTTTTTTTTT',
|
58
|
+
'Content-Type' => 'application/json',
|
59
|
+
}).to_return(body: body.to_json)
|
60
60
|
ret = @srv.list
|
61
61
|
expect(ret).to eq(body[:items])
|
62
62
|
end
|
63
63
|
|
64
|
-
it
|
64
|
+
it 'fetches, with header' do
|
65
65
|
body = {
|
66
|
-
id:
|
67
|
-
name:
|
68
|
-
alias:
|
69
|
-
solution_id:
|
70
|
-
service:
|
71
|
-
event:
|
72
|
-
created_at:
|
73
|
-
updated_at:
|
66
|
+
id: '9K0',
|
67
|
+
name: 'debug',
|
68
|
+
alias: 'XYZ_debug',
|
69
|
+
solution_id: 'XYZ',
|
70
|
+
service: 'device',
|
71
|
+
event: 'datapoint',
|
72
|
+
created_at: '2016-07-07T19:16:19.479Z',
|
73
|
+
updated_at: '2016-09-12T13:26:55.868Z',
|
74
74
|
script: %{--#EVENT device datapoint
|
75
75
|
-- lua code is here
|
76
76
|
function foo(bar)
|
@@ -78,25 +78,25 @@ function foo(bar)
|
|
78
78
|
end
|
79
79
|
},
|
80
80
|
}
|
81
|
-
stub_request(:get,
|
82
|
-
with(headers: {
|
83
|
-
|
84
|
-
|
85
|
-
|
81
|
+
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0')
|
82
|
+
.with(headers: {
|
83
|
+
'Authorization' => 'token TTTTTTTTTT',
|
84
|
+
'Content-Type' => 'application/json',
|
85
|
+
}).to_return(body: body.to_json)
|
86
86
|
ret = @srv.fetch('9K0')
|
87
87
|
expect(ret).to eq(body[:script])
|
88
88
|
end
|
89
89
|
|
90
|
-
it
|
90
|
+
it 'fetches, with header into block' do
|
91
91
|
body = {
|
92
|
-
id:
|
93
|
-
name:
|
94
|
-
alias:
|
95
|
-
solution_id:
|
96
|
-
service:
|
97
|
-
event:
|
98
|
-
created_at:
|
99
|
-
updated_at:
|
92
|
+
id: '9K0',
|
93
|
+
name: 'debug',
|
94
|
+
alias: 'XYZ_debug',
|
95
|
+
solution_id: 'XYZ',
|
96
|
+
service: 'device',
|
97
|
+
event: 'datapoint',
|
98
|
+
created_at: '2016-07-07T19:16:19.479Z',
|
99
|
+
updated_at: '2016-09-12T13:26:55.868Z',
|
100
100
|
script: %{
|
101
101
|
--#EVENT device datapoint
|
102
102
|
-- lua code is here
|
@@ -105,37 +105,39 @@ end
|
|
105
105
|
end
|
106
106
|
},
|
107
107
|
}
|
108
|
-
stub_request(
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
108
|
+
stub_request(
|
109
|
+
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0'
|
110
|
+
).with(headers: {
|
111
|
+
'Authorization' => 'token TTTTTTTTTT',
|
112
|
+
'Content-Type' => 'application/json',
|
113
|
+
}).to_return(body: body.to_json)
|
113
114
|
ret = nil
|
114
115
|
@srv.fetch('9K0') { |sc| ret = sc }
|
115
116
|
expect(ret).to eq(body[:script])
|
116
117
|
end
|
117
118
|
|
118
|
-
it
|
119
|
+
it 'fetches, without header' do
|
119
120
|
body = {
|
120
|
-
id:
|
121
|
-
name:
|
122
|
-
alias:
|
123
|
-
solution_id:
|
124
|
-
service:
|
125
|
-
event:
|
126
|
-
created_at:
|
127
|
-
updated_at:
|
121
|
+
id: '9K0',
|
122
|
+
name: 'debug',
|
123
|
+
alias: 'XYZ_debug',
|
124
|
+
solution_id: 'XYZ',
|
125
|
+
service: 'device',
|
126
|
+
event: 'datapoint',
|
127
|
+
created_at: '2016-07-07T19:16:19.479Z',
|
128
|
+
updated_at: '2016-09-12T13:26:55.868Z',
|
128
129
|
script: %{-- lua code is here
|
129
130
|
function foo(bar)
|
130
131
|
return bar + 1
|
131
132
|
end
|
132
133
|
},
|
133
134
|
}
|
134
|
-
stub_request(
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
135
|
+
stub_request(
|
136
|
+
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0'
|
137
|
+
).with(headers: {
|
138
|
+
'Authorization' => 'token TTTTTTTTTT',
|
139
|
+
'Content-Type' => 'application/json',
|
140
|
+
}).to_return(body: body.to_json)
|
139
141
|
|
140
142
|
ret = @srv.fetch('9K0')
|
141
143
|
expect(ret).to eq(%{--#EVENT device datapoint
|
@@ -146,23 +148,25 @@ end
|
|
146
148
|
})
|
147
149
|
end
|
148
150
|
|
149
|
-
it
|
150
|
-
stub_request(
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
151
|
+
it 'removes' do
|
152
|
+
stub_request(
|
153
|
+
:delete, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0'
|
154
|
+
).with(headers: {
|
155
|
+
'Authorization' => 'token TTTTTTTTTT',
|
156
|
+
'Content-Type' => 'application/json',
|
157
|
+
}).to_return(body: '')
|
155
158
|
|
156
159
|
ret = @srv.remove('9K0')
|
157
160
|
expect(ret).to eq({})
|
158
161
|
end
|
159
162
|
|
160
|
-
it
|
161
|
-
stub_request(
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
163
|
+
it 'uploads over old version' do
|
164
|
+
stub_request(
|
165
|
+
:put, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_data_datapoint'
|
166
|
+
).with(headers: {
|
167
|
+
'Authorization' => 'token TTTTTTTTTT',
|
168
|
+
'Content-Type' => 'application/json',
|
169
|
+
}).to_return(body: '')
|
166
170
|
|
167
171
|
Tempfile.open('foo') do |tio|
|
168
172
|
tio << %{
|
@@ -174,27 +178,28 @@ end
|
|
174
178
|
tio.close
|
175
179
|
|
176
180
|
ret = @srv.upload(tio.path,
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
182
|
-
|
181
|
+
MrMurano::EventHandler::EventHandlerItem.new(
|
182
|
+
id: '9K0',
|
183
|
+
service: 'data',
|
184
|
+
event: 'datapoint',
|
185
|
+
solution_id: 'XYZ',
|
186
|
+
))
|
183
187
|
expect(ret)
|
184
188
|
end
|
185
189
|
end
|
186
190
|
|
187
|
-
it
|
188
|
-
stub_request(:put,
|
189
|
-
with(headers: {
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
191
|
+
it 'uploads when nothing is there' do
|
192
|
+
stub_request(:put, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_device_datapoint')
|
193
|
+
.with(headers: {
|
194
|
+
'Authorization' => 'token TTTTTTTTTT',
|
195
|
+
'Content-Type' => 'application/json',
|
196
|
+
}).to_return(status: 404)
|
197
|
+
|
198
|
+
stub_request(:post, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/')
|
199
|
+
.with(headers: {
|
200
|
+
'Authorization' => 'token TTTTTTTTTT',
|
201
|
+
'Content-Type' => 'application/json',
|
202
|
+
}).to_return(body: '')
|
198
203
|
|
199
204
|
Tempfile.open('foo') do |tio|
|
200
205
|
tio << %{
|
@@ -206,161 +211,154 @@ end
|
|
206
211
|
tio.close
|
207
212
|
|
208
213
|
ret = @srv.upload(tio.path,
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
214
|
+
MrMurano::EventHandler::EventHandlerItem.new(
|
215
|
+
id: '9K0',
|
216
|
+
service: 'device',
|
217
|
+
event: 'datapoint',
|
218
|
+
solution_id: 'XYZ',
|
219
|
+
))
|
215
220
|
expect(ret)
|
216
221
|
end
|
217
|
-
|
218
222
|
end
|
219
223
|
|
220
|
-
context
|
224
|
+
context 'compares' do
|
221
225
|
before(:example) do
|
222
|
-
@
|
223
|
-
id:
|
224
|
-
name:
|
225
|
-
alias:
|
226
|
-
solution_id:
|
227
|
-
service:
|
228
|
-
event:
|
229
|
-
created_at:
|
230
|
-
updated_at:
|
226
|
+
@i_a = {
|
227
|
+
id: '9K0',
|
228
|
+
name: 'debug',
|
229
|
+
alias: 'XYZ_debug',
|
230
|
+
solution_id: 'XYZ',
|
231
|
+
service: 'device',
|
232
|
+
event: 'datapoint',
|
233
|
+
created_at: '2016-07-07T19:16:19.479Z',
|
234
|
+
updated_at: '2016-09-12T13:26:55.868Z',
|
231
235
|
}
|
232
|
-
@
|
233
|
-
id:
|
234
|
-
name:
|
235
|
-
alias:
|
236
|
-
solution_id:
|
237
|
-
service:
|
238
|
-
event:
|
239
|
-
created_at:
|
240
|
-
updated_at:
|
236
|
+
@i_b = {
|
237
|
+
id: '9K0',
|
238
|
+
name: 'debug',
|
239
|
+
alias: 'XYZ_debug',
|
240
|
+
solution_id: 'XYZ',
|
241
|
+
service: 'device',
|
242
|
+
event: 'datapoint',
|
243
|
+
created_at: '2016-07-07T19:16:19.479Z',
|
244
|
+
updated_at: '2016-09-12T13:26:55.868Z',
|
241
245
|
}
|
242
246
|
end
|
243
|
-
it
|
244
|
-
ret = @srv.docmp(@
|
247
|
+
it 'both have updated_at' do
|
248
|
+
ret = @srv.docmp(@i_a, @i_b)
|
245
249
|
expect(ret).to eq(false)
|
246
250
|
end
|
247
251
|
|
248
|
-
it
|
252
|
+
it 'i_a is a local file' do
|
249
253
|
Tempfile.open('foo') do |tio|
|
250
|
-
tio <<
|
254
|
+
tio << 'something'
|
251
255
|
tio.close
|
252
|
-
|
253
|
-
|
254
|
-
})
|
255
|
-
ret = @srv.docmp(iA, @iB)
|
256
|
+
i_a = @i_a.reject { |k, _v| k == :updated_at }.merge(local_path: Pathname.new(tio.path))
|
257
|
+
ret = @srv.docmp(i_a, @i_b)
|
256
258
|
expect(ret).to eq(true)
|
257
259
|
|
258
|
-
|
259
|
-
ret = @srv.docmp(
|
260
|
+
i_b = @i_b.merge(updated_at: Pathname.new(tio.path).mtime.getutc)
|
261
|
+
ret = @srv.docmp(i_a, i_b)
|
260
262
|
expect(ret).to eq(false)
|
261
263
|
end
|
262
264
|
end
|
263
265
|
|
264
|
-
it
|
266
|
+
it 'i_b is a local file' do
|
265
267
|
Tempfile.open('foo') do |tio|
|
266
|
-
tio <<
|
268
|
+
tio << 'something'
|
267
269
|
tio.close
|
268
|
-
|
269
|
-
|
270
|
-
})
|
271
|
-
ret = @srv.docmp(@iA, iB)
|
270
|
+
i_b = @i_b.reject { |k, _v| k == :updated_at }.merge(local_path: Pathname.new(tio.path))
|
271
|
+
ret = @srv.docmp(@i_a, i_b)
|
272
272
|
expect(ret).to eq(true)
|
273
273
|
|
274
|
-
|
275
|
-
ret = @srv.docmp(
|
274
|
+
i_a = @i_a.merge(updated_at: Pathname.new(tio.path).mtime.getutc)
|
275
|
+
ret = @srv.docmp(i_a, i_b)
|
276
276
|
expect(ret).to eq(false)
|
277
277
|
end
|
278
278
|
end
|
279
279
|
end
|
280
280
|
|
281
|
-
context
|
282
|
-
it
|
283
|
-
ret = @srv.tolocalname({ name:
|
281
|
+
context 'Lookup functions' do
|
282
|
+
it 'gets local name' do
|
283
|
+
ret = @srv.tolocalname({ name: 'bob' }, nil)
|
284
284
|
expect(ret).to eq('bob.lua')
|
285
285
|
end
|
286
286
|
|
287
|
-
it
|
288
|
-
ret = @srv.synckey(
|
289
|
-
expect(ret).to eq(
|
287
|
+
it 'gets synckey' do
|
288
|
+
ret = @srv.synckey(service: 'device', event: 'datapoint')
|
289
|
+
expect(ret).to eq('device_datapoint')
|
290
290
|
end
|
291
291
|
|
292
|
-
it
|
293
|
-
$cfg['eventhandler.searchFor'] = %
|
292
|
+
it 'gets searchfor' do
|
293
|
+
$cfg['eventhandler.searchFor'] = %(a b c/**/d/*.bob)
|
294
294
|
ret = @srv.searchFor
|
295
|
-
expect(ret).to eq([
|
295
|
+
expect(ret).to eq(['a', 'b', 'c/**/d/*.bob'])
|
296
296
|
end
|
297
297
|
|
298
|
-
it
|
299
|
-
$cfg['eventhandler.ignoring'] = %
|
298
|
+
it 'gets ignoring' do
|
299
|
+
$cfg['eventhandler.ignoring'] = %(a b c/**/d/*.bob)
|
300
300
|
ret = @srv.ignoring
|
301
|
-
expect(ret).to eq([
|
301
|
+
expect(ret).to eq(['a', 'b', 'c/**/d/*.bob'])
|
302
302
|
end
|
303
303
|
|
304
|
-
it
|
305
|
-
expect
|
304
|
+
it 'raises on alias without service' do
|
305
|
+
expect do
|
306
306
|
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(event: 'bob'))
|
307
|
-
|
307
|
+
end.to raise_error %(Missing parts! {"event":"bob"})
|
308
308
|
end
|
309
309
|
|
310
|
-
it
|
311
|
-
expect
|
310
|
+
it 'raises on alias without event' do
|
311
|
+
expect do
|
312
312
|
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(service: 'bob'))
|
313
|
-
|
313
|
+
end.to raise_error %(Missing parts! {"service":"bob"})
|
314
314
|
end
|
315
315
|
|
316
|
-
it
|
317
|
-
expect
|
316
|
+
it 'raises on name without service' do
|
317
|
+
expect do
|
318
318
|
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(event: 'bob'))
|
319
|
-
|
319
|
+
end.to raise_error %(Missing parts! {"event":"bob"})
|
320
320
|
end
|
321
321
|
|
322
|
-
it
|
323
|
-
expect
|
322
|
+
it 'raises on name without event' do
|
323
|
+
expect do
|
324
324
|
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(service: 'bob'))
|
325
|
-
|
325
|
+
end.to raise_error %(Missing parts! {"service":"bob"})
|
326
326
|
end
|
327
327
|
end
|
328
328
|
|
329
|
-
context
|
329
|
+
context 'to_remote_item' do
|
330
330
|
before(:example) do
|
331
331
|
allow(@srv).to receive(:warning)
|
332
332
|
end
|
333
333
|
|
334
|
-
it
|
334
|
+
it 'reads one' do
|
335
335
|
Tempfile.open('foo') do |tio|
|
336
|
-
tio << %
|
336
|
+
tio << %(--#EVENT device datapoint
|
337
337
|
-- do something.
|
338
338
|
Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
|
339
|
-
|
339
|
+
).gsub(/^\s+/, '')
|
340
340
|
tio.close
|
341
341
|
|
342
342
|
ret = @srv.to_remote_item(nil, tio.path)
|
343
343
|
expect(ret).to eq(
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
script: %{--#EVENT device datapoint\n-- do something.\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n},
|
353
|
-
}
|
344
|
+
service: 'device',
|
345
|
+
event: 'datapoint',
|
346
|
+
svc_alias: nil,
|
347
|
+
type: nil,
|
348
|
+
line: 0,
|
349
|
+
line_end: 3,
|
350
|
+
local_path: Pathname.new(tio.path),
|
351
|
+
script: %(--#EVENT device datapoint\n-- do something.\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n)
|
354
352
|
)
|
355
353
|
end
|
356
354
|
end
|
357
355
|
|
358
|
-
it
|
356
|
+
it 'skips all when no header found' do
|
359
357
|
Tempfile.open('foo') do |tio|
|
360
|
-
tio << %
|
358
|
+
tio << %(
|
361
359
|
-- do something.
|
362
360
|
Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
|
363
|
-
|
361
|
+
).gsub(/^\s+/, '')
|
364
362
|
tio.close
|
365
363
|
|
366
364
|
ret = @srv.to_remote_item(nil, tio.path)
|
@@ -368,13 +366,13 @@ end
|
|
368
366
|
end
|
369
367
|
end
|
370
368
|
|
371
|
-
it
|
369
|
+
it 'skips junk at begining' do
|
372
370
|
Tempfile.open('foo') do |tio|
|
373
|
-
tio << %
|
371
|
+
tio << %(
|
374
372
|
-- do something.
|
375
373
|
--#EVENT device datapoint
|
376
374
|
Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
|
377
|
-
|
375
|
+
).gsub(/^\s+/, '')
|
378
376
|
tio.close
|
379
377
|
|
380
378
|
ret = @srv.to_remote_item(nil, tio.path)
|
@@ -387,14 +385,14 @@ end
|
|
387
385
|
line: 1,
|
388
386
|
line_end: 3,
|
389
387
|
local_path: Pathname.new(tio.path),
|
390
|
-
script: %
|
391
|
-
)
|
388
|
+
script: %(--#EVENT device datapoint\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n),
|
389
|
+
)
|
390
|
+
)
|
392
391
|
end
|
393
392
|
end
|
394
|
-
|
395
393
|
end
|
396
394
|
|
397
|
-
context
|
395
|
+
context 'Matching' do
|
398
396
|
before(:example) do
|
399
397
|
@an_item = {
|
400
398
|
service: 'bob',
|
@@ -402,26 +400,26 @@ end
|
|
402
400
|
local_path: Pathname.new('a/relative/path.lua'),
|
403
401
|
}
|
404
402
|
end
|
405
|
-
context
|
406
|
-
it
|
403
|
+
context 'service' do
|
404
|
+
it 'any event' do
|
407
405
|
ret = @srv.match(@an_item, '#bob#')
|
408
406
|
expect(ret).to be true
|
409
407
|
ret = @srv.match(@an_item, '#email#')
|
410
408
|
expect(ret).to be false
|
411
409
|
end
|
412
|
-
it
|
410
|
+
it 'exact event' do
|
413
411
|
ret = @srv.match(@an_item, '#bob#built')
|
414
412
|
expect(ret).to be true
|
415
413
|
ret = @srv.match(@an_item, '#email#built')
|
416
414
|
expect(ret).to be false
|
417
415
|
end
|
418
416
|
end
|
419
|
-
context
|
420
|
-
it
|
417
|
+
context 'any service' do
|
418
|
+
it 'any event' do
|
421
419
|
ret = @srv.match(@an_item, '##')
|
422
420
|
expect(ret).to be true
|
423
421
|
end
|
424
|
-
it
|
422
|
+
it 'exact event' do
|
425
423
|
ret = @srv.match(@an_item, '##built')
|
426
424
|
expect(ret).to be true
|
427
425
|
ret = @srv.match(@an_item, '##sent')
|