puppet-lint-fileserver-check 1.1.0 → 1.1.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 645b0edd4d64a696a598dd3253adb1d8cc160f31
4
- data.tar.gz: bb3a09d4048b9fae10d55c5da7e7072176e14490
3
+ metadata.gz: f29951ef181d127ebc193fec7eed34353148bec0
4
+ data.tar.gz: 617f106be6a01288f8d802c5e394d4eab9eab128
5
5
  SHA512:
6
- metadata.gz: 8f6063629cb0b4964bbee81779f501381a462c82eb17c08083a0f86bd264a33e982297f8938f637645c11aa6d5edf058f290787e81a9e984adb0c6a95d5cb9b5
7
- data.tar.gz: c8467b9f3a604dafe999277c88fb4655577c6576b315e3e4d76269165f38c6ca03acf54481840be0338738b8c71cc43c626e956d260db908e6bbd53999ba6471
6
+ metadata.gz: 0f532ff5320204e0817e359f62ef1c4a89e27926a8126aa3fc748baf5490a78f60a4cbc5a8846c3f1a2fce27a1a9313d6647dc2e96f73edc0c1e9a0f60fa9d1e
7
+ data.tar.gz: 1d41a86a47f7fbf9cc480c9a6a36b6ef558fdda66ab0b9a931359c5b1cb6c6c56d881c3cf3926013f7291f1b93c9a0df109d15d17323cf56245f8baf26060345
@@ -16,32 +16,36 @@ PuppetLint.new_check(:fileserver) do
16
16
  end
17
17
 
18
18
  def fix(problem)
19
- if problem[:resource][:type].value == 'file' && problem[:token].type == :SSTRING
20
- problem[:token].prev_code_token.prev_code_token.value = 'content'
21
- problem[:token].value.sub!(%r{^puppet:///modules/(.*)}, "file('\\1')")
22
- problem[:token].type = :NAME
23
- elsif problem[:token].type == :DQPRE
24
- problem[:token].prev_code_token.prev_code_token.value = 'content'
25
- file = PuppetLint::Lexer::Token.new(
26
- :NAME, 'file',
27
- problem[:token].line, problem[:token].column+1
28
- )
29
- lparen = PuppetLint::Lexer::Token.new(
30
- :LPAREN, '(',
31
- problem[:token].line, problem[:token].column+1
32
- )
33
- rparen = PuppetLint::Lexer::Token.new(
34
- :RPAREN, ')',
35
- problem[:token].line, problem[:token].column+1
36
- )
37
- tokens.insert(tokens.index(problem[:token]), file)
38
- tokens.insert(tokens.index(problem[:token]), lparen)
39
- problem[:token].value.sub!(%r{^puppet:///modules/}, '')
40
- t = problem[:token].next_code_token
41
- while t.type != :DQPOST
42
- t = t.next_code_token
19
+ if problem[:resource][:type].value == 'file'
20
+ if problem[:token].type == :SSTRING
21
+ problem[:token].prev_code_token.prev_code_token.value = 'content'
22
+ problem[:token].value.sub!(%r{^puppet:///modules/(.*)}, "file('\\1')")
23
+ problem[:token].type = :NAME
24
+ elsif problem[:token].type == :DQPRE
25
+ problem[:token].prev_code_token.prev_code_token.value = 'content'
26
+ file = PuppetLint::Lexer::Token.new(
27
+ :NAME, 'file',
28
+ problem[:token].line, problem[:token].column+1
29
+ )
30
+ lparen = PuppetLint::Lexer::Token.new(
31
+ :LPAREN, '(',
32
+ problem[:token].line, problem[:token].column+1
33
+ )
34
+ rparen = PuppetLint::Lexer::Token.new(
35
+ :RPAREN, ')',
36
+ problem[:token].line, problem[:token].column+1
37
+ )
38
+ tokens.insert(tokens.index(problem[:token]), file)
39
+ tokens.insert(tokens.index(problem[:token]), lparen)
40
+ problem[:token].value.sub!(%r{^puppet:///modules/}, '')
41
+ t = problem[:token].next_code_token
42
+ while t.type != :DQPOST
43
+ t = t.next_code_token
44
+ end
45
+ tokens.insert(tokens.index(t)+1, rparen)
46
+ else
47
+ raise PuppetLint::NoFix, "Not fixing"
43
48
  end
44
- tokens.insert(tokens.index(t)+1, rparen)
45
49
  else
46
50
  raise PuppetLint::NoFix, "Not fixing"
47
51
  end
@@ -89,6 +89,24 @@ describe 'fileserver' do
89
89
  expect(problems).to contain_warning(msg).on_line(2).in_column(26)
90
90
  end
91
91
  end
92
+
93
+ context 'when using fileserver not in file resource with variables' do
94
+ let(:code) {
95
+ <<-EOS
96
+ foo { 'foo':
97
+ file_source => "puppet:///${module_name}/foo/bar",
98
+ }
99
+ EOS
100
+ }
101
+
102
+ it 'should detect a single problem' do
103
+ expect(problems).to have(1).problem
104
+ end
105
+
106
+ it 'should create a warning' do
107
+ expect(problems).to contain_warning(msg).on_line(2).in_column(26)
108
+ end
109
+ end
92
110
  end
93
111
 
94
112
  context 'with fix enabled' do
@@ -279,5 +297,27 @@ describe 'fileserver' do
279
297
  expect(manifest).to eq(code)
280
298
  end
281
299
  end
300
+
301
+ context 'when using fileserver not in file resource with variables' do
302
+ let(:code) {
303
+ <<-EOS
304
+ foo { 'foo':
305
+ file_source => "puppet:///${module_name}/foo/bar",
306
+ }
307
+ EOS
308
+ }
309
+
310
+ it 'should detect a single problem' do
311
+ expect(problems).to have(1).problem
312
+ end
313
+
314
+ it 'should create a warning' do
315
+ expect(problems).to contain_warning(msg).on_line(2).in_column(26)
316
+ end
317
+
318
+ it 'should not modify the manifest' do
319
+ expect(manifest).to eq(code)
320
+ end
321
+ end
282
322
  end
283
323
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puppet-lint-fileserver-check
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mickaël Canévet