MrMurano 1.10.4 → 1.11.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/LICENSE.txt +19 -0
- data/MrMurano.iss +50 -0
- data/README.markdown +2 -0
- data/Rakefile +57 -15
- data/TODO.taskpaper +1 -1
- data/lib/MrMurano/Config.rb +10 -0
- data/lib/MrMurano/Mock.rb +63 -0
- data/lib/MrMurano/Product-1P-Device.rb +0 -17
- data/lib/MrMurano/Product-Resources.rb +1 -1
- data/lib/MrMurano/Product.rb +1 -1
- data/lib/MrMurano/Solution-Endpoint.rb +42 -12
- data/lib/MrMurano/Solution-File.rb +21 -14
- data/lib/MrMurano/Solution-ServiceConfig.rb +2 -1
- data/lib/MrMurano/Solution-Services.rb +18 -0
- data/lib/MrMurano/SyncUpDown.rb +17 -14
- data/lib/MrMurano/commands/gb.rb +33 -0
- data/lib/MrMurano/commands/mock.rb +63 -0
- data/lib/MrMurano/commands/productDeviceIdCmds.rb +10 -3
- data/lib/MrMurano/commands.rb +1 -0
- data/lib/MrMurano/template/mock.erb +9 -0
- data/lib/MrMurano/version.rb +1 -1
- data/lib/MrMurano.rb +0 -1
- data/spec/Config_spec.rb +14 -4
- data/spec/Mock_spec.rb +60 -0
- data/spec/ProductResources_spec.rb +1 -1
- data/spec/Solution-Endpoint_spec.rb +314 -0
- data/spec/cmd_common.rb +44 -0
- data/spec/cmd_config_spec.rb +2 -26
- data/spec/cmd_init_spec.rb +2 -26
- metadata +14 -2
@@ -7,15 +7,22 @@ command 'product device list' do |c|
|
|
7
7
|
|
8
8
|
c.option '--offset NUMBER', Integer, %{Offset to start listing at}
|
9
9
|
c.option '--limit NUMBER', Integer, %{How many devices to return}
|
10
|
+
c.option '-o', '--output FILE', %{Download to file instead of STDOUT}
|
10
11
|
|
11
12
|
c.action do |args,options|
|
12
13
|
options.default :offset=>0, :limit=>50
|
13
14
|
|
14
15
|
prd = MrMurano::Product.new
|
16
|
+
io=nil
|
17
|
+
io = File.open(options.output, 'w') if options.output
|
15
18
|
data = prd.list(options.offset, options.limit)
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
+
prd.outf(data, nil) do |dd,ios|
|
20
|
+
dt={}
|
21
|
+
dt[:headers] = [:SN, :Status, :RID]
|
22
|
+
dt[:rows] = data.map{|row| [row[:sn], row[:status], row[:rid]]}
|
23
|
+
prd.tabularize(dt, ios)
|
24
|
+
end
|
25
|
+
io.close unless io.nil?
|
19
26
|
end
|
20
27
|
end
|
21
28
|
|
data/lib/MrMurano/commands.rb
CHANGED
@@ -9,6 +9,7 @@ require 'MrMurano/commands/exportImport'
|
|
9
9
|
require 'MrMurano/commands/init'
|
10
10
|
require 'MrMurano/commands/keystore'
|
11
11
|
require 'MrMurano/commands/logs'
|
12
|
+
require 'MrMurano/commands/mock'
|
12
13
|
require 'MrMurano/commands/postgresql'
|
13
14
|
require 'MrMurano/commands/product'
|
14
15
|
require 'MrMurano/commands/productCreate'
|
@@ -0,0 +1,9 @@
|
|
1
|
+
--#ENDPOINT POST /testpoint/{service}/{call}
|
2
|
+
-- this function allows remote calls to your services
|
3
|
+
if request.headers["authorization"] == "<%= uuid %>" then
|
4
|
+
local fn = _G[request.parameters.service][request.parameters.call]
|
5
|
+
response.message = fn(request.body)
|
6
|
+
else
|
7
|
+
response.code = 401
|
8
|
+
response.message = "invalid authorization header"
|
9
|
+
end
|
data/lib/MrMurano/version.rb
CHANGED
data/lib/MrMurano.rb
CHANGED
data/spec/Config_spec.rb
CHANGED
@@ -246,6 +246,10 @@ bob = test
|
|
246
246
|
end
|
247
247
|
|
248
248
|
context "Can find the project directory by .mrmuranorc but not sub .git/" do
|
249
|
+
#
|
250
|
+
# /home/work/project/
|
251
|
+
# /home/work/project/.mrmuranorc
|
252
|
+
# /home/work/project/some/.git
|
249
253
|
before(:example) do
|
250
254
|
@tmpdir = Dir.tmpdir
|
251
255
|
path = '/home/work/project/some/where'
|
@@ -285,14 +289,17 @@ bob = test
|
|
285
289
|
end
|
286
290
|
end
|
287
291
|
|
288
|
-
context "Can find the project directory by .
|
292
|
+
context "Can find the project directory by .mrmuranorc but not parent .git/" do
|
293
|
+
# /home/work/project/
|
294
|
+
# /home/work/project/.git
|
295
|
+
# /home/work/project/some/.mrmuranorc
|
289
296
|
before(:example) do
|
290
297
|
@tmpdir = Dir.tmpdir
|
291
298
|
path = '/home/work/project/some/where'
|
292
299
|
@projectDir = @tmpdir + '/home/work/project'
|
293
300
|
FileUtils.mkpath(@tmpdir + path)
|
294
|
-
FileUtils.
|
295
|
-
FileUtils.mkpath(@projectDir + '
|
301
|
+
FileUtils.touch(@projectDir + '/some/.mrmuranorc')
|
302
|
+
FileUtils.mkpath(@projectDir + '/.git')
|
296
303
|
|
297
304
|
# Set ENV to override output of Dir.home
|
298
305
|
ENV['HOME'] = @tmpdir + '/home'
|
@@ -309,6 +316,8 @@ bob = test
|
|
309
316
|
# Follow symlinks to get the paths comparable.
|
310
317
|
locbase = cfg.get('location.base', :defaults).realdirpath
|
311
318
|
wkd = Pathname.new(@projectDir).realdirpath
|
319
|
+
# This will correctly assume that this project dir with .git is the
|
320
|
+
# location.base
|
312
321
|
expect(locbase).to eq(wkd)
|
313
322
|
end
|
314
323
|
end
|
@@ -319,11 +328,12 @@ bob = test
|
|
319
328
|
cfg.load
|
320
329
|
# Follow symlinks to get the paths comparable.
|
321
330
|
locbase = cfg.get('location.base', :defaults).realdirpath
|
322
|
-
wkd = Pathname.new(@projectDir).realdirpath
|
331
|
+
wkd = Pathname.new(@projectDir+'/some').realdirpath
|
323
332
|
expect(locbase).to eq(wkd)
|
324
333
|
end
|
325
334
|
end
|
326
335
|
end
|
336
|
+
|
327
337
|
end
|
328
338
|
|
329
339
|
# vim: set ai et sw=2 ts=2 :
|
data/spec/Mock_spec.rb
ADDED
@@ -0,0 +1,60 @@
|
|
1
|
+
require 'MrMurano/Mock'
|
2
|
+
require 'tempfile'
|
3
|
+
|
4
|
+
RSpec.describe MrMurano::Mock, "#mock" do
|
5
|
+
before(:example) do
|
6
|
+
@tmpdir = Dir.tmpdir
|
7
|
+
@projectDir = @tmpdir + '/home/work/project'
|
8
|
+
|
9
|
+
FileUtils.mkpath(@projectDir)
|
10
|
+
FileUtils.mkpath(@projectDir + '/endpoints')
|
11
|
+
Dir.chdir(@projectDir) do
|
12
|
+
$cfg = MrMurano::Config.new
|
13
|
+
$cfg.load
|
14
|
+
end
|
15
|
+
|
16
|
+
@mock = MrMurano::Mock.new
|
17
|
+
end
|
18
|
+
|
19
|
+
after(:example) do
|
20
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
21
|
+
end
|
22
|
+
|
23
|
+
it "can create the testpoint file" do
|
24
|
+
Dir.chdir(@projectDir) do
|
25
|
+
uuid = @mock.create_testpoint()
|
26
|
+
expect(uuid.length).to be("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX".length)
|
27
|
+
path = @mock.get_testpoint_path()
|
28
|
+
testpoint = File.read(path)
|
29
|
+
expect(testpoint.include? uuid).to be(true)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
it "can show the UUID from the testpoint file" do
|
34
|
+
Dir.chdir(@projectDir) do
|
35
|
+
uuid = @mock.create_testpoint()
|
36
|
+
retrieved_uuid = @mock.show()
|
37
|
+
expect(uuid).to eq(retrieved_uuid)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
|
41
|
+
it "can remove the testpoint file" do
|
42
|
+
Dir.chdir(@projectDir) do
|
43
|
+
@mock.create_testpoint()
|
44
|
+
path = @mock.get_testpoint_path()
|
45
|
+
removed = @mock.remove_testpoint()
|
46
|
+
expect(removed).to be(true)
|
47
|
+
expect(File.exist?(path)).to be(false)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
it "cannot show the UUID if there's no testpoint file" do
|
52
|
+
Dir.chdir(@projectDir) do
|
53
|
+
@mock.create_testpoint()
|
54
|
+
@mock.show()
|
55
|
+
@mock.remove_testpoint()
|
56
|
+
retrieved_uuid = @mock.show()
|
57
|
+
expect(retrieved_uuid).to be(false)
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
@@ -47,7 +47,7 @@ RSpec.describe MrMurano::ProductResources do
|
|
47
47
|
it "raises when no spec name" do
|
48
48
|
$cfg['product.spec'] = nil
|
49
49
|
$cfg['product.id'] = nil
|
50
|
-
expect { @prd.location }.to raise_error("No spec file named; run `mr config
|
50
|
+
expect { @prd.location }.to raise_error("No spec file named; run `mr config product.spec <specfile>`")
|
51
51
|
end
|
52
52
|
end
|
53
53
|
|
@@ -0,0 +1,314 @@
|
|
1
|
+
require 'MrMurano/version'
|
2
|
+
require 'MrMurano/Solution-Endpoint'
|
3
|
+
require 'tempfile'
|
4
|
+
|
5
|
+
RSpec.describe MrMurano::Endpoint 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::Endpoint.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/endpoint/")
|
19
|
+
end
|
20
|
+
|
21
|
+
context "lists" do
|
22
|
+
it "same content_type" do
|
23
|
+
body = [{:id=>"9K0",
|
24
|
+
:method=>"websocket",
|
25
|
+
:path=>"/api/v1/bar",
|
26
|
+
:content_type=>"application/json",
|
27
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n\n",
|
28
|
+
},
|
29
|
+
{:id=>"B76",
|
30
|
+
:method=>"websocket",
|
31
|
+
:path=>"/api/v1/foo/{id}",
|
32
|
+
:content_type=>"application/json",
|
33
|
+
:script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
|
34
|
+
}]
|
35
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
|
36
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
37
|
+
'Content-Type'=>'application/json'}).
|
38
|
+
to_return(body: body.to_json)
|
39
|
+
|
40
|
+
ret = @srv.list()
|
41
|
+
expect(ret).to eq(body)
|
42
|
+
end
|
43
|
+
|
44
|
+
it "missing headers" do
|
45
|
+
body = [{:id=>"9K0",
|
46
|
+
:method=>"websocket",
|
47
|
+
:path=>"/api/v1/bar",
|
48
|
+
:content_type=>"application/json",
|
49
|
+
:script=>"response.message = \"HI\"\n\n",
|
50
|
+
},
|
51
|
+
{:id=>"B76",
|
52
|
+
:method=>"websocket",
|
53
|
+
:path=>"/api/v1/foo/{id}",
|
54
|
+
:content_type=>"application/json",
|
55
|
+
:script=> "response.message = \"HI\"\n\n-- BOB WAS HERE\n",
|
56
|
+
}]
|
57
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
|
58
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
59
|
+
'Content-Type'=>'application/json'}).
|
60
|
+
to_return(body: body.to_json)
|
61
|
+
|
62
|
+
ret = @srv.list()
|
63
|
+
expect(ret).to eq(body)
|
64
|
+
end
|
65
|
+
|
66
|
+
it "not default content_type" do
|
67
|
+
body = [{:id=>"9K0",
|
68
|
+
:method=>"websocket",
|
69
|
+
:path=>"/api/v1/bar",
|
70
|
+
:content_type=>"text/csv",
|
71
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar text/csv\nresponse.message = \"HI\"\n\n",
|
72
|
+
},
|
73
|
+
{:id=>"B76",
|
74
|
+
:method=>"websocket",
|
75
|
+
:path=>"/api/v1/foo/{id}",
|
76
|
+
:content_type=>"image/png",
|
77
|
+
:script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id} image/png\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
|
78
|
+
}]
|
79
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
|
80
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
81
|
+
'Content-Type'=>'application/json'}).
|
82
|
+
to_return(body: body.to_json)
|
83
|
+
|
84
|
+
ret = @srv.list()
|
85
|
+
expect(ret).to eq(body)
|
86
|
+
end
|
87
|
+
|
88
|
+
it "mismatched content_type header" do
|
89
|
+
body = [{:id=>"9K0",
|
90
|
+
:method=>"websocket",
|
91
|
+
:path=>"/api/v1/bar",
|
92
|
+
:content_type=>"text/csv",
|
93
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n\n",
|
94
|
+
},
|
95
|
+
{:id=>"B76",
|
96
|
+
:method=>"websocket",
|
97
|
+
:path=>"/api/v1/foo/{id}",
|
98
|
+
:content_type=>"image/png",
|
99
|
+
:script=> "--#ENDPOINT WEBSOCKET /api/v1/foo/{id}\nresponse.message = \"HI\"\n\n-- BOB WAS HERE\n",
|
100
|
+
}]
|
101
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint").
|
102
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
103
|
+
'Content-Type'=>'application/json'}).
|
104
|
+
to_return(body: body.to_json)
|
105
|
+
|
106
|
+
ret = @srv.list()
|
107
|
+
expect(ret).to eq(body)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
|
113
|
+
context "fetches" do
|
114
|
+
it "fetches" do
|
115
|
+
body = {:id=>"9K0",
|
116
|
+
:method=>"websocket",
|
117
|
+
:path=>"/api/v1/bar",
|
118
|
+
:content_type=>"application/json",
|
119
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
|
120
|
+
}
|
121
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
122
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
123
|
+
'Content-Type'=>'application/json'}).
|
124
|
+
to_return(body: body.to_json)
|
125
|
+
|
126
|
+
ret = @srv.fetch('9K0')
|
127
|
+
expect(ret).to eq(body[:script])
|
128
|
+
end
|
129
|
+
|
130
|
+
it "missing headers" do
|
131
|
+
body = {:id=>"9K0",
|
132
|
+
:method=>"websocket",
|
133
|
+
:path=>"/api/v1/bar",
|
134
|
+
:content_type=>"application/json",
|
135
|
+
:script=>"response.message = \"HI\"\n",
|
136
|
+
}
|
137
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
138
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
139
|
+
'Content-Type'=>'application/json'}).
|
140
|
+
to_return(body: body.to_json)
|
141
|
+
|
142
|
+
ret = @srv.fetch('9K0')
|
143
|
+
expect(ret).to eq("--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n")
|
144
|
+
end
|
145
|
+
|
146
|
+
it "not default content_type" do
|
147
|
+
body = {:id=>"9K0",
|
148
|
+
:method=>"websocket",
|
149
|
+
:path=>"/api/v1/bar",
|
150
|
+
:content_type=>"text/csv",
|
151
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar text/csv\nresponse.message = \"HI\"\n",
|
152
|
+
}
|
153
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
154
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
155
|
+
'Content-Type'=>'application/json'}).
|
156
|
+
to_return(body: body.to_json)
|
157
|
+
|
158
|
+
ret = @srv.fetch('9K0')
|
159
|
+
expect(ret).to eq(body[:script])
|
160
|
+
end
|
161
|
+
|
162
|
+
it "missing content_type header" do
|
163
|
+
body = {:id=>"9K0",
|
164
|
+
:method=>"websocket",
|
165
|
+
:path=>"/api/v1/bar",
|
166
|
+
:content_type=>"text/csv",
|
167
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
|
168
|
+
}
|
169
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
170
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
171
|
+
'Content-Type'=>'application/json'}).
|
172
|
+
to_return(body: body.to_json)
|
173
|
+
|
174
|
+
ret = @srv.fetch('9K0')
|
175
|
+
expect(ret).to eq("--#ENDPOINT WEBSOCKET /api/v1/bar text/csv\nresponse.message = \"HI\"\n")
|
176
|
+
end
|
177
|
+
|
178
|
+
it "mismatched content_type header" do
|
179
|
+
body = {:id=>"9K0",
|
180
|
+
:method=>"websocket",
|
181
|
+
:path=>"/api/v1/bar",
|
182
|
+
:content_type=>"text/csv",
|
183
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar image/png\nresponse.message = \"HI\"\n",
|
184
|
+
}
|
185
|
+
stub_request(:get, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
186
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
187
|
+
'Content-Type'=>'application/json'}).
|
188
|
+
to_return(body: body.to_json)
|
189
|
+
|
190
|
+
ret = @srv.fetch('9K0')
|
191
|
+
expect(ret).to eq("--#ENDPOINT WEBSOCKET /api/v1/bar text/csv\nresponse.message = \"HI\"\n")
|
192
|
+
end
|
193
|
+
end
|
194
|
+
|
195
|
+
it "removes" do
|
196
|
+
stub_request(:delete, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
197
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
198
|
+
'Content-Type'=>'application/json'}).
|
199
|
+
to_return(body: "")
|
200
|
+
|
201
|
+
ret = @srv.remove('9K0')
|
202
|
+
expect(ret).to eq({})
|
203
|
+
end
|
204
|
+
|
205
|
+
it "uploads over old version" do
|
206
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
207
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
208
|
+
'Content-Type'=>'application/json'}).
|
209
|
+
to_return(body: "")
|
210
|
+
|
211
|
+
Tempfile.open('foo') do |tio|
|
212
|
+
tio << %{-- lua code is here
|
213
|
+
function foo(bar)
|
214
|
+
return bar + 1
|
215
|
+
end
|
216
|
+
}
|
217
|
+
tio.close
|
218
|
+
|
219
|
+
ret = @srv.upload(tio.path, {:id=>"9K0",
|
220
|
+
:method=>"websocket",
|
221
|
+
:path=>"/api/v1/bar",
|
222
|
+
:content_type=>"application/json",
|
223
|
+
}, true)
|
224
|
+
expect(ret)
|
225
|
+
end
|
226
|
+
end
|
227
|
+
|
228
|
+
it "uploads when nothing is there" do
|
229
|
+
stub_request(:put, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/9K0").
|
230
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
231
|
+
'Content-Type'=>'application/json'}).
|
232
|
+
to_return(status: 404)
|
233
|
+
stub_request(:post, "https://bizapi.hosted.exosite.io/api:1/solution/XYZ/endpoint/").
|
234
|
+
with(:headers=>{'Authorization'=>'token TTTTTTTTTT',
|
235
|
+
'Content-Type'=>'application/json'}).
|
236
|
+
to_return(body: "")
|
237
|
+
|
238
|
+
Tempfile.open('foo') do |tio|
|
239
|
+
tio << %{-- lua code is here
|
240
|
+
function foo(bar)
|
241
|
+
return bar + 1
|
242
|
+
end
|
243
|
+
}
|
244
|
+
tio.close
|
245
|
+
|
246
|
+
ret = @srv.upload(tio.path, {:id=>"9K0",
|
247
|
+
:method=>"websocket",
|
248
|
+
:path=>"/api/v1/bar",
|
249
|
+
:content_type=>"application/json",
|
250
|
+
}, false)
|
251
|
+
expect(ret)
|
252
|
+
end
|
253
|
+
|
254
|
+
end
|
255
|
+
|
256
|
+
context "compares" do
|
257
|
+
before(:example) do
|
258
|
+
@iA = {:id=>"9K0",
|
259
|
+
:method=>"websocket",
|
260
|
+
:path=>"/api/v1/bar",
|
261
|
+
:content_type=>"application/json",
|
262
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
|
263
|
+
}
|
264
|
+
@iB = {:id=>"9K0",
|
265
|
+
:method=>"websocket",
|
266
|
+
:path=>"/api/v1/bar",
|
267
|
+
:content_type=>"application/json",
|
268
|
+
:script=>"--#ENDPOINT WEBSOCKET /api/v1/bar\nresponse.message = \"HI\"\n",
|
269
|
+
}
|
270
|
+
end
|
271
|
+
it "both have script" do
|
272
|
+
ret = @srv.docmp(@iA, @iB)
|
273
|
+
expect(ret).to eq(false)
|
274
|
+
end
|
275
|
+
|
276
|
+
it "iA is a local file" do
|
277
|
+
Tempfile.open('foo') do |tio|
|
278
|
+
tio << @iA[:script]
|
279
|
+
tio.close
|
280
|
+
iA = @iA.reject{|k,v| k == :script}.merge({
|
281
|
+
:local_path => Pathname.new(tio.path)
|
282
|
+
})
|
283
|
+
ret = @srv.docmp(iA, @iB)
|
284
|
+
expect(ret).to eq(false)
|
285
|
+
|
286
|
+
iB = @iB.dup
|
287
|
+
iB[:script] = "BOB"
|
288
|
+
ret = @srv.docmp(iA, iB)
|
289
|
+
expect(ret).to eq(true)
|
290
|
+
end
|
291
|
+
end
|
292
|
+
|
293
|
+
it "iB is a local file" do
|
294
|
+
Tempfile.open('foo') do |tio|
|
295
|
+
tio << @iB[:script]
|
296
|
+
tio.close
|
297
|
+
iB = @iB.reject{|k,v| k == :script}.merge({
|
298
|
+
:local_path => Pathname.new(tio.path)
|
299
|
+
})
|
300
|
+
ret = @srv.docmp(@iA, iB)
|
301
|
+
expect(ret).to eq(false)
|
302
|
+
|
303
|
+
iA = @iB.dup
|
304
|
+
iA[:script] = "BOB"
|
305
|
+
ret = @srv.docmp(iA, iB)
|
306
|
+
expect(ret).to eq(true)
|
307
|
+
end
|
308
|
+
end
|
309
|
+
end
|
310
|
+
|
311
|
+
# TODO: status tests
|
312
|
+
|
313
|
+
end
|
314
|
+
# vim: set ai et sw=2 ts=2 :
|
data/spec/cmd_common.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'shellwords'
|
3
|
+
require 'timeout'
|
4
|
+
require 'tmpdir'
|
5
|
+
|
6
|
+
RSpec.shared_context "CI_CMD" do
|
7
|
+
def capcmd(*args)
|
8
|
+
args = [args] unless args.kind_of? Array
|
9
|
+
args.flatten!
|
10
|
+
testdir = File.realpath(@testdir.to_s)
|
11
|
+
if ENV['CI_MR_EXE'].nil? then
|
12
|
+
args[0] = File.join(testdir, 'bin', args[0])
|
13
|
+
args.unshift("ruby", "-I#{File.join(testdir, 'lib')}")
|
14
|
+
else
|
15
|
+
args[0] = File.join(testdir, (args[0] + '.exe'))
|
16
|
+
end
|
17
|
+
|
18
|
+
if Gem.win_platform? then
|
19
|
+
cmd = args.map{|i| if i =~ / / then %{"#{i}"} else i end}.join(' ')
|
20
|
+
else
|
21
|
+
cmd = Shellwords.join(args)
|
22
|
+
end
|
23
|
+
#pp cmd
|
24
|
+
cmd
|
25
|
+
end
|
26
|
+
|
27
|
+
around(:example) do |ex|
|
28
|
+
@testdir = Pathname.new(Dir.pwd).realpath
|
29
|
+
Dir.mktmpdir do |hdir|
|
30
|
+
ENV['HOME'] = hdir
|
31
|
+
Dir.chdir(hdir) do
|
32
|
+
@tmpdir = File.join(hdir, 'project')
|
33
|
+
Dir.mkdir(@tmpdir)
|
34
|
+
Dir.chdir(@tmpdir) do
|
35
|
+
Timeout::timeout(20) do
|
36
|
+
ex.run
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
# vim: set ai et sw=2 ts=2 :
|
data/spec/cmd_config_spec.rb
CHANGED
@@ -1,34 +1,10 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'open3'
|
3
3
|
require 'pathname'
|
4
|
-
require '
|
5
|
-
require 'tmpdir'
|
4
|
+
require 'cmd_common'
|
6
5
|
|
7
6
|
RSpec.describe 'mr config' do
|
8
|
-
|
9
|
-
def capcmd(*args)
|
10
|
-
args = [args] unless args.kind_of? Array
|
11
|
-
args.flatten!
|
12
|
-
args[0] = @testdir + 'bin' + args[0]
|
13
|
-
args.unshift("ruby", "-I#{(@testdir+'lib').to_s}")
|
14
|
-
cmd = Shellwords.join(args)
|
15
|
-
#pp cmd
|
16
|
-
cmd
|
17
|
-
end
|
18
|
-
|
19
|
-
around(:example) do |ex|
|
20
|
-
@testdir = Pathname.new(Dir.pwd).realpath
|
21
|
-
Dir.mktmpdir do |hdir|
|
22
|
-
ENV['HOME'] = hdir
|
23
|
-
Dir.chdir(hdir) do
|
24
|
-
@tmpdir = File.join(hdir, 'project')
|
25
|
-
Dir.mkdir(@tmpdir)
|
26
|
-
Dir.chdir(@tmpdir) do
|
27
|
-
ex.run
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
7
|
+
include_context "CI_CMD"
|
32
8
|
|
33
9
|
it "Needs a key" do
|
34
10
|
out, err, status = Open3.capture3(capcmd('mr', "config"))
|
data/spec/cmd_init_spec.rb
CHANGED
@@ -1,34 +1,10 @@
|
|
1
1
|
require 'fileutils'
|
2
2
|
require 'open3'
|
3
3
|
require 'pathname'
|
4
|
-
require '
|
5
|
-
require 'tmpdir'
|
4
|
+
require 'cmd_common'
|
6
5
|
|
7
6
|
RSpec.describe 'mr init' do
|
8
|
-
|
9
|
-
def capcmd(*args)
|
10
|
-
args = [args] unless args.kind_of? Array
|
11
|
-
args.flatten!
|
12
|
-
args[0] = @testdir + 'bin' + args[0]
|
13
|
-
args.unshift("ruby", "-I#{(@testdir+'lib').to_s}")
|
14
|
-
cmd = Shellwords.join(args)
|
15
|
-
#pp cmd
|
16
|
-
cmd
|
17
|
-
end
|
18
|
-
|
19
|
-
around(:example) do |ex|
|
20
|
-
@testdir = Pathname.new(Dir.pwd).realpath
|
21
|
-
Dir.mktmpdir do |hdir|
|
22
|
-
ENV['HOME'] = hdir
|
23
|
-
Dir.chdir(hdir) do
|
24
|
-
@tmpdir = File.join(hdir, 'project')
|
25
|
-
Dir.mkdir(@tmpdir)
|
26
|
-
Dir.chdir(@tmpdir) do
|
27
|
-
ex.run
|
28
|
-
end
|
29
|
-
end
|
30
|
-
end
|
31
|
-
end
|
7
|
+
include_context "CI_CMD"
|
32
8
|
|
33
9
|
it "Won't init in HOME (gracefully)" do
|
34
10
|
# this is in the project dir. Want to be in HOME
|