joshuabaird / puppet-ipaclient

Puppet module to manage IPA client installation. Please fork and contribute!
https://forge.puppetlabs.com/joshuabaird/ipaclient
MIT License
12 stars 23 forks source link

Unknown variable: '::ipa_enrolled' (testing a role with PDK) #63

Closed bittner closed 7 years ago

bittner commented 7 years ago

I'm testing the roles of our control repo, and with profiles that include ipaclient I get an Evaluation Error: Unknown variable: for all $::ipa_* variables.

Clearly, they are not defined (e.g. in params.pp), as this happens via facter/ipa_facts.pp.

$ pdk test unit
[✔] Preparing to run the unit tests.
[✖] Running unit tests.
  Evaluated 4 tests in 3.685280097 seconds: 1 failures, 0 pending.
[✔] Cleaning up after running unit tests.
failed: rspec: ./spec/classes/role_workstation_backoffice_spec.rb:10: error during compilation: Evaluation Error: Unknown variable: '::ipa_enrolled'. at /home/peter.bittner/Development/repos/puppet-control/spec/fixtures/modules/ipaclient/manifests/init.pp:120:16 on node peter-pc.comsolit.local
  role::workstation::backoffice on ubuntu-16.04-x86_64 should compile into a catalogue without dependency cycles
  Failure/Error:
        end

        it { is_expected.to compile.with_all_deps }
      end
    end

... which comes from init.pp, line 117.

Do I have to configure the tests via .fixtures.yml in some way, or is there some other way to make facter (and ipa_facts.rb) initialize those values when running the test suite?

bittner commented 7 years ago

Looks like there is a STRICT_VARIABLES environment variable that can be set to make the tests pass, according to the puppetlabs_spec_helper README:

$ STRICT_VARIABLES=no pdk test unit

Any better solution suggested?

binford2k commented 7 years ago

@bittner That's a custom fact that the PDK doesn't know about. See https://github.com/joshuabaird/puppet-ipaclient/blob/052dd074420b6a2a494e86b2c03020be57940205/lib/facter/ipa_facts.rb#L22

You'll have to add it in to your spec test just like you would $osfamily or the like. Don't disable variable validation :)

bittner commented 7 years ago

@binford2k Thanks for the hint! This makes sense. I'll go with the rspec-puppet-facts docs on adding custom facts.

Now comes the tricky part: Figuring out which values to pick. :smirk: