MrMurano 1.11.3 → 1.12.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 +2 -0
- data/README.markdown +12 -14
- data/Rakefile +2 -2
- data/TODO.taskpaper +8 -6
- data/docs/demo.md +109 -0
- data/lib/MrMurano/Account.rb +6 -3
- data/lib/MrMurano/Config.rb +13 -37
- data/lib/MrMurano/Product-1P-Device.rb +2 -0
- data/lib/MrMurano/Product-Resources.rb +5 -4
- data/lib/MrMurano/Product.rb +3 -3
- data/lib/MrMurano/Solution-File.rb +1 -2
- data/lib/MrMurano/Solution-ServiceConfig.rb +11 -1
- data/lib/MrMurano/Solution-Services.rb +24 -7
- data/lib/MrMurano/Solution-Users.rb +6 -4
- data/lib/MrMurano/SyncUpDown.rb +67 -28
- data/lib/MrMurano/commands/config.rb +4 -1
- data/lib/MrMurano/commands/exportImport.rb +3 -0
- data/lib/MrMurano/hash.rb +2 -0
- data/lib/MrMurano/http.rb +3 -3
- data/lib/MrMurano/verbosing.rb +9 -3
- data/lib/MrMurano/version.rb +1 -1
- data/spec/Account_spec.rb +104 -0
- data/spec/Config_spec.rb +202 -57
- data/spec/Http_spec.rb +204 -0
- data/spec/MakePretties_spec.rb +35 -0
- data/spec/Mock_spec.rb +13 -20
- data/spec/ProductBase_spec.rb +2 -0
- data/spec/ProductContent_spec.rb +77 -12
- data/spec/ProductResources_spec.rb +235 -0
- data/spec/Product_1P_Device_spec.rb +62 -0
- data/spec/Product_1P_RPC_spec.rb +2 -0
- data/spec/Product_spec.rb +18 -8
- data/spec/Solution-Cors_spec.rb +28 -1
- data/spec/Solution-Endpoint_spec.rb +250 -33
- data/spec/Solution-File_spec.rb +210 -0
- data/spec/Solution-ServiceConfig_spec.rb +2 -0
- data/spec/Solution-ServiceDevice_spec.rb +174 -0
- data/spec/Solution-ServiceEventHandler_spec.rb +134 -1
- data/spec/Solution-ServiceModules_spec.rb +317 -64
- data/spec/Solution-UsersRoles_spec.rb +207 -0
- data/spec/Solution_spec.rb +90 -0
- data/spec/SyncRoot_spec.rb +52 -46
- data/spec/SyncUpDown_spec.rb +364 -0
- data/spec/Verbosing_spec.rb +279 -0
- data/spec/_workspace.rb +27 -0
- data/spec/fixtures/dumped_config +47 -0
- data/spec/fixtures/product_spec_files/lightbulb-no-state.yaml +11 -0
- data/spec/fixtures/product_spec_files/lightbulb.yaml +2 -0
- data/spec/fixtures/roles-three.yaml +11 -0
- data/spec/spec_helper.rb +9 -0
- metadata +26 -2
data/spec/Config_spec.rb
CHANGED
@@ -1,82 +1,93 @@
|
|
1
1
|
require 'MrMurano/version'
|
2
2
|
require 'MrMurano/Config'
|
3
|
+
require '_workspace'
|
3
4
|
require 'tempfile'
|
5
|
+
require 'erb'
|
4
6
|
|
5
7
|
RSpec.describe MrMurano::Config do
|
8
|
+
|
6
9
|
context "Basics " do
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
#
|
12
|
-
|
10
|
+
include_context "WORKSPACE"
|
11
|
+
it "Sets defaults" do
|
12
|
+
cfg = MrMurano::Config.new
|
13
|
+
cfg.load
|
14
|
+
# Don't check for all of them, just a few.
|
15
|
+
expect(cfg['files.default_page']).to eq('index.html')
|
16
|
+
expect(cfg.get('files.default_page', :defaults)).to eq('index.html')
|
17
|
+
expect(cfg['tool.debug']).to eq(false)
|
18
|
+
expect(cfg.get('tool.debug', :defaults)).to eq(false)
|
13
19
|
end
|
14
20
|
|
15
|
-
|
16
|
-
|
17
|
-
|
21
|
+
it "Sets internal values" do
|
22
|
+
cfg = MrMurano::Config.new
|
23
|
+
cfg.load
|
18
24
|
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
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
|
25
|
+
cfg['bob.test'] = 'twelve'
|
26
|
+
|
27
|
+
expect(cfg['bob.test']).to eq('twelve')
|
28
|
+
expect(cfg.get('bob.test', :internal)).to eq('twelve')
|
29
29
|
end
|
30
30
|
|
31
|
-
it "Sets
|
32
|
-
|
33
|
-
|
34
|
-
cfg.load
|
31
|
+
it "Sets tool values" do
|
32
|
+
cfg = MrMurano::Config.new
|
33
|
+
cfg.load
|
35
34
|
|
36
|
-
|
35
|
+
cfg['test'] = 'twelve'
|
37
36
|
|
38
|
-
|
39
|
-
|
40
|
-
end
|
37
|
+
expect(cfg['tool.test']).to eq('twelve')
|
38
|
+
expect(cfg.get('tool.test', :internal)).to eq('twelve')
|
41
39
|
end
|
42
40
|
|
43
41
|
it "Sets project values" do # This should write
|
44
|
-
|
45
|
-
|
46
|
-
cfg.load
|
42
|
+
cfg = MrMurano::Config.new
|
43
|
+
cfg.load
|
47
44
|
|
48
|
-
|
45
|
+
cfg.set('bob.test', 'twelve', :project)
|
49
46
|
|
50
|
-
|
51
|
-
|
47
|
+
expect(cfg['bob.test']).to eq('twelve')
|
48
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
52
49
|
|
53
|
-
|
50
|
+
expect(FileTest.exist?(@projectDir + '.mrmuranorc'))
|
54
51
|
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
end
|
52
|
+
#reload
|
53
|
+
cfg = MrMurano::Config.new
|
54
|
+
cfg.load
|
55
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
60
56
|
end
|
61
57
|
|
62
|
-
it "
|
63
|
-
|
64
|
-
|
65
|
-
io << %{[test]
|
66
|
-
bob = test
|
67
|
-
}
|
68
|
-
end
|
58
|
+
it "Sets a user value" do
|
59
|
+
cfg = MrMurano::Config.new
|
60
|
+
cfg.load
|
69
61
|
|
70
|
-
|
71
|
-
cfg.load
|
72
|
-
cfg.load_specific(@projectDir + '/foo.cfg')
|
62
|
+
cfg.set('bob.test', 'twelve', :user)
|
73
63
|
|
74
|
-
|
64
|
+
expect(cfg['bob.test']).to eq('twelve')
|
65
|
+
expect(cfg.get('bob.test', :user)).to eq('twelve')
|
66
|
+
|
67
|
+
expect(FileTest.exist?(ENV['HOME'] + '.mrmuranorc'))
|
68
|
+
|
69
|
+
#reload
|
70
|
+
cfg = MrMurano::Config.new
|
71
|
+
cfg.load
|
72
|
+
expect(cfg.get('bob.test', :user)).to eq('twelve')
|
73
|
+
end
|
74
|
+
|
75
|
+
it "loads from a specific file" do
|
76
|
+
File.open(@projectDir + '/foo.cfg', 'w') do |io|
|
77
|
+
io << %{[test]
|
78
|
+
bob = test
|
79
|
+
}.gsub(/^\s\+/,'')
|
75
80
|
end
|
81
|
+
|
82
|
+
cfg = MrMurano::Config.new
|
83
|
+
cfg.load
|
84
|
+
cfg.load_specific(@projectDir + '/foo.cfg')
|
85
|
+
|
86
|
+
expect(cfg['test.bob']).to eq('test')
|
76
87
|
end
|
77
88
|
|
78
|
-
|
79
|
-
|
89
|
+
context "returns a path to a file in" do
|
90
|
+
it "project mrmurano dir" do
|
80
91
|
cfg = MrMurano::Config.new
|
81
92
|
cfg.load
|
82
93
|
path = cfg.file_at('testfile').realdirpath
|
@@ -84,10 +95,8 @@ bob = test
|
|
84
95
|
|
85
96
|
expect(path).to eq(want)
|
86
97
|
end
|
87
|
-
end
|
88
98
|
|
89
|
-
|
90
|
-
Dir.chdir(@projectDir) do
|
99
|
+
it "user mrmurano dir" do
|
91
100
|
cfg = MrMurano::Config.new
|
92
101
|
cfg.load
|
93
102
|
path = cfg.file_at('testfile', :user).realdirpath
|
@@ -95,6 +104,30 @@ bob = test
|
|
95
104
|
|
96
105
|
expect(path).to eq(want)
|
97
106
|
end
|
107
|
+
|
108
|
+
it "internal" do
|
109
|
+
cfg = MrMurano::Config.new
|
110
|
+
cfg.load
|
111
|
+
path = cfg.file_at('testfile', :internal)
|
112
|
+
|
113
|
+
expect(path).to eq(nil)
|
114
|
+
end
|
115
|
+
|
116
|
+
it "specified" do
|
117
|
+
cfg = MrMurano::Config.new
|
118
|
+
cfg.load
|
119
|
+
path = cfg.file_at('testfile', :specified)
|
120
|
+
|
121
|
+
expect(path).to eq(nil)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "defaults" do
|
125
|
+
cfg = MrMurano::Config.new
|
126
|
+
cfg.load
|
127
|
+
path = cfg.file_at('testfile', :defaults)
|
128
|
+
|
129
|
+
expect(path).to eq(nil)
|
130
|
+
end
|
98
131
|
end
|
99
132
|
|
100
133
|
context "ENV['MR_CONFIGFILE']" do
|
@@ -102,8 +135,8 @@ bob = test
|
|
102
135
|
ENV['MR_CONFIGFILE'] = @tmpdir + '/home/test.config'
|
103
136
|
File.open(@tmpdir + '/home/test.config', 'w') do |io|
|
104
137
|
io << %{[test]
|
105
|
-
bob = test
|
106
|
-
}
|
138
|
+
bob = test
|
139
|
+
}.gsub(/^\s\+/,'')
|
107
140
|
end
|
108
141
|
|
109
142
|
cfg = MrMurano::Config.new
|
@@ -126,6 +159,47 @@ bob = test
|
|
126
159
|
expect(cfg.get('coffee.hot', :env)).to eq('yes')
|
127
160
|
end
|
128
161
|
end
|
162
|
+
|
163
|
+
it "dumps" do
|
164
|
+
cfg = MrMurano::Config.new
|
165
|
+
cfg.load
|
166
|
+
cfg['sync.bydefault'] = 'files'
|
167
|
+
ret = cfg.dump
|
168
|
+
|
169
|
+
rawwant = IO.read(File.join(@testdir.to_path, 'spec','fixtures','dumped_config'))
|
170
|
+
template = ERB.new(rawwant)
|
171
|
+
want = template.result(binding)
|
172
|
+
|
173
|
+
expect(ret).to eq(want)
|
174
|
+
end
|
175
|
+
|
176
|
+
context "fixing permissions" do
|
177
|
+
it "fixes a directory" do
|
178
|
+
Dir.mkdir('test')
|
179
|
+
cfg = MrMurano::Config.new
|
180
|
+
cfg.fixModes(Pathname.new('test'))
|
181
|
+
if Gem.win_platform? then
|
182
|
+
expect(FileTest.world_readable? 'test').to eq(493)
|
183
|
+
expect(FileTest.world_writable? 'test').to be_nil
|
184
|
+
else
|
185
|
+
expect(FileTest.world_readable? 'test').to be_nil
|
186
|
+
expect(FileTest.world_writable? 'test').to be_nil
|
187
|
+
end
|
188
|
+
end
|
189
|
+
|
190
|
+
it "fixes a file" do
|
191
|
+
FileUtils.touch('test')
|
192
|
+
cfg = MrMurano::Config.new
|
193
|
+
cfg.fixModes(Pathname.new('test'))
|
194
|
+
if Gem.win_platform? then
|
195
|
+
expect(FileTest.world_readable? 'test').to eq(420)
|
196
|
+
expect(FileTest.world_writable? 'test').to be_nil
|
197
|
+
else
|
198
|
+
expect(FileTest.world_readable? 'test').to be_nil
|
199
|
+
expect(FileTest.world_writable? 'test').to be_nil
|
200
|
+
end
|
201
|
+
end
|
202
|
+
end
|
129
203
|
end
|
130
204
|
|
131
205
|
context "Can find the project directory by .mrmuranorc" do
|
@@ -334,6 +408,77 @@ bob = test
|
|
334
408
|
end
|
335
409
|
end
|
336
410
|
|
411
|
+
context "When pwd is $HOME:" do
|
412
|
+
before(:example) do
|
413
|
+
@tmpdir = Dir.tmpdir
|
414
|
+
@projectDir = @tmpdir + '/home/work/project'
|
415
|
+
FileUtils.mkpath(@projectDir)
|
416
|
+
# Set ENV to override output of Dir.home
|
417
|
+
ENV['HOME'] = @tmpdir + '/home'
|
418
|
+
end
|
419
|
+
|
420
|
+
after(:example) do
|
421
|
+
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
422
|
+
end
|
423
|
+
|
424
|
+
it "Sets a user value" do
|
425
|
+
Dir.chdir(ENV['HOME']) do
|
426
|
+
cfg = MrMurano::Config.new
|
427
|
+
cfg.load
|
428
|
+
|
429
|
+
cfg.set('bob.test', 'twelve', :user)
|
430
|
+
|
431
|
+
expect(cfg['bob.test']).to eq('twelve')
|
432
|
+
expect(cfg.get('bob.test', :user)).to eq('twelve')
|
433
|
+
|
434
|
+
expect(FileTest.exist?(ENV['HOME'] + '.mrmuranorc'))
|
435
|
+
|
436
|
+
#reload
|
437
|
+
cfg = MrMurano::Config.new
|
438
|
+
cfg.load
|
439
|
+
expect(cfg.get('bob.test', :user)).to eq('twelve')
|
440
|
+
end
|
441
|
+
end
|
442
|
+
|
443
|
+
it "Sets project values" do # This should write
|
444
|
+
Dir.chdir(ENV['HOME']) do
|
445
|
+
cfg = MrMurano::Config.new
|
446
|
+
cfg.load
|
447
|
+
|
448
|
+
cfg.set('bob.test', 'twelve', :project)
|
449
|
+
|
450
|
+
expect(cfg['bob.test']).to eq('twelve')
|
451
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
452
|
+
|
453
|
+
expect(FileTest.exist?(ENV['HOME'] + '.mrmuranorc'))
|
454
|
+
|
455
|
+
#reload
|
456
|
+
cfg = MrMurano::Config.new
|
457
|
+
cfg.load
|
458
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
459
|
+
end
|
460
|
+
end
|
461
|
+
|
462
|
+
it "write a project value and reads it as a user value" do
|
463
|
+
Dir.chdir(ENV['HOME']) do
|
464
|
+
cfg = MrMurano::Config.new
|
465
|
+
cfg.load
|
466
|
+
|
467
|
+
cfg.set('bob.test', 'twelve', :project)
|
468
|
+
|
469
|
+
expect(cfg['bob.test']).to eq('twelve')
|
470
|
+
# :user won't have the new value until it is loaded again
|
471
|
+
expect(cfg.get('bob.test', :project)).to eq('twelve')
|
472
|
+
|
473
|
+
expect(FileTest.exist?(ENV['HOME'] + '.mrmuranorc'))
|
474
|
+
|
475
|
+
#reload
|
476
|
+
cfg = MrMurano::Config.new
|
477
|
+
cfg.load
|
478
|
+
expect(cfg.get('bob.test', :user)).to eq('twelve')
|
479
|
+
end
|
480
|
+
end
|
481
|
+
end
|
337
482
|
end
|
338
483
|
|
339
484
|
# vim: set ai et sw=2 ts=2 :
|
data/spec/Http_spec.rb
ADDED
@@ -0,0 +1,204 @@
|
|
1
|
+
require 'MrMurano/version'
|
2
|
+
require 'MrMurano/http'
|
3
|
+
require 'MrMurano/verbosing'
|
4
|
+
require 'MrMurano/Account'
|
5
|
+
require '_workspace'
|
6
|
+
|
7
|
+
class Tst
|
8
|
+
include MrMurano::Verbose
|
9
|
+
include MrMurano::Http
|
10
|
+
def initialize
|
11
|
+
@token = nil
|
12
|
+
end
|
13
|
+
end
|
14
|
+
RSpec.describe MrMurano::Http do
|
15
|
+
include_context "WORKSPACE"
|
16
|
+
|
17
|
+
before(:example) do
|
18
|
+
$cfg = MrMurano::Config.new
|
19
|
+
$cfg.load
|
20
|
+
@tst = Tst.new
|
21
|
+
end
|
22
|
+
|
23
|
+
context "gets a token" do
|
24
|
+
before(:example) do
|
25
|
+
@acc = instance_double("MrMurano::Account")
|
26
|
+
allow(MrMurano::Account).to receive(:new).and_return(@acc)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "already has one" do
|
30
|
+
@tst.instance_variable_set(:@token, "ABCDEFG")
|
31
|
+
ret = @tst.token
|
32
|
+
expect(ret).to eq("ABCDEFG")
|
33
|
+
end
|
34
|
+
|
35
|
+
it "gets one" do
|
36
|
+
expect(@acc).to receive(:token).and_return("ABCDEFG")
|
37
|
+
ret = @tst.token
|
38
|
+
expect(ret).to eq("ABCDEFG")
|
39
|
+
end
|
40
|
+
|
41
|
+
it "raises when no logged in" do
|
42
|
+
expect(@acc).to receive(:token).and_return(nil)
|
43
|
+
expect {
|
44
|
+
@tst.token
|
45
|
+
}.to raise_error "Not logged in!"
|
46
|
+
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
context "puts curl request" do
|
51
|
+
before(:example) do
|
52
|
+
@req = Net::HTTP::Get.new URI("https://test.host/this/is/a/test")
|
53
|
+
@req.content_type = 'application/json'
|
54
|
+
@req['User-Agent'] = 'test'
|
55
|
+
end
|
56
|
+
it "puts nothing" do
|
57
|
+
$cfg['tool.curldebug'] = false
|
58
|
+
$stdout = StringIO.new
|
59
|
+
@tst.curldebug(@req)
|
60
|
+
expect($stdout.string).to eq("")
|
61
|
+
end
|
62
|
+
|
63
|
+
it "puts something" do
|
64
|
+
$cfg['tool.curldebug'] = true
|
65
|
+
$stdout = StringIO.new
|
66
|
+
@tst.curldebug(@req)
|
67
|
+
expect($stdout.string).to eq(%{curl -s -H 'User-Agent: test' -H 'Content-Type: application/json' -X GET 'https://test.host/this/is/a/test'\n})
|
68
|
+
end
|
69
|
+
|
70
|
+
it "puts something with Auth" do
|
71
|
+
$cfg['tool.curldebug'] = true
|
72
|
+
$stdout = StringIO.new
|
73
|
+
@req['Authorization'] = 'LetMeIn'
|
74
|
+
@tst.curldebug(@req)
|
75
|
+
expect($stdout.string).to eq(%{curl -s -H 'Authorization: LetMeIn' -H 'User-Agent: test' -H 'Content-Type: application/json' -X GET 'https://test.host/this/is/a/test'\n})
|
76
|
+
end
|
77
|
+
|
78
|
+
it "puts something with Body" do
|
79
|
+
$cfg['tool.curldebug'] = true
|
80
|
+
$stdout = StringIO.new
|
81
|
+
@req.body = "builder"
|
82
|
+
@tst.curldebug(@req)
|
83
|
+
expect($stdout.string).to eq(%{curl -s -H 'User-Agent: test' -H 'Content-Type: application/json' -X GET 'https://test.host/this/is/a/test' -d 'builder'\n})
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "checks if JSON" do
|
88
|
+
it "is JSON" do
|
89
|
+
ok, data = @tst.isJSON(%{{"one": "two", "three":[1,2,3,4,5,6]}})
|
90
|
+
expect(ok).to be true
|
91
|
+
expect(data).to eq({
|
92
|
+
:one=>'two',
|
93
|
+
:three=>[1,2,3,4,5,6]
|
94
|
+
})
|
95
|
+
end
|
96
|
+
it "is not JSON" do
|
97
|
+
ok, data = @tst.isJSON(%{woeiutepoxam})
|
98
|
+
expect(ok).to be false
|
99
|
+
expect(data).to eq('woeiutepoxam')
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
context "shows HTTP errors" do
|
104
|
+
before(:example) do
|
105
|
+
@req = Net::HTTP::Get.new URI("https://test.host/this/is/a/test")
|
106
|
+
@req.content_type = 'application/json'
|
107
|
+
@req['User-Agent'] = 'test'
|
108
|
+
@rsp = Net::HTTPGone.new('1.1', 410, 'ok')
|
109
|
+
end
|
110
|
+
|
111
|
+
it "shows debug details" do
|
112
|
+
$cfg['tool.debug'] = true
|
113
|
+
$stdout = StringIO.new
|
114
|
+
$stderr = StringIO.new
|
115
|
+
|
116
|
+
allow(@rsp).to receive(:body).and_return("ok")
|
117
|
+
expect(@tst).to receive(:error).once.with('Request Failed: 410: ok')
|
118
|
+
|
119
|
+
@tst.showHttpError(@req, @rsp)
|
120
|
+
expect($stdout.string).to eq(%{Sent GET https://test.host/this/is/a/test
|
121
|
+
> Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
122
|
+
> Accept: */*
|
123
|
+
> User-Agent: test
|
124
|
+
> Host: test.host
|
125
|
+
> Content-Type: application/json
|
126
|
+
Got 410 ok
|
127
|
+
}.gsub(/^\s+/,''))
|
128
|
+
expect($stderr.string).to eq('')
|
129
|
+
end
|
130
|
+
|
131
|
+
it "shows debug details; has req body" do
|
132
|
+
$cfg['tool.debug'] = true
|
133
|
+
$stdout = StringIO.new
|
134
|
+
$stderr = StringIO.new
|
135
|
+
|
136
|
+
allow(@req).to receive(:body).and_return("this is my body")
|
137
|
+
allow(@rsp).to receive(:body).and_return("ok")
|
138
|
+
expect(@tst).to receive(:error).once.with('Request Failed: 410: ok')
|
139
|
+
|
140
|
+
@tst.showHttpError(@req, @rsp)
|
141
|
+
expect($stdout.string).to eq(%{Sent GET https://test.host/this/is/a/test
|
142
|
+
> Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
143
|
+
> Accept: */*
|
144
|
+
> User-Agent: test
|
145
|
+
> Host: test.host
|
146
|
+
> Content-Type: application/json
|
147
|
+
>> this is my body
|
148
|
+
Got 410 ok
|
149
|
+
}.gsub(/^\s+/,''))
|
150
|
+
expect($stderr.string).to eq('')
|
151
|
+
end
|
152
|
+
|
153
|
+
it "shows debug details; json body" do
|
154
|
+
$cfg['tool.debug'] = true
|
155
|
+
$stdout = StringIO.new
|
156
|
+
$stderr = StringIO.new
|
157
|
+
|
158
|
+
allow(@rsp).to receive(:body).and_return(%{{"statusCode": 123, "message": "ok"}})
|
159
|
+
expect(@tst).to receive(:error).once.with('Request Failed: 410: [123] ok')
|
160
|
+
|
161
|
+
@tst.showHttpError(@req, @rsp)
|
162
|
+
expect($stdout.string).to eq(%{Sent GET https://test.host/this/is/a/test
|
163
|
+
> Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
|
164
|
+
> Accept: */*
|
165
|
+
> User-Agent: test
|
166
|
+
> Host: test.host
|
167
|
+
> Content-Type: application/json
|
168
|
+
Got 410 ok
|
169
|
+
}.gsub(/^\s+/,''))
|
170
|
+
expect($stderr.string).to eq('')
|
171
|
+
end
|
172
|
+
|
173
|
+
it "shows full error responses" do
|
174
|
+
$cfg['tool.fullerror'] = true
|
175
|
+
$stdout = StringIO.new
|
176
|
+
$stderr = StringIO.new
|
177
|
+
|
178
|
+
allow(@rsp).to receive(:body).and_return(%{{"statusCode": 123, "message": "ok"}})
|
179
|
+
expect(@tst).to receive(:error).once.with("Request Failed: 410: {\n \"statusCode\": 123,\n \"message\": \"ok\"\n}")
|
180
|
+
|
181
|
+
@tst.showHttpError(@req, @rsp)
|
182
|
+
expect($stdout.string).to eq('')
|
183
|
+
expect($stderr.string).to eq('')
|
184
|
+
end
|
185
|
+
|
186
|
+
|
187
|
+
it "calls showHttpError" do
|
188
|
+
$stdout = StringIO.new
|
189
|
+
$stderr = StringIO.new
|
190
|
+
|
191
|
+
idhttp = instance_double('Net::HTTP')
|
192
|
+
expect(idhttp).to receive(:request).once.and_return(@rsp)
|
193
|
+
expect(@tst).to receive(:http).once.and_return(idhttp)
|
194
|
+
expect(@rsp).to receive(:body).and_return(%{{"statusCode": 123, "message": "gone"}})
|
195
|
+
|
196
|
+
@tst.workit(@req)
|
197
|
+
expect($stdout.string).to eq('')
|
198
|
+
expect($stderr.string).to eq("\e[31mRequest Failed: 410: [123] gone\e[0m\n")
|
199
|
+
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
end
|
204
|
+
# vim: set ai et sw=2 ts=2 :
|
data/spec/MakePretties_spec.rb
CHANGED
@@ -45,6 +45,18 @@ RSpec.describe MrMurano::Pretties do
|
|
45
45
|
expect(ret).to eq(str)
|
46
46
|
end
|
47
47
|
|
48
|
+
it "makes it pretty; localtime" do
|
49
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
50
|
+
:subject=>"websocket_websocket_info",
|
51
|
+
:data=>"Script Error: "}
|
52
|
+
ldt = Time.at(1476386031).localtime.to_datetime.iso8601(3)
|
53
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m#{ldt}\e[0m:\nScript Error: "
|
54
|
+
@options[:localtime] = true
|
55
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
56
|
+
@options[:localtime] = false
|
57
|
+
expect(ret).to eq(str)
|
58
|
+
end
|
59
|
+
|
48
60
|
it "makes it pretty; missing timestamp" do
|
49
61
|
data ={:type=>"debug",
|
50
62
|
:subject=>"websocket_websocket_info",
|
@@ -79,5 +91,28 @@ RSpec.describe MrMurano::Pretties do
|
|
79
91
|
ret = MrMurano::Pretties::makePretty(data, @options)
|
80
92
|
expect(ret).to eq(str)
|
81
93
|
end
|
94
|
+
|
95
|
+
it "makes it pretty; hash data" do
|
96
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
97
|
+
:subject=>"websocket_websocket_info",
|
98
|
+
:data=>{
|
99
|
+
:random=>'junk'
|
100
|
+
}}
|
101
|
+
str ="\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\n\e[35m{\e[0m\n \"random\": \"junk\"\n\e[35m}\e[0m"
|
102
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
103
|
+
expect(ret).to eq(str)
|
104
|
+
end
|
105
|
+
|
106
|
+
it "makes it pretty; http hash data" do
|
107
|
+
data ={:type=>"debug", :timestamp=>1476386031,
|
108
|
+
:subject=>"websocket_websocket_info",
|
109
|
+
:data=>{
|
110
|
+
:request=>{:method=>'get'},
|
111
|
+
:response=>{:status=>200},
|
112
|
+
}}
|
113
|
+
str =%|\e[31m\e[48;5;231mDEBUG \e[0m\e[31m\e[48;5;231m[websocket_websocket_info]\e[0m \e[34m2016-10-13T19:13:51.000+00:00\e[0m:\n---------\nrequest:\e[35m{\e[0m\n "method\": \"get\"\n\e[35m}\e[0m\n---------\nresponse:\e[35m{\e[0m\n \"status\": 200\n\e[35m}\e[0m|
|
114
|
+
ret = MrMurano::Pretties::makePretty(data, @options)
|
115
|
+
expect(ret).to eq(str)
|
116
|
+
end
|
82
117
|
end
|
83
118
|
# vim: set ai et sw=2 ts=2 :
|
data/spec/Mock_spec.rb
CHANGED
@@ -1,60 +1,53 @@
|
|
1
|
+
require 'MrMurano/Config'
|
1
2
|
require 'MrMurano/Mock'
|
2
3
|
require 'tempfile'
|
4
|
+
require '_workspace'
|
3
5
|
|
4
6
|
RSpec.describe MrMurano::Mock, "#mock" do
|
7
|
+
include_context "WORKSPACE"
|
5
8
|
before(:example) do
|
6
|
-
@tmpdir = Dir.tmpdir
|
7
|
-
@projectDir = @tmpdir + '/home/work/project'
|
8
|
-
|
9
|
-
FileUtils.mkpath(@projectDir)
|
10
9
|
FileUtils.mkpath(@projectDir + '/endpoints')
|
11
|
-
|
12
|
-
|
13
|
-
$cfg.load
|
14
|
-
end
|
10
|
+
$cfg = MrMurano::Config.new
|
11
|
+
$cfg.load
|
15
12
|
|
16
13
|
@mock = MrMurano::Mock.new
|
17
14
|
end
|
18
15
|
|
19
|
-
after(:example) do
|
20
|
-
FileUtils.remove_dir(@tmpdir + '/home', true) if FileTest.exist? @tmpdir
|
21
|
-
end
|
22
|
-
|
23
16
|
it "can create the testpoint file" do
|
24
|
-
Dir.chdir(@projectDir) do
|
25
17
|
uuid = @mock.create_testpoint()
|
26
18
|
expect(uuid.length).to be("XXXXXXXX-XXXX-XXXX-XXXX-XXXXXXXXXXXX".length)
|
27
19
|
path = @mock.get_testpoint_path()
|
28
20
|
testpoint = File.read(path)
|
29
21
|
expect(testpoint.include? uuid).to be(true)
|
30
|
-
end
|
31
22
|
end
|
32
23
|
|
33
24
|
it "can show the UUID from the testpoint file" do
|
34
|
-
Dir.chdir(@projectDir) do
|
35
25
|
uuid = @mock.create_testpoint()
|
36
26
|
retrieved_uuid = @mock.show()
|
37
27
|
expect(uuid).to eq(retrieved_uuid)
|
38
|
-
end
|
39
28
|
end
|
40
29
|
|
41
30
|
it "can remove the testpoint file" do
|
42
|
-
Dir.chdir(@projectDir) do
|
43
31
|
@mock.create_testpoint()
|
44
32
|
path = @mock.get_testpoint_path()
|
45
33
|
removed = @mock.remove_testpoint()
|
46
34
|
expect(removed).to be(true)
|
47
35
|
expect(File.exist?(path)).to be(false)
|
48
|
-
|
36
|
+
end
|
37
|
+
|
38
|
+
it "can remove the missing testpoint file" do
|
39
|
+
path = @mock.get_testpoint_path()
|
40
|
+
removed = @mock.remove_testpoint()
|
41
|
+
expect(removed).to be(false)
|
42
|
+
expect(File.exist?(path)).to be(false)
|
49
43
|
end
|
50
44
|
|
51
45
|
it "cannot show the UUID if there's no testpoint file" do
|
52
|
-
Dir.chdir(@projectDir) do
|
53
46
|
@mock.create_testpoint()
|
54
47
|
@mock.show()
|
55
48
|
@mock.remove_testpoint()
|
56
49
|
retrieved_uuid = @mock.show()
|
57
50
|
expect(retrieved_uuid).to be(false)
|
58
|
-
end
|
59
51
|
end
|
60
52
|
end
|
53
|
+
# vim: set ai et sw=2 ts=2 :
|
data/spec/ProductBase_spec.rb
CHANGED