This is related to https://github.com/puppetlabs/puppet/pull/3443.

The piece that's important here is the definition of #trusted. That may
need to be stubbed so that it returns true (or false, it's worth testing
both cases in a spec test) to get the behavior you want.

One technique we often use is, when we have to call executables, wrapping
those calls in their own method so it can be stubbed. For example, you
might write

def exec_getprpw(user):
  %x(/usr/lbin/getprpw #{user} 2>&1)
end

then in the test

provider.stubs(:exec_getprpw).with('root').returns('Some text')

This simulates the call to getprpw without having a dependency on a
particular OS.


On Wed, Jan 14, 2015 at 12:27 PM, James Perry <jjperr...@gmail.com> wrote:

> I am a bit stuck here with a modification to the HPUX user provider
> module.
>
> What I wrote works fine when running the rspec against it on HP-UX but
> fails everywhere else.  Part of the problem I is that to find if the system
> is trusted I have to run a shell command.
>
> To get the modify command to work correctly for trusted and untrusted
> systems, the code needs to be able to add a second program to the command
> line to reset password expiration to 0.
>
> In the code I have a call to a routing to check for the system being a
> trusted computer. When bundler / rspec runs against it on my Linux test
> box, it fails because ther command is HPUX specific, as expected.
>
> How do I stub / mock how to get it to have the rspec not try to make that
> call and take the provided return as if it had done so?  I tried stubs and
> mocks with no success, and I have tried as many ways as I could to figure
> this out with no success.
>
> Code in hpux.rb:
>  def modifycmd(param,value)
>      cmd = super(param, value)
>      cmd << "-F"
>      if self.trusted == "Trusted"
>         cmd << ";"
>         cmd << "/usr/lbin/modprpw"
>         cmd << "-v"
>         cmd << "-l"
>         cmd << "#{resource.name}"
>      end
>      cmd
>   end
>
>
> hpux_spec.rb subset:
>   it "should add /usr/lbin/modprpw -v -l when modifying user if trusted" do
>        resource.stubs(:allowdupe?).returns true
>        provider.expects(:execute).with() { |args|
>  args.include?('/usr/lbin/modprpw') and args.include?("-v") and
> args.include?("-l") }
>        provider.uid = 1000
>   end
>
>
>
>  --
> You received this message because you are subscribed to the Google Groups
> "Puppet Developers" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to puppet-dev+unsubscr...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/puppet-dev/3a21b300-eda7-4168-b1fe-44c28d932d2f%40googlegroups.com
> <https://groups.google.com/d/msgid/puppet-dev/3a21b300-eda7-4168-b1fe-44c28d932d2f%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> For more options, visit https://groups.google.com/d/optout.
>

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

Reply via email to