Skip to content

Commit

Permalink
(PUP-11981) Add test for non-literal class params in ClassInfoService…
Browse files Browse the repository at this point in the history
… spec
  • Loading branch information
AriaXLi committed Jan 17, 2024
1 parent 838a496 commit 63176d4
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions spec/unit/info_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ class Borked($Herp+$Derp) {}
CODE
'json_unsafe.pp' => <<-CODE,
class json_unsafe($arg1 = /.*/, $arg2 = default, $arg3 = {1 => 1}) {}
CODE
'non_literal.pp' => <<-CODE,
class oops(Integer[1-3] $bad_int) { }
CODE
'non_literal_2.pp' => <<-CODE,
class oops_2(Optional[[String]] $double_brackets) { }
CODE
})
end
Expand Down Expand Up @@ -509,6 +515,19 @@ class json_unsafe($arg1 = /.*/, $arg2 = default, $arg3 = {1 => 1}) {}
})
end

it "errors with a descriptive message if non-literal class parameter is given" do
files = ['non_literal.pp', 'non_literal_2.pp'].map {|f| File.join(code_dir, f) }
result = Puppet::InfoService.classes_per_environment({'production' => files })
expect(result).to eq({
"production"=>{
"#{code_dir}/non_literal.pp" =>
{:error=> "The parameter '$bad_int' must be a literal type, not a Puppet::Pops::Model::AccessExpression (file: #{code_dir}/non_literal.pp, line: 1, column: 37)"},
"#{code_dir}/non_literal_2.pp" =>
{:error=> "The parameter '$double_brackets' must be a literal type, not a Puppet::Pops::Model::AccessExpression (file: #{code_dir}/non_literal_2.pp, line: 1, column: 44)"}
} # end production env
})
end

it "produces no type entry if type is not given" do
files = ['fum.pp'].map {|f| File.join(code_dir, f) }
result = Puppet::InfoService.classes_per_environment({'production' => files })
Expand Down

0 comments on commit 63176d4

Please sign in to comment.