MuranoCLI 3.2.1.pre.beta.6 → 3.2.1.pre.beta.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/HISTORY.md +10 -0
- data/MuranoCLI.gemspec +37 -6
- data/Rakefile +38 -11
- data/lib/MrMurano/commands/business.rb +0 -4
- data/lib/MrMurano/version.rb +1 -1
- metadata +2 -251
- data/dockers/Dockerfile.2.2.9 +0 -40
- data/dockers/Dockerfile.2.3.6 +0 -40
- data/dockers/Dockerfile.2.4.3 +0 -40
- data/dockers/Dockerfile.2.5.0 +0 -40
- data/dockers/Dockerfile.GemRelease +0 -49
- data/dockers/Dockerfile.m4 +0 -122
- data/dockers/README.rst +0 -362
- data/dockers/RELEASE.rst +0 -135
- data/dockers/docker-test.sh +0 -163
- data/dockers/gem-release.sh +0 -4
- data/docs/basic_example.rst +0 -436
- data/docs/ci/.trustme.plugin +0 -140
- data/docs/ci/.trustme.sh +0 -516
- data/docs/ci/.trustme.vim +0 -55
- data/docs/completions/murano_completion-bash +0 -4484
- data/docs/demo.md +0 -109
- data/docs/develop.rst +0 -392
- data/docs/release.rst +0 -295
- data/spec/Account-Passwords_spec.rb +0 -245
- data/spec/Account_spec.rb +0 -256
- data/spec/Business_spec.rb +0 -307
- data/spec/ConfigFile_spec.rb +0 -55
- data/spec/ConfigMigrate_spec.rb +0 -108
- data/spec/Config_spec.rb +0 -440
- data/spec/Content_spec.rb +0 -422
- data/spec/GatewayBase_spec.rb +0 -65
- data/spec/GatewayDevice_spec.rb +0 -403
- data/spec/GatewayResource_spec.rb +0 -283
- data/spec/GatewaySettings_spec.rb +0 -130
- data/spec/HttpAuthed_spec.rb +0 -87
- data/spec/Http_spec.rb +0 -220
- data/spec/MakePretties_spec.rb +0 -127
- data/spec/Mock_spec.rb +0 -62
- data/spec/ProjectFile_spec.rb +0 -381
- data/spec/Setting_spec.rb +0 -120
- data/spec/Solution-ServiceConfig_spec.rb +0 -272
- data/spec/Solution-ServiceEventHandler_spec.rb +0 -442
- data/spec/Solution-ServiceModules_spec.rb +0 -562
- data/spec/Solution-UsersRoles_spec.rb +0 -269
- data/spec/Solution_spec.rb +0 -140
- data/spec/SyncRoot_spec.rb +0 -111
- data/spec/SyncUpDown_spec.rb +0 -868
- data/spec/Verbosing_spec.rb +0 -332
- data/spec/Webservice-Cors_spec.rb +0 -225
- data/spec/Webservice-Endpoint_spec.rb +0 -650
- data/spec/Webservice-File_spec.rb +0 -282
- data/spec/Webservice-Setting_spec.rb +0 -105
- data/spec/_workspace.rb +0 -43
- data/spec/cmd_business_spec.rb +0 -64
- data/spec/cmd_common.rb +0 -507
- data/spec/cmd_config_spec.rb +0 -73
- data/spec/cmd_content_spec.rb +0 -109
- data/spec/cmd_cors_spec.rb +0 -54
- data/spec/cmd_device_spec.rb +0 -130
- data/spec/cmd_domain_spec.rb +0 -62
- data/spec/cmd_element_spec.rb +0 -401
- data/spec/cmd_exchange_spec.rb +0 -114
- data/spec/cmd_help_spec.rb +0 -72
- data/spec/cmd_init_spec.rb +0 -475
- data/spec/cmd_keystore_spec.rb +0 -97
- data/spec/cmd_link_spec.rb +0 -105
- data/spec/cmd_logs_spec.rb +0 -162
- data/spec/cmd_password_spec.rb +0 -64
- data/spec/cmd_setting_application_spec.rb +0 -300
- data/spec/cmd_setting_product_spec.rb +0 -246
- data/spec/cmd_status_spec.rb +0 -300
- data/spec/cmd_syncdown_application_spec.rb +0 -128
- data/spec/cmd_syncdown_both_spec.rb +0 -178
- data/spec/cmd_syncdown_unit_spec.rb +0 -861
- data/spec/cmd_syncup_spec.rb +0 -148
- data/spec/cmd_token_spec.rb +0 -53
- data/spec/cmd_usage_spec.rb +0 -79
- data/spec/dry_run_formatter.rb +0 -28
- data/spec/fixtures/.mrmuranorc +0 -9
- data/spec/fixtures/ProjectFiles/invalid.yaml +0 -9
- data/spec/fixtures/ProjectFiles/only_meta.yaml +0 -24
- data/spec/fixtures/ProjectFiles/with_routes.yaml +0 -27
- data/spec/fixtures/SolutionFiles/0.2.0.json +0 -20
- data/spec/fixtures/SolutionFiles/0.2.0_invalid.json +0 -18
- data/spec/fixtures/SolutionFiles/0.2.json +0 -21
- data/spec/fixtures/SolutionFiles/0.3.0.json +0 -20
- data/spec/fixtures/SolutionFiles/0.3.0_invalid.json +0 -19
- data/spec/fixtures/SolutionFiles/0.3.json +0 -20
- data/spec/fixtures/SolutionFiles/basic.json +0 -20
- data/spec/fixtures/SolutionFiles/secret.json +0 -6
- data/spec/fixtures/configfile +0 -9
- data/spec/fixtures/dumped_config +0 -57
- data/spec/fixtures/exchange_element/element-show.json +0 -1
- data/spec/fixtures/exchange_element/swagger-mur-6407__10k.yaml +0 -282
- data/spec/fixtures/exchange_element/swagger-mur-6407__20k.yaml +0 -588
- data/spec/fixtures/gateway_resource_files/resources.notyaml +0 -12
- data/spec/fixtures/gateway_resource_files/resources.yaml +0 -13
- data/spec/fixtures/gateway_resource_files/resources_invalid.yaml +0 -13
- data/spec/fixtures/mrmuranorc_deleted_bob +0 -6
- data/spec/fixtures/mrmuranorc_tool_bob +0 -3
- data/spec/fixtures/product_spec_files/example.exoline.spec.yaml +0 -116
- data/spec/fixtures/product_spec_files/example.murano.spec.yaml +0 -14
- data/spec/fixtures/product_spec_files/gwe.exoline.spec.yaml +0 -21
- data/spec/fixtures/product_spec_files/gwe.murano.spec.yaml +0 -16
- data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +0 -11
- data/spec/fixtures/product_spec_files/lightbulb.yaml +0 -21
- data/spec/fixtures/roles-three.yaml +0 -11
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value 0.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value 1.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value No.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value Yes.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value bob.webmock +0 -72
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value false.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value off.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value on STDIN.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value on.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a bool value true.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a json array blob with STDIN.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) a json array blob.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) an array.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting Writes (using Webservice.cors) appends an array.webmock +0 -98
- data/spec/fixtures/snapshots/murano application setting reads Webservice.cors to a file.webmock +0 -72
- data/spec/fixtures/snapshots/murano application setting reads Webservice.cors.webmock +0 -72
- data/spec/fixtures/snapshots/murano business list as json.webmock +0 -27
- data/spec/fixtures/snapshots/murano business list as table.webmock +0 -27
- data/spec/fixtures/snapshots/murano business list fewer fields.webmock +0 -27
- data/spec/fixtures/snapshots/murano business list only ids.webmock +0 -27
- data/spec/fixtures/snapshots/murano business list output to file.webmock +0 -27
- data/spec/fixtures/snapshots/murano business without project help.webmock +0 -9
- data/spec/fixtures/snapshots/murano config Needs a key.webmock +0 -9
- data/spec/fixtures/snapshots/murano config Reads a key.webmock +0 -9
- data/spec/fixtures/snapshots/murano config Removes a key.webmock +0 -9
- data/spec/fixtures/snapshots/murano config Sets a key.webmock +0 -9
- data/spec/fixtures/snapshots/murano config Sets a user key.webmock +0 -9
- data/spec/fixtures/snapshots/murano content life cycle.webmock +0 -144
- data/spec/fixtures/snapshots/murano cors sets CORS.webmock +0 -78
- data/spec/fixtures/snapshots/murano cors show CORS.webmock +0 -64
- data/spec/fixtures/snapshots/murano device activates.webmock +0 -86
- data/spec/fixtures/snapshots/murano device enables a batch.webmock +0 -76
- data/spec/fixtures/snapshots/murano device enables and lists.webmock +0 -78
- data/spec/fixtures/snapshots/murano device writes and reads.webmock +0 -136
- data/spec/fixtures/snapshots/murano domain show domain.webmock +0 -101
- data/spec/fixtures/snapshots/murano element edit unknown as unknown element.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show --help.webmock +0 -9
- data/spec/fixtures/snapshots/murano element show as csv.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show as default-table.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show as json.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show as table truncate.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show as table wrap.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show as yaml.webmock +0 -43
- data/spec/fixtures/snapshots/murano element show using ambiguous name.webmock +0 -43
- data/spec/fixtures/snapshots/murano element without project usage.webmock +0 -9
- data/spec/fixtures/snapshots/murano exchange with project list as json.webmock +0 -59
- data/spec/fixtures/snapshots/murano exchange with project list as table.webmock +0 -59
- data/spec/fixtures/snapshots/murano exchange with project list fewer fields.webmock +0 -59
- data/spec/fixtures/snapshots/murano exchange with project list only ids.webmock +0 -59
- data/spec/fixtures/snapshots/murano exchange with project list output to file.webmock +0 -59
- data/spec/fixtures/snapshots/murano exchange with project list purchase is already added ID.webmock +0 -83
- data/spec/fixtures/snapshots/murano exchange with project list purchase is ambiguous name.webmock +0 -59
- data/spec/fixtures/snapshots/murano exchange without project help.webmock +0 -9
- data/spec/fixtures/snapshots/murano help using commander as --help.webmock +0 -9
- data/spec/fixtures/snapshots/murano help using commander no args.webmock +0 -9
- data/spec/fixtures/snapshots/murano help using subshell no args.webmock +0 -9
- data/spec/fixtures/snapshots/murano help using subshell with --help.webmock +0 -9
- data/spec/fixtures/snapshots/murano init Won't init in HOME (gracefully).webmock +0 -9
- data/spec/fixtures/snapshots/murano init in empty directory with existing project.webmock +0 -201
- data/spec/fixtures/snapshots/murano init in empty directory without existing project.webmock +0 -193
- data/spec/fixtures/snapshots/murano init in existing project directory with ProjectFile.webmock +0 -213
- data/spec/fixtures/snapshots/murano init in existing project directory with SolutionFile 0.2.0.webmock +0 -213
- data/spec/fixtures/snapshots/murano init in existing project directory with SolutionFile 0.3.0.webmock +0 -213
- data/spec/fixtures/snapshots/murano init in existing project directory without ProjectFile.webmock +0 -213
- data/spec/fixtures/snapshots/murano keystore can call other commands.webmock +0 -108
- data/spec/fixtures/snapshots/murano keystore clearAll.webmock +0 -124
- data/spec/fixtures/snapshots/murano keystore deletes.webmock +0 -112
- data/spec/fixtures/snapshots/murano keystore gets.webmock +0 -96
- data/spec/fixtures/snapshots/murano keystore infos.webmock +0 -96
- data/spec/fixtures/snapshots/murano keystore lists.webmock +0 -96
- data/spec/fixtures/snapshots/murano link with project links and lists.webmock +0 -149
- data/spec/fixtures/snapshots/murano link with project unlinks.webmock +0 -165
- data/spec/fixtures/snapshots/murano link without project help.webmock +0 -9
- data/spec/fixtures/snapshots/murano link without project subshell vs inline using commander will not list.webmock +0 -27
- data/spec/fixtures/snapshots/murano link without project subshell vs inline using subshell will not list.webmock +0 -27
- data/spec/fixtures/snapshots/murano logs when project is setup tail log.webmock +0 -9
- data/spec/fixtures/snapshots/murano password Lists when no file.webmock +0 -9
- data/spec/fixtures/snapshots/murano password deletes a password.webmock +0 -9
- data/spec/fixtures/snapshots/murano password sets a password.webmock +0 -9
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a forced string value on STDIN.webmock +0 -90
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a forced string value.webmock +0 -90
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value fiftyHalf.webmock +0 -64
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value float 12.67.webmock +0 -90
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value integer 12.webmock +0 -90
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a number value on STDIN.webmock +0 -90
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) a string value.webmock +0 -90
- data/spec/fixtures/snapshots/murano product setting Writes (using Device2.identity_format) merges into a dictionary.webmock +0 -90
- data/spec/fixtures/snapshots/murano single sync without ProjectFile syncdown.webmock +0 -322
- data/spec/fixtures/snapshots/murano status with ProjectFile status.webmock +0 -153
- data/spec/fixtures/snapshots/murano status with Solutionfile 0.2.0 status.webmock +0 -153
- data/spec/fixtures/snapshots/murano status with Solutionfile 0.3.0 status.webmock +0 -153
- data/spec/fixtures/snapshots/murano status without ProjectFile matches file path.webmock +0 -153
- data/spec/fixtures/snapshots/murano status without ProjectFile matches route.webmock +0 -153
- data/spec/fixtures/snapshots/murano status without ProjectFile status.webmock +0 -153
- data/spec/fixtures/snapshots/murano syncdown stubbed without ProjectFile syncdown.webmock +0 -151
- data/spec/fixtures/snapshots/murano syncdown without ProjectFile syncdown.webmock +0 -479
- data/spec/fixtures/snapshots/murano syncup without ProjectFile syncup.webmock +0 -357
- data/spec/fixtures/snapshots/murano token with project list as table.webmock +0 -9
- data/spec/fixtures/snapshots/murano token without project help.webmock +0 -9
- data/spec/fixtures/snapshots/murano usage show usage.webmock +0 -93
- data/spec/fixtures/syncable_conflict/services/devdata.lua +0 -18
- data/spec/fixtures/syncable_conflict/services/timers.lua +0 -4
- data/spec/fixtures/syncable_content/assets/icon.png +0 -0
- data/spec/fixtures/syncable_content/assets/index.html +0 -0
- data/spec/fixtures/syncable_content/assets/js/script.js +0 -0
- data/spec/fixtures/syncable_content/modules/table_util.lua +0 -58
- data/spec/fixtures/syncable_content/routes/manyRoutes.lua +0 -11
- data/spec/fixtures/syncable_content/routes/singleRoute.lua +0 -5
- data/spec/fixtures/websocket/README.rst +0 -110
- data/spec/fixtures/websocket/logs_blather.rb +0 -27
- data/spec/fixtures/websocket/logs_faker.rb +0 -153
- data/spec/fixtures/websocket/simple_connection.rb +0 -45
- data/spec/fixtures/websocket/simple_options.rb +0 -77
- data/spec/fixtures/websocket/simple_server.rb +0 -69
- data/spec/fixtures/websocket/wss-echo.rb +0 -48
- data/spec/fixtures/websocket/wss-fake-logs.rb +0 -20
- data/spec/spec_helper.rb +0 -131
- data/spec/variegated_TruthyFalsey_spec.rb +0 -29
- data/spec/webmock_snapshot.rb +0 -296
@@ -1,272 +0,0 @@
|
|
1
|
-
# Copyright © 2016-2017 Exosite LLC. All Rights Reserved
|
2
|
-
# License: PROPRIETARY. See LICENSE.txt.
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
|
-
# vim:tw=0:ts=2:sw=2:et:ai
|
6
|
-
# Unauthorized copying of this file is strictly prohibited.
|
7
|
-
|
8
|
-
require 'tempfile'
|
9
|
-
require 'MrMurano/version'
|
10
|
-
require 'MrMurano/HttpAuthed'
|
11
|
-
require 'MrMurano/ProjectFile'
|
12
|
-
require 'MrMurano/Solution-ServiceConfig'
|
13
|
-
require 'MrMurano/SyncRoot'
|
14
|
-
require '_workspace'
|
15
|
-
require 'HttpAuthed_spec'
|
16
|
-
|
17
|
-
RSpec.describe MrMurano::ServiceConfig do
|
18
|
-
include_context 'WORKSPACE'
|
19
|
-
|
20
|
-
before(:example) do
|
21
|
-
$cfg = MrMurano::Config.new
|
22
|
-
$cfg.load
|
23
|
-
$project = MrMurano::ProjectFile.new
|
24
|
-
$project.load
|
25
|
-
$cfg['net.host'] = 'bizapi.hosted.exosite.io'
|
26
|
-
# serviceconfig works on all solution types.
|
27
|
-
$cfg['product.id'] = 'XYZ'
|
28
|
-
$cfg['application.id'] = 'XYZ'
|
29
|
-
stub_request_email_password
|
30
|
-
|
31
|
-
# ServiceConfig needs an api_id, else one could instantiate
|
32
|
-
# ServiceConfigApplication or ServiceConfigProduct.
|
33
|
-
@srv = MrMurano::ServiceConfig.new('XYZ')
|
34
|
-
MrMurano::HttpAuthed.instance.instance_variable_set(:@token_biz, 'TTTTTTTTTT')
|
35
|
-
end
|
36
|
-
|
37
|
-
it 'initializes' do
|
38
|
-
uri = @srv.endpoint('/')
|
39
|
-
expect(uri.to_s).to eq('https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/')
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'lists' do
|
43
|
-
body = {
|
44
|
-
items: [
|
45
|
-
{
|
46
|
-
id: '9K0',
|
47
|
-
name: 'debug',
|
48
|
-
alias: 'XYZ_debug',
|
49
|
-
solution_id: 'XYZ',
|
50
|
-
service: 'device',
|
51
|
-
status: 'ready',
|
52
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
53
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
54
|
-
deleted_at: nil,
|
55
|
-
},
|
56
|
-
],
|
57
|
-
total: 1,
|
58
|
-
}
|
59
|
-
stub_request(
|
60
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig'
|
61
|
-
).with(
|
62
|
-
headers: { 'Authorization' => 'token TTTTTTTTTT',
|
63
|
-
'Content-Type' => 'application/json', }
|
64
|
-
).to_return(body: body.to_json)
|
65
|
-
|
66
|
-
ret = @srv.list
|
67
|
-
expect(ret).to eq(body[:items])
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'fetches' do
|
71
|
-
body = {
|
72
|
-
id: '9K0',
|
73
|
-
name: 'debug',
|
74
|
-
alias: 'XYZ_debug',
|
75
|
-
solution_id: 'XYZ',
|
76
|
-
service: 'device',
|
77
|
-
status: 'ready',
|
78
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
79
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
80
|
-
}
|
81
|
-
stub_request(
|
82
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0'
|
83
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
84
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
85
|
-
|
86
|
-
ret = @srv.fetch('9K0')
|
87
|
-
expect(ret).to eq(body)
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'creates' do
|
91
|
-
body = {
|
92
|
-
id: '9K0',
|
93
|
-
name: 'debug',
|
94
|
-
alias: 'XYZ_debug',
|
95
|
-
solution_id: 'XYZ',
|
96
|
-
service: 'device',
|
97
|
-
status: 'ready',
|
98
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
99
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
100
|
-
}
|
101
|
-
# VERIFY/2017-07-03: Does this POST now need a trailing path delimiter?
|
102
|
-
#stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig").
|
103
|
-
stub_request(
|
104
|
-
:post, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/'
|
105
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
106
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
107
|
-
|
108
|
-
ret = @srv.create('p4q0m2ruyoxierh')
|
109
|
-
expect(ret).to eq(body)
|
110
|
-
end
|
111
|
-
|
112
|
-
it 'removes' do
|
113
|
-
body = {}
|
114
|
-
stub_request(
|
115
|
-
:delete, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0'
|
116
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
117
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
118
|
-
|
119
|
-
ret = @srv.remove('9K0')
|
120
|
-
expect(ret).to eq(body)
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'gets id from service' do
|
124
|
-
body = {
|
125
|
-
items: [
|
126
|
-
{
|
127
|
-
id: '9K0',
|
128
|
-
name: 'debug',
|
129
|
-
alias: 'XYZ_debug',
|
130
|
-
solution_id: 'XYZ',
|
131
|
-
service: 'device',
|
132
|
-
status: 'ready',
|
133
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
134
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
135
|
-
deleted_at: nil,
|
136
|
-
},
|
137
|
-
],
|
138
|
-
total: 1,
|
139
|
-
}
|
140
|
-
stub_request(
|
141
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig'
|
142
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
143
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
144
|
-
|
145
|
-
ret = @srv.scid_for_name('device')
|
146
|
-
expect(ret).to eq('9K0')
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'gets nil if not there' do
|
150
|
-
body = {
|
151
|
-
items: [
|
152
|
-
{
|
153
|
-
id: '9K0',
|
154
|
-
name: 'debug',
|
155
|
-
alias: 'XYZ_debug',
|
156
|
-
solution_id: 'XYZ',
|
157
|
-
service: 'device',
|
158
|
-
status: 'ready',
|
159
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
160
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
161
|
-
deleted_at: nil,
|
162
|
-
},
|
163
|
-
],
|
164
|
-
total: 1,
|
165
|
-
}
|
166
|
-
stub_request(
|
167
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig'
|
168
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
169
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
170
|
-
|
171
|
-
ret = @srv.scid_for_name('debug')
|
172
|
-
expect(ret).to eq(nil)
|
173
|
-
end
|
174
|
-
|
175
|
-
it 'gets info' do
|
176
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
177
|
-
stub_request(
|
178
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/info'
|
179
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
180
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
181
|
-
|
182
|
-
ret = @srv.info('9K0')
|
183
|
-
expect(ret).to eq(body)
|
184
|
-
end
|
185
|
-
|
186
|
-
context 'calls' do
|
187
|
-
before(:example) do
|
188
|
-
allow(@srv).to receive(:scid).and_return('9K0')
|
189
|
-
end
|
190
|
-
it 'a get' do
|
191
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
192
|
-
stub_request(
|
193
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/info'
|
194
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
195
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
196
|
-
|
197
|
-
ret = @srv.call(:info)
|
198
|
-
expect(ret).to eq(body)
|
199
|
-
end
|
200
|
-
|
201
|
-
it 'a get with query' do
|
202
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
203
|
-
stub_request(
|
204
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask?q=what'
|
205
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
206
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
207
|
-
|
208
|
-
ret = @srv.call(:ask, :get, q: 'what')
|
209
|
-
expect(ret).to eq(body)
|
210
|
-
end
|
211
|
-
|
212
|
-
it 'a post' do
|
213
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
214
|
-
stub_request(
|
215
|
-
:post, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask'
|
216
|
-
).with(body: JSON.generate(q: 'what'),
|
217
|
-
headers: { 'Authorization' => 'token TTTTTTTTTT',
|
218
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
219
|
-
|
220
|
-
ret = @srv.call(:ask, :post, q: 'what')
|
221
|
-
expect(ret).to eq(body)
|
222
|
-
end
|
223
|
-
|
224
|
-
it 'a post without data' do
|
225
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
226
|
-
stub_request(
|
227
|
-
:post, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask'
|
228
|
-
).with(body: JSON.generate({}),
|
229
|
-
headers: { 'Authorization' => 'token TTTTTTTTTT',
|
230
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
231
|
-
|
232
|
-
ret = @srv.call(:ask, :post)
|
233
|
-
expect(ret).to eq(body)
|
234
|
-
end
|
235
|
-
|
236
|
-
it 'a put' do
|
237
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
238
|
-
stub_request(
|
239
|
-
:put, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask'
|
240
|
-
).with(body: JSON.generate(q: 'what'),
|
241
|
-
headers: { 'Authorization' => 'token TTTTTTTTTT',
|
242
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
243
|
-
|
244
|
-
ret = @srv.call(:ask, :put, q: 'what')
|
245
|
-
expect(ret).to eq(body)
|
246
|
-
end
|
247
|
-
|
248
|
-
it 'a put without data' do
|
249
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
250
|
-
stub_request(
|
251
|
-
:put, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/ask'
|
252
|
-
).with(body: JSON.generate({}),
|
253
|
-
headers: { 'Authorization' => 'token TTTTTTTTTT',
|
254
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
255
|
-
|
256
|
-
ret = @srv.call(:ask, :put)
|
257
|
-
expect(ret).to eq(body)
|
258
|
-
end
|
259
|
-
|
260
|
-
it 'a delete' do
|
261
|
-
body = { calls: { daily: 0, monthly: 0, total: 0 } }
|
262
|
-
stub_request(
|
263
|
-
:delete, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/serviceconfig/9K0/call/gone'
|
264
|
-
).with(headers: { 'Authorization' => 'token TTTTTTTTTT',
|
265
|
-
'Content-Type' => 'application/json', }).to_return(body: body.to_json)
|
266
|
-
|
267
|
-
ret = @srv.call(:gone, :delete)
|
268
|
-
expect(ret).to eq(body)
|
269
|
-
end
|
270
|
-
end
|
271
|
-
end
|
272
|
-
|
@@ -1,442 +0,0 @@
|
|
1
|
-
# Copyright © 2016-2017 Exosite LLC. All Rights Reserved
|
2
|
-
# License: PROPRIETARY. See LICENSE.txt.
|
3
|
-
# frozen_string_literal: true
|
4
|
-
|
5
|
-
# vim:tw=0:ts=2:sw=2:et:ai
|
6
|
-
# Unauthorized copying of this file is strictly prohibited.
|
7
|
-
|
8
|
-
require 'pathname'
|
9
|
-
require 'tempfile'
|
10
|
-
require 'MrMurano/version'
|
11
|
-
require 'MrMurano/HttpAuthed'
|
12
|
-
require 'MrMurano/ProjectFile'
|
13
|
-
require 'MrMurano/Solution-Services'
|
14
|
-
require '_workspace'
|
15
|
-
require 'HttpAuthed_spec'
|
16
|
-
|
17
|
-
RSpec.describe MrMurano::EventHandler do
|
18
|
-
include_context 'WORKSPACE'
|
19
|
-
before(:example) do
|
20
|
-
$cfg = MrMurano::Config.new
|
21
|
-
$cfg.load
|
22
|
-
$project = MrMurano::ProjectFile.new
|
23
|
-
$project.load
|
24
|
-
$cfg['net.host'] = 'bizapi.hosted.exosite.io'
|
25
|
-
$cfg['application.id'] = 'XYZ'
|
26
|
-
stub_request_email_password
|
27
|
-
|
28
|
-
# 2017-06-23: EventHandler is an intermediate class now, and we
|
29
|
-
# cannot use it because its @project_section is not defined.
|
30
|
-
#@srv = MrMurano::EventHandler.new
|
31
|
-
# It shouldn't matter which final event handler class we use:
|
32
|
-
# the only different is if it uses application.id or product.id.
|
33
|
-
@srv = MrMurano::EventHandlerSolnApp.new
|
34
|
-
#@srv = MrMurano::EventHandlerSolnPrd.new
|
35
|
-
MrMurano::HttpAuthed.instance.instance_variable_set(:@token_biz, 'TTTTTTTTTT')
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'initializes' do
|
39
|
-
uri = @srv.endpoint('/')
|
40
|
-
expect(uri.to_s).to eq('https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'lists' do
|
44
|
-
body = {
|
45
|
-
items: [
|
46
|
-
{
|
47
|
-
id: '9K0',
|
48
|
-
name: 'debug',
|
49
|
-
alias: 'XYZ_debug',
|
50
|
-
solution_id: 'XYZ',
|
51
|
-
service: 'device',
|
52
|
-
event: 'datapoint',
|
53
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
54
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
55
|
-
},
|
56
|
-
],
|
57
|
-
total: 1,
|
58
|
-
}
|
59
|
-
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler')
|
60
|
-
.with(headers: {
|
61
|
-
'Authorization' => 'token TTTTTTTTTT',
|
62
|
-
'Content-Type' => 'application/json',
|
63
|
-
}).to_return(body: body.to_json)
|
64
|
-
ret = @srv.list
|
65
|
-
expect(ret).to eq(body[:items])
|
66
|
-
end
|
67
|
-
|
68
|
-
it 'fetches, with header' do
|
69
|
-
body = {
|
70
|
-
id: '9K0',
|
71
|
-
name: 'debug',
|
72
|
-
alias: 'XYZ_debug',
|
73
|
-
solution_id: 'XYZ',
|
74
|
-
service: 'device',
|
75
|
-
event: 'datapoint',
|
76
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
77
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
78
|
-
header: '--#EVENT device datapoint',
|
79
|
-
script: %{--#EVENT device datapoint
|
80
|
-
-- lua code is here
|
81
|
-
function foo(bar)
|
82
|
-
return bar + 1
|
83
|
-
end
|
84
|
-
},
|
85
|
-
}
|
86
|
-
stub_request(:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0')
|
87
|
-
.with(headers: {
|
88
|
-
'Authorization' => 'token TTTTTTTTTT',
|
89
|
-
'Content-Type' => 'application/json',
|
90
|
-
}).to_return(body: body.to_json)
|
91
|
-
ret = @srv.fetch('9K0')
|
92
|
-
expect(ret).to eq(body[:script])
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'fetches, with header into block' do
|
96
|
-
body = {
|
97
|
-
id: '9K0',
|
98
|
-
name: 'debug',
|
99
|
-
alias: 'XYZ_debug',
|
100
|
-
solution_id: 'XYZ',
|
101
|
-
service: 'device',
|
102
|
-
event: 'datapoint',
|
103
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
104
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
105
|
-
script: %{
|
106
|
-
--#EVENT device datapoint
|
107
|
-
-- lua code is here
|
108
|
-
function foo(bar)
|
109
|
-
return bar + 1
|
110
|
-
end
|
111
|
-
},
|
112
|
-
}
|
113
|
-
stub_request(
|
114
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0'
|
115
|
-
).with(headers: {
|
116
|
-
'Authorization' => 'token TTTTTTTTTT',
|
117
|
-
'Content-Type' => 'application/json',
|
118
|
-
}).to_return(body: body.to_json)
|
119
|
-
ret = nil
|
120
|
-
@srv.fetch('9K0') { |sc| ret = sc }
|
121
|
-
expect(ret).to eq(body[:script])
|
122
|
-
end
|
123
|
-
|
124
|
-
it 'fetches, without header' do
|
125
|
-
body = {
|
126
|
-
id: '9K0',
|
127
|
-
name: 'debug',
|
128
|
-
alias: 'XYZ_debug',
|
129
|
-
solution_id: 'XYZ',
|
130
|
-
service: 'device',
|
131
|
-
event: 'datapoint',
|
132
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
133
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
134
|
-
script: %{-- lua code is here
|
135
|
-
function foo(bar)
|
136
|
-
return bar + 1
|
137
|
-
end
|
138
|
-
},
|
139
|
-
}
|
140
|
-
stub_request(
|
141
|
-
:get, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0'
|
142
|
-
).with(headers: {
|
143
|
-
'Authorization' => 'token TTTTTTTTTT',
|
144
|
-
'Content-Type' => 'application/json',
|
145
|
-
}).to_return(body: body.to_json)
|
146
|
-
|
147
|
-
ret = @srv.fetch('9K0')
|
148
|
-
expect(ret).to eq(%{--#EVENT device datapoint
|
149
|
-
-- lua code is here
|
150
|
-
function foo(bar)
|
151
|
-
return bar + 1
|
152
|
-
end
|
153
|
-
})
|
154
|
-
end
|
155
|
-
|
156
|
-
it 'removes' do
|
157
|
-
stub_request(
|
158
|
-
:delete, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0'
|
159
|
-
).with(headers: {
|
160
|
-
'Authorization' => 'token TTTTTTTTTT',
|
161
|
-
'Content-Type' => 'application/json',
|
162
|
-
}).to_return(body: '')
|
163
|
-
|
164
|
-
ret = @srv.remove('9K0')
|
165
|
-
expect(ret).to eq({})
|
166
|
-
end
|
167
|
-
|
168
|
-
it 'uploads over old version' do
|
169
|
-
stub_request(
|
170
|
-
:put, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_data_datapoint'
|
171
|
-
).with(headers: {
|
172
|
-
'Authorization' => 'token TTTTTTTTTT',
|
173
|
-
'Content-Type' => 'application/json',
|
174
|
-
}).to_return(body: '')
|
175
|
-
|
176
|
-
Tempfile.open('foo') do |tio|
|
177
|
-
tio << %{
|
178
|
-
-- lua code is here
|
179
|
-
function foo(bar)
|
180
|
-
return bar + 1
|
181
|
-
end
|
182
|
-
}
|
183
|
-
tio.close
|
184
|
-
|
185
|
-
ret = @srv.upload(tio.path,
|
186
|
-
MrMurano::EventHandler::EventHandlerItem.new(
|
187
|
-
id: '9K0',
|
188
|
-
service: 'data',
|
189
|
-
event: 'datapoint',
|
190
|
-
solution_id: 'XYZ',
|
191
|
-
))
|
192
|
-
expect(ret)
|
193
|
-
end
|
194
|
-
end
|
195
|
-
|
196
|
-
it 'uploads when nothing is there' do
|
197
|
-
stub_request(:put, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_device_datapoint')
|
198
|
-
.with(headers: {
|
199
|
-
'Authorization' => 'token TTTTTTTTTT',
|
200
|
-
'Content-Type' => 'application/json',
|
201
|
-
}).to_return(status: 404)
|
202
|
-
|
203
|
-
stub_request(:post, 'https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/')
|
204
|
-
.with(headers: {
|
205
|
-
'Authorization' => 'token TTTTTTTTTT',
|
206
|
-
'Content-Type' => 'application/json',
|
207
|
-
}).to_return(body: '')
|
208
|
-
|
209
|
-
Tempfile.open('foo') do |tio|
|
210
|
-
tio << %{
|
211
|
-
-- lua code is here
|
212
|
-
function foo(bar)
|
213
|
-
return bar + 1
|
214
|
-
end
|
215
|
-
}
|
216
|
-
tio.close
|
217
|
-
|
218
|
-
ret = @srv.upload(tio.path,
|
219
|
-
MrMurano::EventHandler::EventHandlerItem.new(
|
220
|
-
id: '9K0',
|
221
|
-
service: 'device',
|
222
|
-
event: 'datapoint',
|
223
|
-
solution_id: 'XYZ',
|
224
|
-
))
|
225
|
-
expect(ret)
|
226
|
-
end
|
227
|
-
end
|
228
|
-
|
229
|
-
context 'compares' do
|
230
|
-
before(:example) do
|
231
|
-
@i_a = {
|
232
|
-
id: '9K0',
|
233
|
-
name: 'debug',
|
234
|
-
alias: 'XYZ_debug',
|
235
|
-
solution_id: 'XYZ',
|
236
|
-
service: 'device',
|
237
|
-
event: 'datapoint',
|
238
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
239
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
240
|
-
}
|
241
|
-
@i_b = {
|
242
|
-
id: '9K0',
|
243
|
-
name: 'debug',
|
244
|
-
alias: 'XYZ_debug',
|
245
|
-
solution_id: 'XYZ',
|
246
|
-
service: 'device',
|
247
|
-
event: 'datapoint',
|
248
|
-
created_at: '2016-07-07T19:16:19.479Z',
|
249
|
-
updated_at: '2016-09-12T13:26:55.868Z',
|
250
|
-
}
|
251
|
-
end
|
252
|
-
it 'both have updated_at' do
|
253
|
-
ret = @srv.docmp(@i_a, @i_b)
|
254
|
-
expect(ret).to eq(false)
|
255
|
-
end
|
256
|
-
|
257
|
-
it 'i_a is a local file' do
|
258
|
-
Tempfile.open('foo') do |tio|
|
259
|
-
tio << 'something'
|
260
|
-
tio.close
|
261
|
-
i_a = @i_a.reject { |k, _v| k == :updated_at }.merge(local_path: Pathname.new(tio.path))
|
262
|
-
ret = @srv.docmp(i_a, @i_b)
|
263
|
-
expect(ret).to eq(true)
|
264
|
-
|
265
|
-
i_b = @i_b.merge(updated_at: Pathname.new(tio.path).mtime.getutc)
|
266
|
-
ret = @srv.docmp(i_a, i_b)
|
267
|
-
expect(ret).to eq(false)
|
268
|
-
end
|
269
|
-
end
|
270
|
-
|
271
|
-
it 'i_b is a local file' do
|
272
|
-
Tempfile.open('foo') do |tio|
|
273
|
-
tio << 'something'
|
274
|
-
tio.close
|
275
|
-
i_b = @i_b.reject { |k, _v| k == :updated_at }.merge(local_path: Pathname.new(tio.path))
|
276
|
-
ret = @srv.docmp(@i_a, i_b)
|
277
|
-
expect(ret).to eq(true)
|
278
|
-
|
279
|
-
i_a = @i_a.merge(updated_at: Pathname.new(tio.path).mtime.getutc)
|
280
|
-
ret = @srv.docmp(i_a, i_b)
|
281
|
-
expect(ret).to eq(false)
|
282
|
-
end
|
283
|
-
end
|
284
|
-
end
|
285
|
-
|
286
|
-
context 'Lookup functions' do
|
287
|
-
it 'gets local name' do
|
288
|
-
ret = @srv.tolocalname({ name: 'bob' }, nil)
|
289
|
-
expect(ret).to eq('bob.lua')
|
290
|
-
end
|
291
|
-
|
292
|
-
it 'gets synckey' do
|
293
|
-
ret = @srv.synckey(service: 'device', event: 'datapoint')
|
294
|
-
expect(ret).to eq('device_datapoint')
|
295
|
-
end
|
296
|
-
|
297
|
-
it 'gets searchfor' do
|
298
|
-
$cfg['eventhandler.searchFor'] = %(a b c/**/d/*.bob)
|
299
|
-
ret = @srv.searchFor
|
300
|
-
expect(ret).to eq(['a', 'b', 'c/**/d/*.bob'])
|
301
|
-
end
|
302
|
-
|
303
|
-
it 'gets ignoring' do
|
304
|
-
$cfg['eventhandler.ignoring'] = %(a b c/**/d/*.bob)
|
305
|
-
ret = @srv.ignoring
|
306
|
-
expect(ret).to eq(['a', 'b', 'c/**/d/*.bob'])
|
307
|
-
end
|
308
|
-
|
309
|
-
it 'raises on alias without service' do
|
310
|
-
expect do
|
311
|
-
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(event: 'bob'))
|
312
|
-
end.to raise_error %(Missing parts! {"event":"bob"})
|
313
|
-
end
|
314
|
-
|
315
|
-
it 'raises on alias without event' do
|
316
|
-
expect do
|
317
|
-
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(service: 'bob'))
|
318
|
-
end.to raise_error %(Missing parts! {"service":"bob"})
|
319
|
-
end
|
320
|
-
|
321
|
-
it 'raises on name without service' do
|
322
|
-
expect do
|
323
|
-
@srv.mkalias(MrMurano::EventHandler::EventHandlerItem.new(event: 'bob'))
|
324
|
-
end.to raise_error %(Missing parts! {"event":"bob"})
|
325
|
-
end
|
326
|
-
|
327
|
-
it 'raises on name without event' do
|
328
|
-
expect do
|
329
|
-
@srv.mkname(MrMurano::EventHandler::EventHandlerItem.new(service: 'bob'))
|
330
|
-
end.to raise_error %(Missing parts! {"service":"bob"})
|
331
|
-
end
|
332
|
-
end
|
333
|
-
|
334
|
-
context 'to_remote_items' do
|
335
|
-
before(:example) do
|
336
|
-
allow(@srv).to receive(:warning)
|
337
|
-
end
|
338
|
-
|
339
|
-
it 'reads one' do
|
340
|
-
Tempfile.open('foo') do |tio|
|
341
|
-
tio << %(--#EVENT device datapoint
|
342
|
-
-- do something.
|
343
|
-
Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
|
344
|
-
).gsub(/^\s+/, '')
|
345
|
-
tio.close
|
346
|
-
|
347
|
-
want = [
|
348
|
-
{
|
349
|
-
service: 'device',
|
350
|
-
event: 'datapoint',
|
351
|
-
svc_alias: nil,
|
352
|
-
type: nil,
|
353
|
-
line_beg: 1,
|
354
|
-
line_end: 3,
|
355
|
-
local_path: Pathname.new(tio.path),
|
356
|
-
header: %(--#EVENT device datapoint),
|
357
|
-
script: %(-- do something.\nTsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n),
|
358
|
-
},
|
359
|
-
]
|
360
|
-
ret = @srv.to_remote_items(nil, tio.path)
|
361
|
-
expect(ret).to eq(want)
|
362
|
-
end
|
363
|
-
end
|
364
|
-
|
365
|
-
it 'skips all when no header found' do
|
366
|
-
Tempfile.open('foo') do |tio|
|
367
|
-
tio << %(
|
368
|
-
-- do something.
|
369
|
-
Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
|
370
|
-
).gsub(/^\s+/, '')
|
371
|
-
tio.close
|
372
|
-
|
373
|
-
ret = @srv.to_remote_items(nil, tio.path)
|
374
|
-
expect(ret).to eq([])
|
375
|
-
end
|
376
|
-
end
|
377
|
-
|
378
|
-
it 'skips junk at begining' do
|
379
|
-
Tempfile.open('foo') do |tio|
|
380
|
-
tio << %(
|
381
|
-
-- do something.
|
382
|
-
--#EVENT device datapoint
|
383
|
-
Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}
|
384
|
-
).gsub(/^\s+/, '')
|
385
|
-
tio.close
|
386
|
-
|
387
|
-
want = [
|
388
|
-
MrMurano::EventHandler::EventHandlerItem.new(
|
389
|
-
service: 'device',
|
390
|
-
event: 'datapoint',
|
391
|
-
svc_alias: nil,
|
392
|
-
type: nil,
|
393
|
-
line_beg: 2, # Skips the "-- do something." line, before --#EVENT.
|
394
|
-
line_end: 3,
|
395
|
-
local_path: Pathname.new(tio.path),
|
396
|
-
header: %(--#EVENT device datapoint),
|
397
|
-
script: %(Tsdb.write{tags={sn='1'},metrics={[data.alias]=data.value[2]}}\n),
|
398
|
-
),
|
399
|
-
]
|
400
|
-
ret = @srv.to_remote_items(nil, tio.path)
|
401
|
-
expect(ret).to eq(want)
|
402
|
-
end
|
403
|
-
end
|
404
|
-
end
|
405
|
-
|
406
|
-
context 'Matching' do
|
407
|
-
before(:example) do
|
408
|
-
@an_item = {
|
409
|
-
service: 'bob',
|
410
|
-
event: 'built',
|
411
|
-
local_path: Pathname.new('a/relative/path.lua'),
|
412
|
-
}
|
413
|
-
end
|
414
|
-
context 'service' do
|
415
|
-
it 'any event' do
|
416
|
-
ret = @srv.match(@an_item, '#bob#')
|
417
|
-
expect(ret).to be true
|
418
|
-
ret = @srv.match(@an_item, '#email#')
|
419
|
-
expect(ret).to be false
|
420
|
-
end
|
421
|
-
it 'exact event' do
|
422
|
-
ret = @srv.match(@an_item, '#bob#built')
|
423
|
-
expect(ret).to be true
|
424
|
-
ret = @srv.match(@an_item, '#email#built')
|
425
|
-
expect(ret).to be false
|
426
|
-
end
|
427
|
-
end
|
428
|
-
context 'any service' do
|
429
|
-
it 'any event' do
|
430
|
-
ret = @srv.match(@an_item, '##')
|
431
|
-
expect(ret).to be true
|
432
|
-
end
|
433
|
-
it 'exact event' do
|
434
|
-
ret = @srv.match(@an_item, '##built')
|
435
|
-
expect(ret).to be true
|
436
|
-
ret = @srv.match(@an_item, '##sent')
|
437
|
-
expect(ret).to be false
|
438
|
-
end
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
442
|
-
|