require 'spec_helper' describe Puppet::Type.type(:package).provider(:nim) do before(:each) do @resource = double('resource') # A catch all; no parameters set allow(@resource).to receive(:[]).and_return(nil) # But set name and source allow(@resource).to receive(:[]).with(:name).and_return("mypackage.foo") allow(@resource).to receive(:[]).with(:source).and_return("mysource") allow(@resource).to receive(:[]).with(:ensure).and_return(:installed) @provider = subject() @provider.resource = @resource end it "should have an install method" do @provider = subject() expect(@provider).to respond_to(:install) end let(:bff_showres_output) { Puppet::Util::Execution::ProcessOutput.new(<> +-----------------------------------------------------------------------------+ BUILDDATE Verification ... +-----------------------------------------------------------------------------+ Verifying build dates...done FILESET STATISTICS ------------------ 1 Selected to be installed, of which: 1 Already installed (directly or via superseding filesets) ---- 0 Total to be installed Pre-installation Failure/Warning Summary ---------------------------------------- Name Level Pre-installation Failure/Warning ------------------------------------------------------------------------------- mypackage.foo 1.2.3.1 Already superseded by 1.2.3.4 OUTPUT allow(@resource).to receive(:should).with(:ensure).and_return("1.2.3.1") expect(Puppet::Util::Execution).to receive(:execute).with("/usr/sbin/nimclient -o showres -a resource=mysource |/usr/bin/grep -p -E 'mypackage\\.foo( |-)1\\.2\\.3\\.1'").and_return(bff_showres_output).ordered expect(@provider).to receive(:nimclient).with("-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=mysource", "-a", "filesets=mypackage.foo 1.2.3.1").and_return(install_output).ordered expect { @provider.install }.to raise_error(Puppet::Error, "NIM package provider is unable to downgrade packages") end it "should succeed if an RPM package is available on the lpp source" do allow(@resource).to receive(:should).with(:ensure).and_return("1.2.3-4") expect(Puppet::Util::Execution).to receive(:execute).with("/usr/sbin/nimclient -o showres -a resource=mysource |/usr/bin/grep -p -E 'mypackage\\.foo( |-)1\\.2\\.3\\-4'").and_return(rpm_showres_output).ordered expect(@provider).to receive(:nimclient).with("-o", "cust", "-a", "installp_flags=acgwXY", "-a", "lpp_source=mysource", "-a", "filesets=mypackage.foo-1.2.3-4").ordered @provider.install end end it "should fail if the specified version of a RPM package is superseded" do install_output = < 'mypackage.foo').and_return(nil) @provider.uninstall end it "should call rpm to uninstall an rpm package" do expect(@provider).to receive(:lslpp).with("-qLc", "mypackage.foo").and_return("cdrecord:cdrecord-1.9-6:1.9-6: : :C:R:A command line CD/DVD recording program.: :/bin/rpm -e cdrecord: : : : :0: :/opt/freeware:Wed Jun 29 09:41:32 PDT 2005") expect(@provider).to receive(:rpm).with("-e", "mypackage.foo") expect(@provider.class).to receive(:pkglist).with(:pkgname => 'mypackage.foo').and_return(nil) @provider.uninstall end end context "when parsing nimclient showres output" do describe "#parse_showres_output" do it "should be able to parse installp/BFF package listings" do packages = subject.send(:parse_showres_output, bff_showres_output) expect(Set.new(packages.keys)).to eq(Set.new(['mypackage.foo'])) versions = packages['mypackage.foo'] ['1.2.3.1', '1.2.3.4', '1.2.3.8'].each do |version| expect(versions.has_key?(version)).to eq(true) expect(versions[version]).to eq(:installp) end end it "should be able to parse RPM package listings" do packages = subject.send(:parse_showres_output, rpm_showres_output) expect(Set.new(packages.keys)).to eq(Set.new(['mypackage.foo'])) versions = packages['mypackage.foo'] ['1.2.3-1', '1.2.3-4', '1.2.3-8'].each do |version| expect(versions.has_key?(version)).to eq(true) expect(versions[version]).to eq(:rpm) end end it "should be able to parse RPM package listings with letters in version" do showres_output = <