components/ruby/puppet-modules/oracle-solaris_providers/files/etc/puppet/modules/solaris_providers/spec/unit/type/pkg_mediator_spec.rb
changeset 5861 720358c56a5d
equal deleted inserted replaced
5860:afd31ba91ee9 5861:720358c56a5d
       
     1 #!/usr/bin/env rspec
       
     2 require 'spec_helper'
       
     3 
       
     4 describe Puppet::Type.type(:pkg_mediator) do
       
     5 
       
     6   before do
       
     7     @class = described_class
       
     8     @profile_name = "pkgmediator"
       
     9   end
       
    10 
       
    11   it "should have :name as its keyattribute" do
       
    12     expect( @class.key_attributes).to be == [:name]
       
    13   end
       
    14 
       
    15   describe "when validating attributes" do
       
    16     [ :ensure, :version, :implementation ].each do |prop|
       
    17       it "should have a #{prop} property" do
       
    18         expect(@class.attrtype(prop)).to be == :property
       
    19       end
       
    20     end
       
    21   end
       
    22 
       
    23   describe "when validating values" do
       
    24 
       
    25     describe "for ensure" do
       
    26       error_pattern = /Invalid value/m
       
    27       def validate(ens)
       
    28          @class.new(:name => @profile_name, :ensure => ens)
       
    29       end
       
    30 
       
    31       [ "present", "absent" ].each do |newval|
       
    32         it "should accept a value of #{newval}" do
       
    33           expect { validate(newval) }.not_to raise_error
       
    34         end
       
    35       end
       
    36     end
       
    37 
       
    38     describe "for version" do
       
    39       def validate(ver)
       
    40          @class.new(:name => @profile_name, :version => ver)
       
    41       end
       
    42 
       
    43       [ "none", "None", "1", "1.2", "1.2.3" ].each do |v|
       
    44         it "should accept #{v}" do
       
    45           expect { validate v }.not_to raise_error
       
    46         end
       
    47       end
       
    48 
       
    49       [ "A", "1a", "1.2b" ].each do |v|
       
    50         it "should not accept #{v}" do
       
    51           expect { validate v }.to raise_error(Puppet::ResourceError)
       
    52         end
       
    53       end
       
    54     end  # version
       
    55 
       
    56     describe "for implementation" do
       
    57       def validate(imp)
       
    58          @class.new(:name => @profile_name, :implementation => imp)
       
    59       end
       
    60 
       
    61       [ "none", "None", "foo", "foo@1", "[email protected]" ].each do |v|
       
    62         it "should accept #{v}" do
       
    63           expect { validate v }.not_to raise_error
       
    64         end
       
    65       end
       
    66         [ "foo bar", "foo 1", "[email protected]" ].each do |v|
       
    67       it "should not accept #{v}" do
       
    68           expect { validate v }.to raise_error(Puppet::ResourceError)
       
    69         end
       
    70       end
       
    71     end  # implementation
       
    72   end # validating values
       
    73   describe "when validating resource" do
       
    74     it "should not accept None for both implementation and version" do
       
    75          expect { @class.new(:name => @profile_name, :version => 'None', :implementation => "None") }.to raise_error(Puppet::ResourceError)
       
    76     end
       
    77   end
       
    78 end