Closed hunner closed 8 years ago
Submitted PR #317 to address this issue
This PR is merged, but I'm still seeing a possibly-related issue.
Using a spec including:
let(:facts) {{
:disks => {
'sda' => {
'model' => "APPLE SSD SM0256",
'size' => "233.76 GiB",
'size_bytes' => 251000193024,
'vendor' => "ATA"
},
'sdb' => {
'model' => "SD Card Reader",
'size' => "0 bytes",
'size_bytes' => 0,
'vendor' => "APPLE"
}
},
}}
In my class, I'm trying to filter on this:
$ssd_disks = filter($::disks) |$x| {
$x[1]['model'] =~ /(?i:ssd)/
}
This works when run with a puppet apply
, but now every rspec including that class errors with:
Puppet::PreformattedError:
Evaluation Error: Error while evaluating a Function Call, filter(): wrong argument type (NilClass; must be something enumerable. at /home/jantman/GIT/puppet-archlinux-macbookretina/spec/fixtures/modules/archlinux_macbookretina/manifests/ssd.pp:26:21 on node phoenix.jasonantman.com
Even though doing a notify {'foo': message => $::disks }
shows the proper content. As far as I can tell, this may be related to the fact that, through puppet apply
, type_of($::disks)
is Struct
but in rspec-puppet it is Puppet::Pops::Types::PStructType
.
The error message clearly says that nil
is passed into filter
. Meanwhile PStructType
is Enumerable
as https://github.com/puppetlabs/puppet/blob/master/lib/puppet/pops/types/types.rb#L814 shows.
Can you provide a minimal test case that hits this issue?
:+1: I have this problem as well mocking when puppet read stuff like
$::facts['ec2_metadata']['block-device-mapping']
@rodjek If possible, could you direct us on how to solve this? It's a major for us blocker right now.
@tnn @JesperTerkelsen Have you been able to create a minimal test case?
Using the rough example provided by @jantman as follows
test/manifests/init.pp
class test {
$ssd_disks = filter($::disks) |$x| {
$x[1]['model'] =~ /(?i:ssd)/
}
notify { 'ssd_disks':
message => $ssd_disks
}
}
and the relevant spec (which includes the fact definition provided previously)
context "test class without any parameters" do
it { is_expected.to compile.with_all_deps }
it { is_expected.to contain_notify('ssd_disks').with({
'message' => /SSD /
})
}
it { should have_notify_resource_count(1) }
end
The test runs successfully
$ bundle exec rake spec
...
test
test
test class without any parameters
should compile into a catalogue without dependency cycles
should contain Notify[ssd_disks] with message =~ /SSD /
should contain exactly 1 Notify resource
...
The module elements were provided by garethr/puppet-module-skeleton project.
Pending a failing example, I'm closing this. @tnn there'll be a release with bkeyser's work merged RSN, I hope this resolves your issues!
For a given class:
and a given spec:
rspec gives the resulting output:
Source: https://gist.github.com/jorhett/7e7b33ecba62758200f5