MrMurano 1.4.3 → 1.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +1 -0
- data/Gemfile +1 -0
- data/MrMurano.gemspec +4 -0
- data/README.markdown +84 -0
- data/Rakefile +4 -3
- data/TODO.taskpaper +9 -9
- data/bin/mr +2 -0
- data/lib/MrMurano/Account.rb +4 -55
- data/lib/MrMurano/{configFile.rb → Config.rb} +60 -10
- data/lib/MrMurano/Product.rb +16 -4
- data/lib/MrMurano/Solution-Endpoint.rb +3 -3
- data/lib/MrMurano/Solution-File.rb +4 -10
- data/lib/MrMurano/Solution-ServiceConfig.rb +1 -52
- data/lib/MrMurano/Solution-Services.rb +44 -8
- data/lib/MrMurano/Solution-Users.rb +2 -2
- data/lib/MrMurano/Solution.rb +3 -0
- data/lib/MrMurano/commands/account.rb +54 -0
- data/lib/MrMurano/commands/assign.rb +54 -0
- data/lib/MrMurano/{configCommand.rb → commands/config.rb} +0 -0
- data/lib/MrMurano/{contentCommand.rb → commands/content.rb} +0 -0
- data/lib/MrMurano/{cors.rb → commands/cors.rb} +0 -0
- data/lib/MrMurano/commands/domain.rb +17 -0
- data/lib/MrMurano/{exportImport.rb → commands/exportImport.rb} +32 -15
- data/lib/MrMurano/{keystore.rb → commands/keystore.rb} +0 -0
- data/lib/MrMurano/{logs.rb → commands/logs.rb} +0 -0
- data/lib/MrMurano/commands/productSpec.rb +94 -0
- data/lib/MrMurano/{status.rb → commands/status.rb} +0 -0
- data/lib/MrMurano/{sync.rb → commands/sync.rb} +0 -0
- data/lib/MrMurano/{timeseries.rb → commands/timeseries.rb} +0 -0
- data/lib/MrMurano/commands.rb +14 -0
- data/lib/MrMurano/http.rb +24 -3
- data/lib/MrMurano/version.rb +1 -1
- data/lib/MrMurano.rb +9 -17
- data/spec/Account-Passwords_spec.rb +2 -11
- data/spec/ConfigFile_spec.rb +48 -0
- data/spec/Config_spec.rb +329 -0
- data/spec/ProductBase_spec.rb +0 -3
- data/spec/ProductContent_spec.rb +0 -3
- data/spec/Product_spec.rb +0 -3
- data/spec/Solution-ServiceEventHandler_spec.rb +217 -0
- data/spec/Solution-ServiceModules_spec.rb +177 -0
- data/spec/testfiles/configfile +9 -0
- metadata +42 -14
- data/lib/MrMurano/shelledCommand.rb +0 -43
data/spec/Config_spec.rb
ADDED
@@ -0,0 +1,329 @@
|
|
1
|
+
require 'MrMurano/version'
|
2
|
+
require 'MrMurano/Config'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
RSpec.describe MrMurano::Config do
|
6
|
+
context "Basics " do
|
7
|
+
before(:example) do
|
8
|
+
@tmpdir = Dir.tmpdir
|
9
|
+
@projectDir = @tmpdir + '/home/work/project'
|
10
|
+
FileUtils.mkpath(@projectDir)
|
11
|
+
# Set ENV to override output of Dir.home
|
12
|
+
ENV['HOME'] = @tmpdir + '/home'
|
13
|
+
end
|
14
|
+
|
15
|
+
after(:example) do
|
16
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
17
|
+
end
|
18
|
+
|
19
|
+
it "Sets defaults" do
|
20
|
+
Dir.chdir(@projectDir) do
|
21
|
+
cfg = MrMurano::Config.new
|
22
|
+
cfg.load
|
23
|
+
# Don't check for all of them, just a few.
|
24
|
+
expect(cfg['files.default_page']).to eq('index.html')
|
25
|
+
expect(cfg.get('files.default_page', :defaults)).to eq('index.html')
|
26
|
+
expect(cfg['tool.debug']).to eq(false)
|
27
|
+
expect(cfg.get('tool.debug', :defaults)).to eq(false)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
it "Sets internal values" do
|
32
|
+
Dir.chdir(@projectDir) do
|
33
|
+
cfg = MrMurano::Config.new
|
34
|
+
cfg.load
|
35
|
+
|
36
|
+
cfg['bob.test'] = 'twelve'
|
37
|
+
|
38
|
+
expect(cfg['bob.test']).to eq('twelve')
|
39
|
+
expect(cfg.get('bob.test', :internal)).to eq('twelve')
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
it "Sets project values" do # This should write
|
44
|
+
Dir.chdir(@projectDir) do
|
45
|
+
cfg = MrMurano::Config.new
|
46
|
+
cfg.load
|
47
|
+
|
48
|
+
cfg.set('bob.test', 'twelve', :project)
|
49
|
+
|
50
|
+
expect(cfg['bob.test']).to eq('twelve')
|
51
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
52
|
+
|
53
|
+
expect(FileTest.exist?(@projectDir + '.mrmuranorc'))
|
54
|
+
|
55
|
+
#reload
|
56
|
+
cfg = MrMurano::Config.new
|
57
|
+
cfg.load
|
58
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
it "loads from a specific file" do
|
63
|
+
Dir.chdir(@projectDir) do
|
64
|
+
File.open(@projectDir + '/foo.cfg', 'w') do |io|
|
65
|
+
io << %{[test]
|
66
|
+
bob = test
|
67
|
+
}
|
68
|
+
end
|
69
|
+
|
70
|
+
cfg = MrMurano::Config.new
|
71
|
+
cfg.load
|
72
|
+
cfg.load_specific(@projectDir + '/foo.cfg')
|
73
|
+
|
74
|
+
expect(cfg['test.bob']).to eq('test')
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
it "returns a path to a file in project mrmurano dir" do
|
79
|
+
Dir.chdir(@projectDir) do
|
80
|
+
cfg = MrMurano::Config.new
|
81
|
+
cfg.load
|
82
|
+
path = cfg.file_at('testfile').realdirpath
|
83
|
+
want = Pathname.new(@projectDir + '/.mrmurano/testfile').realdirpath
|
84
|
+
|
85
|
+
expect(path).to eq(want)
|
86
|
+
end
|
87
|
+
end
|
88
|
+
|
89
|
+
it "returns a path to a file in user mrmurano dir" do
|
90
|
+
Dir.chdir(@projectDir) do
|
91
|
+
cfg = MrMurano::Config.new
|
92
|
+
cfg.load
|
93
|
+
path = cfg.file_at('testfile', :user).realdirpath
|
94
|
+
want = Pathname.new(Dir.home + '/.mrmurano/testfile').realdirpath
|
95
|
+
|
96
|
+
expect(path).to eq(want)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
context "ENV['MR_CONFIGFILE']" do
|
101
|
+
it "loads file in env" do
|
102
|
+
ENV['MR_CONFIGFILE'] = @tmpdir + '/home/test.config'
|
103
|
+
File.open(@tmpdir + '/home/test.config', 'w') do |io|
|
104
|
+
io << %{[test]
|
105
|
+
bob = test
|
106
|
+
}
|
107
|
+
end
|
108
|
+
|
109
|
+
cfg = MrMurano::Config.new
|
110
|
+
cfg.load
|
111
|
+
expect(cfg['test.bob']).to eq('test')
|
112
|
+
end
|
113
|
+
|
114
|
+
it "will create file at env" do
|
115
|
+
ENV['MR_CONFIGFILE'] = @tmpdir + '/home/testcreate.config'
|
116
|
+
cfg = MrMurano::Config.new
|
117
|
+
cfg.load
|
118
|
+
cfg.set('coffee.hot', 'yes', :env)
|
119
|
+
|
120
|
+
expect(FileTest.exist?(ENV['MR_CONFIGFILE']))
|
121
|
+
|
122
|
+
#reload
|
123
|
+
cfg = MrMurano::Config.new
|
124
|
+
cfg.load
|
125
|
+
expect(cfg['coffee.hot']).to eq('yes')
|
126
|
+
expect(cfg.get('coffee.hot', :env)).to eq('yes')
|
127
|
+
end
|
128
|
+
end
|
129
|
+
end
|
130
|
+
|
131
|
+
context "Can find the project directory by .mrmuranorc" do
|
132
|
+
before(:example) do
|
133
|
+
@tmpdir = Dir.tmpdir
|
134
|
+
path = '/home/work/project/some/where'
|
135
|
+
@projectDir = @tmpdir + '/home/work/project'
|
136
|
+
FileUtils.mkpath(@tmpdir + path)
|
137
|
+
FileUtils.touch(@projectDir + '/.mrmuranorc')
|
138
|
+
|
139
|
+
# Set ENV to override output of Dir.home
|
140
|
+
ENV['HOME'] = @tmpdir + '/home'
|
141
|
+
end
|
142
|
+
|
143
|
+
after(:example) do
|
144
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
145
|
+
end
|
146
|
+
|
147
|
+
it "when in project directory" do
|
148
|
+
Dir.chdir(@projectDir) do
|
149
|
+
cfg = MrMurano::Config.new
|
150
|
+
cfg.load
|
151
|
+
# Follow symlinks to get the paths comparable.
|
152
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
153
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
154
|
+
expect(locbase).to eq(wkd)
|
155
|
+
end
|
156
|
+
end
|
157
|
+
|
158
|
+
it "when in sub directory" do
|
159
|
+
Dir.chdir(@projectDir + '/some/where') do
|
160
|
+
cfg = MrMurano::Config.new
|
161
|
+
cfg.load
|
162
|
+
# Follow symlinks to get the paths comparable.
|
163
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
164
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
165
|
+
expect(locbase).to eq(wkd)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
context "Can find the project directory by .mrmurano/" do
|
171
|
+
before(:example) do
|
172
|
+
@tmpdir = Dir.tmpdir
|
173
|
+
path = '/home/work/project/some/where'
|
174
|
+
@projectDir = @tmpdir + '/home/work/project'
|
175
|
+
FileUtils.mkpath(@tmpdir + path)
|
176
|
+
FileUtils.mkpath(@projectDir + '/.mrmurano')
|
177
|
+
|
178
|
+
# Set ENV to override output of Dir.home
|
179
|
+
ENV['HOME'] = @tmpdir + '/home'
|
180
|
+
end
|
181
|
+
|
182
|
+
after(:example) do
|
183
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
184
|
+
end
|
185
|
+
|
186
|
+
it "when in project directory" do
|
187
|
+
Dir.chdir(@projectDir) do
|
188
|
+
cfg = MrMurano::Config.new
|
189
|
+
cfg.load
|
190
|
+
# Follow symlinks to get the paths comparable.
|
191
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
192
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
193
|
+
expect(locbase).to eq(wkd)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it "when in sub directory" do
|
198
|
+
Dir.chdir(@projectDir + '/some/where') do
|
199
|
+
cfg = MrMurano::Config.new
|
200
|
+
cfg.load
|
201
|
+
# Follow symlinks to get the paths comparable.
|
202
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
203
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
204
|
+
expect(locbase).to eq(wkd)
|
205
|
+
end
|
206
|
+
end
|
207
|
+
end
|
208
|
+
|
209
|
+
context "Can find the project directory by .git/" do
|
210
|
+
before(:example) do
|
211
|
+
@tmpdir = Dir.tmpdir
|
212
|
+
path = '/home/work/project/some/where'
|
213
|
+
@projectDir = @tmpdir + '/home/work/project'
|
214
|
+
FileUtils.mkpath(@tmpdir + path)
|
215
|
+
FileUtils.mkpath(@projectDir + '/.git')
|
216
|
+
|
217
|
+
# Set ENV to override output of Dir.home
|
218
|
+
ENV['HOME'] = @tmpdir + '/home'
|
219
|
+
end
|
220
|
+
|
221
|
+
after(:example) do
|
222
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
223
|
+
end
|
224
|
+
|
225
|
+
it "when in project directory" do
|
226
|
+
Dir.chdir(@projectDir) do
|
227
|
+
cfg = MrMurano::Config.new
|
228
|
+
cfg.load
|
229
|
+
# Follow symlinks to get the paths comparable.
|
230
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
231
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
232
|
+
expect(locbase).to eq(wkd)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
it "when in sub directory" do
|
237
|
+
Dir.chdir(@projectDir + '/some/where') do
|
238
|
+
cfg = MrMurano::Config.new
|
239
|
+
cfg.load
|
240
|
+
# Follow symlinks to get the paths comparable.
|
241
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
242
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
243
|
+
expect(locbase).to eq(wkd)
|
244
|
+
end
|
245
|
+
end
|
246
|
+
end
|
247
|
+
|
248
|
+
context "Can find the project directory by .mrmuranorc but not sub .git/" do
|
249
|
+
before(:example) do
|
250
|
+
@tmpdir = Dir.tmpdir
|
251
|
+
path = '/home/work/project/some/where'
|
252
|
+
@projectDir = @tmpdir + '/home/work/project'
|
253
|
+
FileUtils.mkpath(@tmpdir + path)
|
254
|
+
FileUtils.touch(@projectDir + '/.mrmuranorc')
|
255
|
+
FileUtils.mkpath(@projectDir + '/some/.git')
|
256
|
+
|
257
|
+
# Set ENV to override output of Dir.home
|
258
|
+
ENV['HOME'] = @tmpdir + '/home'
|
259
|
+
end
|
260
|
+
|
261
|
+
after(:example) do
|
262
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
263
|
+
end
|
264
|
+
|
265
|
+
it "when in project directory" do
|
266
|
+
Dir.chdir(@projectDir) do
|
267
|
+
cfg = MrMurano::Config.new
|
268
|
+
cfg.load
|
269
|
+
# Follow symlinks to get the paths comparable.
|
270
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
271
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
272
|
+
expect(locbase).to eq(wkd)
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
it "when in sub directory" do
|
277
|
+
Dir.chdir(@projectDir + '/some/where') do
|
278
|
+
cfg = MrMurano::Config.new
|
279
|
+
cfg.load
|
280
|
+
# Follow symlinks to get the paths comparable.
|
281
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
282
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
283
|
+
expect(locbase).to eq(wkd)
|
284
|
+
end
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
context "Can find the project directory by .mrmurano/ but not sub .git/" do
|
289
|
+
before(:example) do
|
290
|
+
@tmpdir = Dir.tmpdir
|
291
|
+
path = '/home/work/project/some/where'
|
292
|
+
@projectDir = @tmpdir + '/home/work/project'
|
293
|
+
FileUtils.mkpath(@tmpdir + path)
|
294
|
+
FileUtils.mkpath(@projectDir + '/.mrmurano')
|
295
|
+
FileUtils.mkpath(@projectDir + '/some/.git')
|
296
|
+
|
297
|
+
# Set ENV to override output of Dir.home
|
298
|
+
ENV['HOME'] = @tmpdir + '/home'
|
299
|
+
end
|
300
|
+
|
301
|
+
after(:example) do
|
302
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
303
|
+
end
|
304
|
+
|
305
|
+
it "when in project directory" do
|
306
|
+
Dir.chdir(@projectDir) do
|
307
|
+
cfg = MrMurano::Config.new
|
308
|
+
cfg.load
|
309
|
+
# Follow symlinks to get the paths comparable.
|
310
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
311
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
312
|
+
expect(locbase).to eq(wkd)
|
313
|
+
end
|
314
|
+
end
|
315
|
+
|
316
|
+
it "when in sub directory" do
|
317
|
+
Dir.chdir(@projectDir + '/some/where') do
|
318
|
+
cfg = MrMurano::Config.new
|
319
|
+
cfg.load
|
320
|
+
# Follow symlinks to get the paths comparable.
|
321
|
+
locbase = cfg.get('location.base', :defaults).realdirpath
|
322
|
+
wkd = Pathname.new(@projectDir).realdirpath
|
323
|
+
expect(locbase).to eq(wkd)
|
324
|
+
end
|
325
|
+
end
|
326
|
+
end
|
327
|
+
end
|
328
|
+
|
329
|
+
# vim: set ai et sw=2 ts=2 :
|
data/spec/ProductBase_spec.rb
CHANGED
data/spec/ProductContent_spec.rb
CHANGED
data/spec/Product_spec.rb
CHANGED
@@ -0,0 +1,217 @@
|
|
1
|
+
require 'MrMurano/version'
|
2
|
+
require 'MrMurano/Solution-Services'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
RSpec.describe MrMurano::EventHandler do
|
6
|
+
before(:example) do
|
7
|
+
$cfg = MrMurano::Config.new
|
8
|
+
$cfg.load
|
9
|
+
$cfg['net.host'] = 'bizapi.hosted.exosite.io'
|
10
|
+
$cfg['solution.id'] = 'XYZ'
|
11
|
+
|
12
|
+
@srv = MrMurano::EventHandler.new
|
13
|
+
allow(@srv).to receive(:token).and_return("TTTTTTTTTT")
|
14
|
+
end
|
15
|
+
|
16
|
+
it "initializes" do
|
17
|
+
uri = @srv.endPoint('/')
|
18
|
+
expect(uri.to_s).to eq("https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/")
|
19
|
+
end
|
20
|
+
|
21
|
+
it "lists" do
|
22
|
+
body = {:items=>[{:id=>"9K0",
|
23
|
+
:name=>"debug",
|
24
|
+
:alias=>"XYZ_debug",
|
25
|
+
:solution_id=>"XYZ",
|
26
|
+
:service=>"device",
|
27
|
+
:event=>"datapoint",
|
28
|
+
:created_at=>"2016-07-07T19:16:19.479Z",
|
29
|
+
:updated_at=>"2016-09-12T13:26:55.868Z"}],
|
30
|
+
:total=>1}
|
31
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler").
|
32
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
33
|
+
'Content-Type'=>'application/json'}).
|
34
|
+
to_return(body: body.to_json)
|
35
|
+
|
36
|
+
ret = @srv.list()
|
37
|
+
expect(ret).to eq(body[:items])
|
38
|
+
end
|
39
|
+
|
40
|
+
it "fetches, with header" do
|
41
|
+
body = {:id=>"9K0",
|
42
|
+
:name=>"debug",
|
43
|
+
:alias=>"XYZ_debug",
|
44
|
+
:solution_id=>"XYZ",
|
45
|
+
:service=>"device",
|
46
|
+
:event=>"datapoint",
|
47
|
+
:created_at=>"2016-07-07T19:16:19.479Z",
|
48
|
+
:updated_at=>"2016-09-12T13:26:55.868Z",
|
49
|
+
:script=>%{--#EVENT device datapoint
|
50
|
+
-- lua code is here
|
51
|
+
function foo(bar)
|
52
|
+
return bar + 1
|
53
|
+
end
|
54
|
+
}
|
55
|
+
}
|
56
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
57
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
58
|
+
'Content-Type'=>'application/json'}).
|
59
|
+
to_return(body: body.to_json)
|
60
|
+
|
61
|
+
ret = @srv.fetch('9K0')
|
62
|
+
expect(ret).to eq(body[:script])
|
63
|
+
end
|
64
|
+
|
65
|
+
it "fetches, without header" do
|
66
|
+
body = {: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
|
+
:script=>%{-- lua code is here
|
75
|
+
function foo(bar)
|
76
|
+
return bar + 1
|
77
|
+
end
|
78
|
+
}
|
79
|
+
}
|
80
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
81
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
82
|
+
'Content-Type'=>'application/json'}).
|
83
|
+
to_return(body: body.to_json)
|
84
|
+
|
85
|
+
ret = @srv.fetch('9K0')
|
86
|
+
expect(ret).to eq(%{--#EVENT device datapoint
|
87
|
+
-- lua code is here
|
88
|
+
function foo(bar)
|
89
|
+
return bar + 1
|
90
|
+
end
|
91
|
+
})
|
92
|
+
end
|
93
|
+
|
94
|
+
it "removes" do
|
95
|
+
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/9K0").
|
96
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
97
|
+
'Content-Type'=>'application/json'}).
|
98
|
+
to_return(body: "")
|
99
|
+
|
100
|
+
ret = @srv.remove('9K0')
|
101
|
+
expect(ret).to eq({})
|
102
|
+
end
|
103
|
+
|
104
|
+
it "uploads over old version" do
|
105
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_debug").
|
106
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
107
|
+
'Content-Type'=>'application/json'}).
|
108
|
+
to_return(body: "")
|
109
|
+
|
110
|
+
Tempfile.open('foo') do |tio|
|
111
|
+
tio << %{-- lua code is here
|
112
|
+
function foo(bar)
|
113
|
+
return bar + 1
|
114
|
+
end
|
115
|
+
}
|
116
|
+
tio.close
|
117
|
+
|
118
|
+
ret = @srv.upload(tio.path, {:id=>"9K0",
|
119
|
+
:name=>"debug",
|
120
|
+
:alias=>"XYZ_debug",
|
121
|
+
:solution_id=>"XYZ",
|
122
|
+
})
|
123
|
+
expect(ret)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
127
|
+
it "uploads when nothing is there" do
|
128
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/XYZ_debug").
|
129
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
130
|
+
'Content-Type'=>'application/json'}).
|
131
|
+
to_return(status: 404)
|
132
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/eventhandler/").
|
133
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
134
|
+
'Content-Type'=>'application/json'}).
|
135
|
+
to_return(body: "")
|
136
|
+
|
137
|
+
Tempfile.open('foo') do |tio|
|
138
|
+
tio << %{-- lua code is here
|
139
|
+
function foo(bar)
|
140
|
+
return bar + 1
|
141
|
+
end
|
142
|
+
}
|
143
|
+
tio.close
|
144
|
+
|
145
|
+
ret = @srv.upload(tio.path, {:id=>"9K0",
|
146
|
+
:name=>"debug",
|
147
|
+
:alias=>"XYZ_debug",
|
148
|
+
:solution_id=>"XYZ",
|
149
|
+
:service=>"device",
|
150
|
+
:event=>"datapoint",
|
151
|
+
})
|
152
|
+
expect(ret)
|
153
|
+
end
|
154
|
+
|
155
|
+
end
|
156
|
+
|
157
|
+
context "compares" do
|
158
|
+
before(:example) do
|
159
|
+
@iA = {:id=>"9K0",
|
160
|
+
:name=>"debug",
|
161
|
+
:alias=>"XYZ_debug",
|
162
|
+
:solution_id=>"XYZ",
|
163
|
+
:service=>"device",
|
164
|
+
:event=>"datapoint",
|
165
|
+
:created_at=>"2016-07-07T19:16:19.479Z",
|
166
|
+
:updated_at=>"2016-09-12T13:26:55.868Z"}
|
167
|
+
@iB = {:id=>"9K0",
|
168
|
+
:name=>"debug",
|
169
|
+
:alias=>"XYZ_debug",
|
170
|
+
:solution_id=>"XYZ",
|
171
|
+
:service=>"device",
|
172
|
+
:event=>"datapoint",
|
173
|
+
:created_at=>"2016-07-07T19:16:19.479Z",
|
174
|
+
:updated_at=>"2016-09-12T13:26:55.868Z"}
|
175
|
+
end
|
176
|
+
it "both have updated_at" do
|
177
|
+
ret = @srv.docmp(@iA, @iB)
|
178
|
+
expect(ret).to eq(false)
|
179
|
+
end
|
180
|
+
|
181
|
+
it "iA is a local file" do
|
182
|
+
Tempfile.open('foo') do |tio|
|
183
|
+
tio << "something"
|
184
|
+
tio.close
|
185
|
+
iA = @iA.reject{|k,v| k == :updated_at}.merge({
|
186
|
+
:local_path => Pathname.new(tio.path)
|
187
|
+
})
|
188
|
+
ret = @srv.docmp(iA, @iB)
|
189
|
+
expect(ret).to eq(true)
|
190
|
+
|
191
|
+
iB = @iB.merge({:updated_at=>Pathname.new(tio.path).mtime.getutc})
|
192
|
+
ret = @srv.docmp(iA, iB)
|
193
|
+
expect(ret).to eq(false)
|
194
|
+
end
|
195
|
+
end
|
196
|
+
|
197
|
+
it "iB is a local file" do
|
198
|
+
Tempfile.open('foo') do |tio|
|
199
|
+
tio << "something"
|
200
|
+
tio.close
|
201
|
+
iB = @iB.reject{|k,v| k == :updated_at}.merge({
|
202
|
+
:local_path => Pathname.new(tio.path)
|
203
|
+
})
|
204
|
+
ret = @srv.docmp(@iA, iB)
|
205
|
+
expect(ret).to eq(true)
|
206
|
+
|
207
|
+
iA = @iA.merge({:updated_at=>Pathname.new(tio.path).mtime.getutc})
|
208
|
+
ret = @srv.docmp(iA, iB)
|
209
|
+
expect(ret).to eq(false)
|
210
|
+
end
|
211
|
+
end
|
212
|
+
end
|
213
|
+
|
214
|
+
# TODO: status tests
|
215
|
+
|
216
|
+
end
|
217
|
+
# vim: set ai et sw=2 ts=2 :
|