Skip to content

Commit

Permalink
Add Unit tests for facts hash with topscope
Browse files Browse the repository at this point in the history
  • Loading branch information
bastelfreak committed Feb 28, 2023
1 parent 83477bc commit adad156
Showing 1 changed file with 60 additions and 0 deletions.
60 changes: 60 additions & 0 deletions spec/puppet-lint/plugins/topscope_variable_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,36 @@ class profile::foo {
end
end

context 'with incorrect topscope from facts hash' do
let(:code) do
<<~PUP
class profile::foo {
notify { 'foo':
message => $::facts['some_component_module'],
}
}
PUP
end

it 'should detect one problem' do
expect(problems).to have(1).problem
end

it 'should fix the problem' do
expect(problems).to contain_fixed('use $some_component_module::bar instead of $::some_component_module::bar').on_line(3).in_column(16)
end

it 'should remove :: after the $' do
expect(manifest).to eq <<~PUP
class profile::foo {
notify { 'foo':
message => $facts['some_component_module'],
}
}
PUP
end
end

context 'with incorrect topscope in quoted variable' do
let(:code) do
<<~PUP
Expand Down Expand Up @@ -230,6 +260,36 @@ class foo::blub {
PUP
end
end

context 'with incorrect topscope facts hash in quoted variable' do
let(:code) do
<<~PUP
class foo::blub {
notify { 'foo':
message => ">${::facts['bar'}<"
}
}
PUP
end

it 'should detect one problem' do
expect(problems).to have(1).problem
end

it 'should fix the problem' do
expect(problems).to contain_fixed(msg).on_line(3).in_column(20)
end

it 'should remove :: after the $' do
expect(manifest).to eq <<~PUP
class foo::blub {
notify { 'foo':
message => ">${facts['ar']}<"
}
}
PUP
end
end
end

context 'without a class scope' do
Expand Down

0 comments on commit adad156

Please sign in to comment.