On 20 October 2015 at 08:49, Alex Harvey <alexharv...@gmail.com> wrote:
> Hi all,
>
> I am investigating whether or not I can use Beaker to do acceptance testing
> on roles and profiles.
>
> I've had a look at Liam Bennett's excellent blog posts -
> http://tech.opentable.co.uk/blog/2014/09/01/testing-puppet-with-beaker-pt-dot-3-testing-roles/
> http://www.slideshare.net/liamjbennett/cfgmgmt2015-testing-with-beaker
>
> I need to handle a situation in my tests where, say, a role that I am
> testing will apply a base class which will cause the node, for instance, to
> join a FreeIPA domain.  But I don't want Beaker to actually build a FreeIPA
> box.  And I don't want my short-lived node to join a real FreeIPA domain.
>
> I would hope that Beaker could either build Mock Services
> https://en.wikipedia.org/wiki/Mock_object
>
> Or better still, tell Beaker to expect the base class to try to apply the
> FreeIPA class, and just pretend it succeeds.  Just as you can stub out
> methods in rspec etc.
>
> Has anyone done anything like this before?
>

You can actually do something like that :)

Beaker is going to run you Puppet code on the node(s) it spins up,
probably using apply manifest like so:

    apply_manifest(pp, :catch_failures=>true)

If this sees an error while doing so (because your FreeIP class
doesn't apply) then it will throw an error. However...

If you check the API docs you can see:

http://www.rubydoc.info/github/puppetlabs/beaker/Beaker/DSL/Helpers/PuppetHelpers#apply_manifest_on-instance_method

    apply_manifest(pp, :accept_all_exit_codes => true)

This will run your puppet code and not throw an error.

Now, whether this works for you really depends on if any other classes
depend on the FreeIPA class. And you can't easily test for idempotent
runs easily with this.

Another approach if you can change the puppet code is to introduce a
switch in the profile, for instance if a fact exists like MOCK_FREEIPA
you could not include the class. And then drop that fact into your
beaker test environment.

Also see the other points about testing at different levels but you
can absolutely do it in your acceptance tests.

Gareth

> Kind regards,
> Alex Harvey
>
> --
> You received this message because you are subscribed to the Google Groups
> "Puppet Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-users+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-users/5493914c-ecc9-42e4-ad90-4151e0e75fbc%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.



-- 
Gareth Rushgrove
@garethr

devopsweekly.com
morethanseven.net
garethrushgrove.com

-- 
You received this message because you are subscribed to the Google Groups 
"Puppet Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to puppet-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/puppet-users/CAFi_6yL5ikcYWFGyhrYeFtqkauTX%3DE4vjsVj_tb7AYHpk%3D_Myg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to