puppet-repl 0.1.1 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.rspec +1 -0
- data/.travis.yml +8 -1
- data/CHANGELOG.md +17 -1
- data/Gemfile +3 -5
- data/Gemfile.lock +16 -19
- data/README.md +96 -45
- data/VERSION +1 -1
- data/lib/awesome_print/ext/awesome_puppet.rb +5 -4
- data/lib/puppet-repl/cli.rb +96 -64
- data/lib/puppet-repl/support/environment.rb +6 -6
- data/lib/puppet-repl/support/errors.rb +69 -0
- data/lib/puppet-repl/support/facts.rb +9 -0
- data/lib/puppet-repl/support/input_responders.rb +62 -16
- data/lib/puppet-repl/support/node.rb +72 -7
- data/lib/puppet-repl/support/play.rb +33 -11
- data/lib/puppet-repl/support/scope.rb +17 -13
- data/lib/puppet-repl/support.rb +29 -0
- data/lib/puppet-repl.rb +34 -0
- data/lib/version.rb +1 -1
- data/puppet-repl.gemspec +23 -13
- data/resources/classes.png +0 -0
- data/resources/classification.png +0 -0
- data/resources/command_line_node.png +0 -0
- data/resources/functions.png +0 -0
- data/resources/hiera.png +0 -0
- data/resources/set_node.png +0 -0
- data/resources/tab_complete.png +0 -0
- data/resources/variables.png +0 -0
- data/spec/fixtures/invalid_node_obj.yaml +8 -0
- data/spec/fixtures/node_obj.yaml +315 -0
- data/spec/prepl_spec.rb +16 -0
- data/spec/puppet-repl_spec.rb +301 -51
- data/spec/spec_helper.rb +17 -15
- data/spec/support_spec.rb +114 -2
- metadata +32 -34
data/spec/puppet-repl_spec.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
require 'spec_helper'
|
2
|
-
|
2
|
+
require 'stringio'
|
3
3
|
describe "PuppetRepl" do
|
4
4
|
|
5
5
|
let(:resource) do
|
@@ -10,8 +10,12 @@ describe "PuppetRepl" do
|
|
10
10
|
repl.handle_input('reset')
|
11
11
|
end
|
12
12
|
|
13
|
+
let(:output) do
|
14
|
+
StringIO.new('', 'w')
|
15
|
+
end
|
16
|
+
|
13
17
|
let(:repl) do
|
14
|
-
PuppetRepl::Cli.new
|
18
|
+
PuppetRepl::Cli.new(:out_buffer => output)
|
15
19
|
end
|
16
20
|
|
17
21
|
let(:input) do
|
@@ -22,6 +26,39 @@ describe "PuppetRepl" do
|
|
22
26
|
repl.parser.evaluate_string(repl.scope, input)
|
23
27
|
end
|
24
28
|
|
29
|
+
describe 'multiple lines of input' do
|
30
|
+
describe '3 lines' do
|
31
|
+
let(:input) do
|
32
|
+
"$var1 = 'test'\nfile{\"/tmp/${var1}.txt\": ensure => present, mode => '0755'}\nvars"
|
33
|
+
end
|
34
|
+
it do
|
35
|
+
repl.handle_input(input)
|
36
|
+
expect(output.string).to match(/server_facts/) if Puppet.version.to_f >= 4.1
|
37
|
+
expect(output.string).to match(/test/)
|
38
|
+
expect(output.string).to match(/Puppet::Type::File/)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe '2 lines' do
|
42
|
+
let(:input) do
|
43
|
+
"$var1 = 'test'\n $var2 = 'test2'"
|
44
|
+
end
|
45
|
+
it do
|
46
|
+
repl.handle_input(input)
|
47
|
+
expect(output.string).to eq("\n => \e[0;33m\"test\"\e[0m\n => \e[0;33m\"test2\"\e[0m\n")
|
48
|
+
end
|
49
|
+
end
|
50
|
+
describe '1 lines' do
|
51
|
+
let(:input) do
|
52
|
+
"$var1 = 'test'"
|
53
|
+
end
|
54
|
+
it do
|
55
|
+
repl.handle_input(input)
|
56
|
+
expect(output.string).to eq("\n => \e[0;33m\"test\"\e[0m\n")
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
|
25
62
|
describe 'returns a array of resource_types' do
|
26
63
|
it 'returns resource type' do
|
27
64
|
expect(resource_types.first.class.to_s).to eq('Puppet::Pops::Types::PResourceType')
|
@@ -33,12 +70,13 @@ describe "PuppetRepl" do
|
|
33
70
|
'help'
|
34
71
|
end
|
35
72
|
it 'can show the help screen' do
|
36
|
-
|
37
|
-
|
38
|
-
expect
|
39
|
-
expect
|
40
|
-
expect
|
41
|
-
expect
|
73
|
+
expected_repl_output = /Type \"exit\", \"functions\", \"vars\", \"krt\", \"facts\", \"resources\", \"classes\",\n \"play\", \"classification\", \"reset\", or \"help\" for more information.\n\n/
|
74
|
+
repl.handle_input(input)
|
75
|
+
expect(output.string).to match(/Ruby Version: #{RUBY_VERSION}\n/)
|
76
|
+
expect(output.string).to match(/Puppet Version: \d.\d.\d\n/)
|
77
|
+
expect(output.string).to match(/Puppet Repl Version: \d.\d.\d\n/)
|
78
|
+
expect(output.string).to match(/Created by: NWOps <corey@nwops.io>\n/)
|
79
|
+
expect(output.string).to match(expected_repl_output)
|
42
80
|
end
|
43
81
|
end
|
44
82
|
|
@@ -47,16 +85,18 @@ describe "PuppetRepl" do
|
|
47
85
|
""
|
48
86
|
end
|
49
87
|
it 'can run' do
|
50
|
-
repl_output = "
|
51
|
-
|
88
|
+
repl_output = "\n"
|
89
|
+
repl.handle_input(input)
|
90
|
+
expect(output.string).to eq(repl_output)
|
52
91
|
end
|
53
92
|
describe 'space' do
|
54
93
|
let(:input) do
|
55
94
|
" "
|
56
95
|
end
|
57
96
|
it 'can run' do
|
58
|
-
repl_output = " => \n"
|
59
|
-
|
97
|
+
repl_output = "\n => \n"
|
98
|
+
repl.handle_input(input)
|
99
|
+
expect(output.string).to eq(repl_output)
|
60
100
|
end
|
61
101
|
end
|
62
102
|
end
|
@@ -67,7 +107,8 @@ describe "PuppetRepl" do
|
|
67
107
|
end
|
68
108
|
it 'can run' do
|
69
109
|
repl_output = /hostclasses/
|
70
|
-
|
110
|
+
repl.handle_input(input)
|
111
|
+
expect(output.string).to match(repl_output)
|
71
112
|
end
|
72
113
|
end
|
73
114
|
|
@@ -80,12 +121,13 @@ describe "PuppetRepl" do
|
|
80
121
|
'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'
|
81
122
|
end
|
82
123
|
it 'file' do
|
83
|
-
|
124
|
+
repl.handle_input("play #{fixtures_file}")
|
125
|
+
expect(output.string).to match(/Puppet::Type::File/)
|
84
126
|
end
|
85
127
|
it 'url' do
|
86
|
-
|
128
|
+
repl.handle_input("play #{file_url}")
|
129
|
+
expect(output.string).to match(/Puppet::Type::File/)
|
87
130
|
end
|
88
|
-
|
89
131
|
end
|
90
132
|
|
91
133
|
describe 'variables' do
|
@@ -93,8 +135,9 @@ describe "PuppetRepl" do
|
|
93
135
|
"$file_path = '/tmp/test2.txt'"
|
94
136
|
end
|
95
137
|
it 'can process a variable' do
|
96
|
-
repl_output = " => \e[0;33m\"/tmp/test2.txt\"\e[0m\n"
|
97
|
-
|
138
|
+
repl_output = "\n => \e[0;33m\"/tmp/test2.txt\"\e[0m\n"
|
139
|
+
repl.handle_input(input)
|
140
|
+
expect(output.string).to eq(repl_output)
|
98
141
|
end
|
99
142
|
end
|
100
143
|
|
@@ -104,7 +147,8 @@ describe "PuppetRepl" do
|
|
104
147
|
end
|
105
148
|
it 'can process a resource' do
|
106
149
|
repl_output = /Puppet::Type::File/
|
107
|
-
|
150
|
+
repl.handle_input(input)
|
151
|
+
expect(output.string).to match(repl_output)
|
108
152
|
end
|
109
153
|
end
|
110
154
|
|
@@ -113,18 +157,20 @@ describe "PuppetRepl" do
|
|
113
157
|
"Service{"
|
114
158
|
end
|
115
159
|
it 'can process' do
|
116
|
-
repl_output = " => \e[31mSyntax error at end of file\e[0m\n"
|
117
|
-
|
160
|
+
repl_output = "\n => \e[31mSyntax error at end of file\e[0m\n"
|
161
|
+
repl.handle_input(input)
|
162
|
+
expect(output.string).to eq(repl_output)
|
118
163
|
end
|
119
164
|
end
|
120
165
|
|
121
|
-
describe '
|
166
|
+
describe 'classification' do
|
122
167
|
let(:input) do
|
123
|
-
"
|
168
|
+
"classification"
|
124
169
|
end
|
125
|
-
|
126
|
-
|
127
|
-
|
170
|
+
|
171
|
+
it 'can process a file' do
|
172
|
+
repl.handle_input(input)
|
173
|
+
expect(output.string).to eq("\n[]\n")
|
128
174
|
end
|
129
175
|
end
|
130
176
|
|
@@ -135,19 +181,21 @@ describe "PuppetRepl" do
|
|
135
181
|
|
136
182
|
it 'can process a file' do
|
137
183
|
repl_output = /Puppet::Type::File/
|
138
|
-
|
184
|
+
repl.handle_input(input)
|
185
|
+
expect(output.string).to match(repl_output)
|
139
186
|
repl.handle_input('reset')
|
140
|
-
|
187
|
+
repl.handle_input(input)
|
188
|
+
expect(output.string).to match(repl_output)
|
141
189
|
end
|
142
190
|
|
143
191
|
describe 'loglevel' do
|
144
192
|
it 'has not changed' do
|
145
193
|
repl.handle_input(":set loglevel debug")
|
146
194
|
expect(Puppet::Util::Log.level).to eq(:debug)
|
147
|
-
expect(Puppet::Util::Log.destinations[:
|
195
|
+
expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
|
148
196
|
repl.handle_input('reset')
|
149
197
|
expect(Puppet::Util::Log.level).to eq(:debug)
|
150
|
-
expect(Puppet::Util::Log.destinations[:
|
198
|
+
expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
|
151
199
|
end
|
152
200
|
end
|
153
201
|
end
|
@@ -158,7 +206,8 @@ describe "PuppetRepl" do
|
|
158
206
|
end
|
159
207
|
it 'can process a each block' do
|
160
208
|
repl_output = /Puppet::Type::File/
|
161
|
-
|
209
|
+
repl.handle_input(input)
|
210
|
+
expect(output.string).to match(repl_output)
|
162
211
|
end
|
163
212
|
end
|
164
213
|
|
@@ -167,10 +216,11 @@ describe "PuppetRepl" do
|
|
167
216
|
"['/tmp/test3', '/tmp/test4'].each |String $path| { file{$path: ensure => present} }"
|
168
217
|
end
|
169
218
|
let(:repl_output) do
|
170
|
-
" => [\n
|
219
|
+
"\n => [\n \e[1;37m[0] \e[0m\e[0;33m\"/tmp/test3\"\e[0m,\n \e[1;37m[1] \e[0m\e[0;33m\"/tmp/test4\"\e[0m\n]\n"
|
171
220
|
end
|
172
221
|
it 'can process a each block' do
|
173
|
-
|
222
|
+
repl.handle_input(input)
|
223
|
+
expect(output.string).to eq(repl_output)
|
174
224
|
end
|
175
225
|
end
|
176
226
|
|
@@ -179,8 +229,9 @@ describe "PuppetRepl" do
|
|
179
229
|
"$::fqdn"
|
180
230
|
end
|
181
231
|
it 'should be able to resolve fqdn' do
|
182
|
-
repl_output = " => \e[0;33m\"foo.example.com\"\e[0m\n"
|
183
|
-
|
232
|
+
repl_output = "\n => \e[0;33m\"foo.example.com\"\e[0m\n"
|
233
|
+
repl.handle_input(input)
|
234
|
+
expect(output.string).to eq(repl_output)
|
184
235
|
end
|
185
236
|
end
|
186
237
|
|
@@ -189,7 +240,9 @@ describe "PuppetRepl" do
|
|
189
240
|
"facts"
|
190
241
|
end
|
191
242
|
it 'should be able to print facts' do
|
192
|
-
|
243
|
+
repl_output = /kernel/
|
244
|
+
repl.handle_input(input)
|
245
|
+
expect(output.string).to match(repl_output)
|
193
246
|
end
|
194
247
|
end
|
195
248
|
|
@@ -198,7 +251,20 @@ describe "PuppetRepl" do
|
|
198
251
|
'resources'
|
199
252
|
end
|
200
253
|
it 'should be able to print resources' do
|
201
|
-
|
254
|
+
repl_output = /main/
|
255
|
+
repl.handle_input(input)
|
256
|
+
expect(output.string).to match(repl_output)
|
257
|
+
end
|
258
|
+
end
|
259
|
+
|
260
|
+
describe 'print class' do
|
261
|
+
let(:input) do
|
262
|
+
"Class['settings']"
|
263
|
+
end
|
264
|
+
it 'should be able to print classes' do
|
265
|
+
repl_output = /Settings/
|
266
|
+
repl.handle_input(input)
|
267
|
+
expect(output.string).to match(repl_output)
|
202
268
|
end
|
203
269
|
end
|
204
270
|
|
@@ -207,7 +273,9 @@ describe "PuppetRepl" do
|
|
207
273
|
'resources'
|
208
274
|
end
|
209
275
|
it 'should be able to print classes' do
|
210
|
-
|
276
|
+
repl_output = /Settings/
|
277
|
+
repl.handle_input(input)
|
278
|
+
expect(output.string).to match(repl_output)
|
211
279
|
end
|
212
280
|
end
|
213
281
|
|
@@ -216,10 +284,11 @@ describe "PuppetRepl" do
|
|
216
284
|
":set loglevel debug"
|
217
285
|
end
|
218
286
|
it 'should set the loglevel' do
|
219
|
-
|
220
|
-
|
287
|
+
repl_output = /loglevel debug is set/
|
288
|
+
repl.handle_input(input)
|
289
|
+
expect(output.string).to match(repl_output)
|
221
290
|
expect(Puppet::Util::Log.level).to eq(:debug)
|
222
|
-
expect(Puppet::Util::Log.destinations[:
|
291
|
+
expect(Puppet::Util::Log.destinations[:buffer].name).to eq(:buffer)
|
223
292
|
end
|
224
293
|
end
|
225
294
|
|
@@ -228,16 +297,29 @@ describe "PuppetRepl" do
|
|
228
297
|
"vars"
|
229
298
|
end
|
230
299
|
it 'display facts variable' do
|
231
|
-
|
232
|
-
|
300
|
+
repl_output = /facts/
|
301
|
+
repl.handle_input(input)
|
302
|
+
expect(output.string).to match(repl_output)
|
303
|
+
end
|
304
|
+
it 'display server facts variable' do
|
305
|
+
repl_output = /server_facts/
|
306
|
+
repl.handle_input(input)
|
307
|
+
expect(output.string).to match(repl_output) if Puppet.version.to_f >= 4.1
|
308
|
+
end
|
309
|
+
it 'display serverversion variable' do
|
310
|
+
repl_output = /serverversion/
|
311
|
+
repl.handle_input(input)
|
312
|
+
expect(output.string).to match(repl_output) if Puppet.version.to_f >= 4.1
|
233
313
|
end
|
234
314
|
it 'display local variable' do
|
235
|
-
|
236
|
-
expect
|
237
|
-
|
315
|
+
repl.handle_input("$var1 = 'value1'")
|
316
|
+
expect(output.string).to match(/value1/)
|
317
|
+
repl.handle_input("$var1")
|
318
|
+
expect(output.string).to match(/value1/)
|
238
319
|
end
|
239
320
|
it 'display productname variable' do
|
240
|
-
|
321
|
+
repl.handle_input("$productname")
|
322
|
+
expect(output.string).to match(/VirtualBox/)
|
241
323
|
end
|
242
324
|
end
|
243
325
|
|
@@ -246,13 +328,181 @@ describe "PuppetRepl" do
|
|
246
328
|
"md5('hello')"
|
247
329
|
end
|
248
330
|
it 'execute md5' do
|
249
|
-
|
250
|
-
|
331
|
+
repl_output = "\n => \e[0;33m\"5d41402abc4b2a76b9719d911017c592\"\e[0m\n"
|
332
|
+
repl.handle_input(input)
|
333
|
+
expect(output.string).to eq(repl_output)
|
251
334
|
end
|
252
335
|
it 'execute swapcase' do
|
253
|
-
|
254
|
-
|
336
|
+
repl_output = /HELLO/
|
337
|
+
repl.handle_input("swapcase('hello')")
|
338
|
+
expect(output.string).to match(repl_output)
|
339
|
+
end
|
340
|
+
end
|
341
|
+
|
342
|
+
describe 'unidentified object' do
|
343
|
+
let(:repl_output) { "\n => \n" }
|
344
|
+
describe "Node['foot']" do
|
345
|
+
let(:input) { subject }
|
346
|
+
it 'returns string' do
|
347
|
+
repl.handle_input(input)
|
348
|
+
expect(output.string).to eq(repl_output)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
describe "Puppet::Pops::Types::PStringType" do
|
352
|
+
let(:input) { subject }
|
353
|
+
it 'returns string' do
|
354
|
+
repl.handle_input(input)
|
355
|
+
expect(output.string).to eq(repl_output)
|
356
|
+
end
|
357
|
+
end
|
358
|
+
describe 'Facts' do
|
359
|
+
let(:input) { subject }
|
360
|
+
it 'returns string' do
|
361
|
+
repl.handle_input(input)
|
362
|
+
expect(output.string).to eq(repl_output)
|
363
|
+
end
|
364
|
+
end
|
365
|
+
end
|
366
|
+
|
367
|
+
describe 'remote node' do
|
368
|
+
let(:node_obj) do
|
369
|
+
YAML.load_file(File.join(fixtures_dir, 'node_obj.yaml'))
|
370
|
+
end
|
371
|
+
let(:node_name) do
|
372
|
+
'puppetdev.localdomain'
|
373
|
+
end
|
374
|
+
before :each do
|
375
|
+
allow(repl).to receive(:get_remote_node).with(node_name).and_return(node_obj)
|
376
|
+
repl.handle_input(":set node #{node_name}")
|
377
|
+
end
|
378
|
+
|
379
|
+
describe 'set' do
|
380
|
+
it 'sends message about resetting' do
|
381
|
+
expect(output.string).to eq("\n => Resetting to use node puppetdev.localdomain\n")
|
382
|
+
end
|
383
|
+
|
384
|
+
it "return node name" do
|
385
|
+
output.reopen # removes previous message
|
386
|
+
repl.handle_input('$::hostname')
|
387
|
+
expect(output.string).to match(/puppetdev.localdomain/)
|
388
|
+
end
|
389
|
+
|
390
|
+
it "return classification" do
|
391
|
+
output.reopen # removes previous message
|
392
|
+
repl.handle_input('classification')
|
393
|
+
expect(output.string).to match(/certificate_authority_host/)
|
394
|
+
end
|
395
|
+
end
|
396
|
+
|
397
|
+
describe 'facts' do
|
398
|
+
let(:input) do
|
399
|
+
"$::facts['os']['family'].downcase == 'debian'"
|
400
|
+
end
|
401
|
+
it 'fact evaulation should return false' do
|
402
|
+
repl_output = /false/
|
403
|
+
repl.handle_input(input)
|
404
|
+
expect(output.string).to match(repl_output)
|
405
|
+
end
|
406
|
+
|
407
|
+
end
|
408
|
+
describe 'use defaults when invalid' do
|
409
|
+
let(:node_obj) do
|
410
|
+
YAML.load_file(File.join(fixtures_dir, 'invalid_node_obj.yaml'))
|
411
|
+
end
|
412
|
+
let(:node_name) do
|
413
|
+
'invalid.localdomain'
|
414
|
+
end
|
415
|
+
it 'name' do
|
416
|
+
expect{repl.node.name}.to raise_error(PuppetRepl::Exception::UndefinedNode)
|
417
|
+
end
|
418
|
+
end
|
419
|
+
|
420
|
+
it 'set node name' do
|
421
|
+
expect(repl.remote_node_name = 'puppetdev.localdomain').to eq("puppetdev.localdomain")
|
422
|
+
end
|
423
|
+
|
424
|
+
describe 'print classes' do
|
425
|
+
let(:input) do
|
426
|
+
'resources'
|
427
|
+
end
|
428
|
+
it 'should be able to print classes' do
|
429
|
+
repl_output = /Settings/
|
430
|
+
repl.handle_input(input)
|
431
|
+
expect(output.string).to match(repl_output)
|
432
|
+
end
|
255
433
|
end
|
256
434
|
|
435
|
+
describe 'vars' do
|
436
|
+
let(:input) do
|
437
|
+
"vars"
|
438
|
+
end
|
439
|
+
it 'display facts variable' do
|
440
|
+
repl_output = /facts/
|
441
|
+
repl.handle_input(input)
|
442
|
+
expect(output.string).to match(repl_output)
|
443
|
+
end
|
444
|
+
it 'display server facts variable' do
|
445
|
+
repl_output = /server_facts/
|
446
|
+
repl.handle_input(input)
|
447
|
+
expect(output.string).to match(repl_output) if Puppet.version.to_f >= 4.1
|
448
|
+
end
|
449
|
+
it 'display server facts variable' do
|
450
|
+
repl_output = /server_facts/
|
451
|
+
repl.handle_input(input)
|
452
|
+
expect(output.string).to match(repl_output) if Puppet.version.to_f >= 4.1
|
453
|
+
end
|
454
|
+
it 'display local variable' do
|
455
|
+
repl.handle_input("$var1 = 'value1'")
|
456
|
+
expect(output.string).to match(/value1/)
|
457
|
+
repl.handle_input("$var1")
|
458
|
+
expect(output.string).to match(/value1/)
|
459
|
+
end
|
460
|
+
it 'display productname variable' do
|
461
|
+
repl.handle_input("$productname")
|
462
|
+
expect(output.string).to match(/VMware Virtual Platform/)
|
463
|
+
end
|
464
|
+
end
|
465
|
+
|
466
|
+
describe 'execute functions' do
|
467
|
+
let(:input) do
|
468
|
+
"md5('hello')"
|
469
|
+
end
|
470
|
+
it 'execute md5' do
|
471
|
+
repl_output = /5d41402abc4b2a76b9719d911017c592/
|
472
|
+
repl.handle_input(input)
|
473
|
+
expect(output.string).to match(repl_output)
|
474
|
+
end
|
475
|
+
it 'execute swapcase' do
|
476
|
+
repl_output = /HELLO/
|
477
|
+
repl.handle_input("swapcase('hello')")
|
478
|
+
expect(output.string).to match(repl_output)
|
479
|
+
end
|
480
|
+
end
|
481
|
+
|
482
|
+
describe 'reset' do
|
483
|
+
let(:input) do
|
484
|
+
"file{'/tmp/reset': ensure => present}"
|
485
|
+
end
|
486
|
+
|
487
|
+
it 'can process a file' do
|
488
|
+
repl_output = /Puppet::Type::File/
|
489
|
+
repl.handle_input(input)
|
490
|
+
expect(output.string).to match(repl_output)
|
491
|
+
repl.handle_input('reset')
|
492
|
+
repl.handle_input(input)
|
493
|
+
expect(output.string).to match(repl_output)
|
494
|
+
end
|
495
|
+
end
|
496
|
+
|
497
|
+
describe 'classification' do
|
498
|
+
let(:input) do
|
499
|
+
"classification"
|
500
|
+
end
|
501
|
+
|
502
|
+
it 'shows certificate_authority_host' do
|
503
|
+
repl.handle_input(input)
|
504
|
+
expect(output.string).to match(/certificate_authority_host/)
|
505
|
+
end
|
506
|
+
end
|
257
507
|
end
|
258
508
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,20 +1,22 @@
|
|
1
1
|
require 'simplecov'
|
2
2
|
require_relative '../lib/puppet-repl'
|
3
|
-
|
4
|
-
module SimpleCov::Configuration
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
9
|
-
|
10
|
-
SimpleCov.configure do
|
11
|
-
|
12
|
-
|
13
|
-
end
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
3
|
+
require 'yaml'
|
4
|
+
# module SimpleCov::Configuration
|
5
|
+
# def clean_filters
|
6
|
+
# @filters = []
|
7
|
+
# end
|
8
|
+
# end
|
9
|
+
#
|
10
|
+
# SimpleCov.configure do
|
11
|
+
# clean_filters
|
12
|
+
# load_profile 'test_frameworks'
|
13
|
+
# end
|
14
|
+
#
|
15
|
+
# SimpleCov.start do
|
16
|
+
# add_filter "/.rvm/"
|
17
|
+
# add_filter "vendor"
|
18
|
+
# add_filter "bundler"
|
19
|
+
# end
|
18
20
|
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
19
21
|
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
20
22
|
|
data/spec/support_spec.rb
CHANGED
@@ -3,14 +3,38 @@ require 'tempfile'
|
|
3
3
|
|
4
4
|
describe 'support' do
|
5
5
|
|
6
|
+
let(:output) do
|
7
|
+
StringIO.new('', 'w')
|
8
|
+
end
|
9
|
+
|
6
10
|
let(:repl) do
|
7
|
-
PuppetRepl::Cli.new
|
11
|
+
PuppetRepl::Cli.new(:out_buffer => output)
|
8
12
|
end
|
9
13
|
|
10
14
|
let(:scope) do
|
11
15
|
repl.scope
|
12
16
|
end
|
13
17
|
|
18
|
+
describe 'play' do
|
19
|
+
let(:url) do
|
20
|
+
'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0'
|
21
|
+
end
|
22
|
+
let(:input) do
|
23
|
+
"play #{url}"
|
24
|
+
end
|
25
|
+
|
26
|
+
let(:expected) do
|
27
|
+
''
|
28
|
+
end
|
29
|
+
|
30
|
+
it do
|
31
|
+
repl.handle_input(input)
|
32
|
+
expect(output.string).to match(/server_facts/) if Puppet.version.to_f >= 4.1
|
33
|
+
expect(output.string).to match(/test/)
|
34
|
+
expect(output.string).to match(/Puppet::Type::File/)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
14
38
|
let(:puppet_version) do
|
15
39
|
repl.mod_finder.match(repl.puppet_lib_dir)[1]
|
16
40
|
end
|
@@ -29,7 +53,6 @@ describe 'support' do
|
|
29
53
|
service{'httpd': ensure => running}\n
|
30
54
|
|
31
55
|
EOF
|
32
|
-
|
33
56
|
end
|
34
57
|
|
35
58
|
after(:each) do
|
@@ -68,4 +91,93 @@ describe 'support' do
|
|
68
91
|
expect(repl.node.facts.values['fqdn']).to eq('foo.example.com')
|
69
92
|
end
|
70
93
|
|
94
|
+
describe 'convert url' do
|
95
|
+
|
96
|
+
describe 'unsupported' do
|
97
|
+
let(:url) { 'https://bitbuck.com/master/lib/log_helper.rb'}
|
98
|
+
let(:converted) { 'https://bitbuck.com/master/lib/log_helper.rb' }
|
99
|
+
it do
|
100
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
101
|
+
end
|
102
|
+
end
|
103
|
+
describe 'gitlab' do
|
104
|
+
describe 'blob' do
|
105
|
+
let(:url) { 'https://gitlab.com/nwops/prepl-web/blob/master/lib/log_helper.rb'}
|
106
|
+
let(:converted) { 'https://gitlab.com/nwops/prepl-web/raw/master/lib/log_helper.rb' }
|
107
|
+
it do
|
108
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'raw' do
|
113
|
+
let(:url) { 'https://gitlab.com/nwops/prepl-web/raw/master/lib/log_helper.rb'}
|
114
|
+
let(:converted) { 'https://gitlab.com/nwops/prepl-web/raw/master/lib/log_helper.rb' }
|
115
|
+
it do
|
116
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
117
|
+
end
|
118
|
+
end
|
119
|
+
|
120
|
+
describe 'snippet' do
|
121
|
+
|
122
|
+
describe 'not raw' do
|
123
|
+
let(:url) { 'https://gitlab.com/snippets/19471'}
|
124
|
+
let(:converted) { 'https://gitlab.com/snippets/19471/raw'}
|
125
|
+
it do
|
126
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
127
|
+
end
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'raw' do
|
131
|
+
let(:url) { 'https://gitlab.com/snippets/19471/raw'}
|
132
|
+
let(:converted) { 'https://gitlab.com/snippets/19471/raw'}
|
133
|
+
it do
|
134
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
135
|
+
end
|
136
|
+
end
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
describe 'github' do
|
141
|
+
describe 'raw' do
|
142
|
+
let(:url) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw'}
|
143
|
+
let(:converted) { 'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw' }
|
144
|
+
it do
|
145
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
describe 'raw gist' do
|
150
|
+
let(:url) {'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw/c8f6be52da5b2b0eeaabb9aa75832b75793d35d1/controls.pp'}
|
151
|
+
let(:converted) {'https://gist.githubusercontent.com/logicminds/f9b1ac65a3a440d562b0/raw/c8f6be52da5b2b0eeaabb9aa75832b75793d35d1/controls.pp'}
|
152
|
+
it do
|
153
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
154
|
+
end
|
155
|
+
end
|
156
|
+
describe 'raw non gist' do
|
157
|
+
let(:url) { 'https://raw.githubusercontent.com/nwops/puppet-repl/master/lib/puppet-repl.rb'}
|
158
|
+
let(:converted) { 'https://raw.githubusercontent.com/nwops/puppet-repl/master/lib/puppet-repl.rb' }
|
159
|
+
it do
|
160
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
161
|
+
end
|
162
|
+
|
163
|
+
end
|
164
|
+
|
165
|
+
describe 'blob' do
|
166
|
+
let(:url) { 'https://github.com/nwops/puppet-repl/blob/master/lib/puppet-repl.rb'}
|
167
|
+
let(:converted) { 'https://github.com/nwops/puppet-repl/raw/master/lib/puppet-repl.rb' }
|
168
|
+
it do
|
169
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
170
|
+
end
|
171
|
+
end
|
172
|
+
|
173
|
+
describe 'gist' do
|
174
|
+
let(:url) { 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0'}
|
175
|
+
let(:converted) { 'https://gist.github.com/logicminds/f9b1ac65a3a440d562b0.txt' }
|
176
|
+
it do
|
177
|
+
expect(repl.convert_to_text(url)).to eq(converted)
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
181
|
+
end
|
182
|
+
|
71
183
|
end
|