Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Unit tests for facts hash with topscope #22

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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