puppetlabs / pdk-templates

The main template repo for the Puppet Development Kit https://github.com/puppetlabs/pdk
Apache License 2.0
47 stars 143 forks source link

Windows FILE resource fails unit testing on Linux #92

Closed canihavethisone closed 6 years ago

canihavethisone commented 6 years ago

Creating a basic FILE resource such as below results in 2 errors when spec testing. the catalogue will successfully apply in windows hosts however:

  1. Parameter path failed on File[test_file]: File paths must be fully qualified
  2. got a relative path in SELinux find_fs:

I have tried stubs however cannot seem to overcome this error. Other windows resources and forge modules (registry, hosts, secpol etc) work fine and do not require stubbing. I have also tried forward slashes, single back slashes, double back slashes, singe and double quotes all to no avail.

class testing {

  file { 'make_z':
    ensure => directory,
    path   => 'c:\\z'
  }
  file { 'test_file':
    ensure  => 'file',
    path    => "c:\\z\\test.txt",
    content => 'I like milk',
    require => File['make_z'],
  }
}
DavidS commented 6 years ago

Hi @canihavethisone , I've created a new module with pdk new module testing --skip-interview, added a class with pdk new class testing, added your code into the class in manifests/init.pp, and ran pdk test unit:

david@davids:~/tmp/testing$ pdk test unit
pdk (INFO): Using Ruby 2.4.4
pdk (INFO): Using Puppet 5.5.1
[✔] Preparing to run the unit tests.
[✖] Running unit tests.
  Evaluated 4 tests in 0.685114981 seconds: 3 failures, 0 pending.
[✔] Cleaning up after running unit tests.
failed: rspec: ./spec/classes/testing_spec.rb:8: error during compilation: Parameter path failed on File[make_z]: File paths must be fully qualified, not 'c:\z' (file: /home/david/tmp/testing/spec/fixtures/modules/testing/manifests/init.pp, line: 8)
  testing on debian-8-x86_64 should compile into a catalogue without dependency cycles
  Failure/Error:
        let(:facts) { os_facts }

        it { is_expected.to compile }
      end
    end

failed: rspec: ./spec/classes/testing_spec.rb:8: error during compilation: Parameter path failed on File[make_z]: File paths must be fully qualified, not 'c:\z' (file: /home/david/tmp/testing/spec/fixtures/modules/testing/manifests/init.pp, line: 8)
  testing on ubuntu-16.04-x86_64 should compile into a catalogue without dependency cycles
  Failure/Error:
        let(:facts) { os_facts }

        it { is_expected.to compile }
      end
    end

failed: rspec: ./spec/classes/testing_spec.rb:8: error during compilation: Parameter path failed on File[make_z]: File paths must be fully qualified, not 'c:\z' (file: /home/david/tmp/testing/spec/fixtures/modules/testing/manifests/init.pp, line: 8)
  testing on redhat-7-x86_64 should compile into a catalogue without dependency cycles
  Failure/Error:
        let(:facts) { os_facts }

        it { is_expected.to compile }
      end
    end

david@davids:~/tmp/testing$

This matches the error you are reporting. (I'm running on Debian here.) Please do note though, that all the errors are for debian, ubuntu, and redhat platforms. The unit tests for windows pass. To cross check, I've removed all platforms other than windows from metadata.json, and there is one remaining test for windows, which passes:

david@davids:~/tmp/testing$ vi metadata.json 
david@davids:~/tmp/testing$ pdk test unit
pdk (INFO): Using Ruby 2.4.4
pdk (INFO): Using Puppet 5.5.1
[✔] Preparing to run the unit tests.
[✔] Running unit tests.
  Evaluated 1 tests in 0.532317288 seconds: 0 failures, 0 pending.
[✔] Cleaning up after running unit tests.
david@davids:~/tmp/testing$ 

I couldn't reproduce the second error you posted, but I'm assuming that it is of similar origin.

Please feel free to re-open this issue with additional information (the platfor you're running on, full output, your test files), or report any other issues you have on the main repo.

Cheers, David