diff --git a/spec/unit/provider/postgresql_conf/parsed_spec.rb b/spec/unit/provider/postgresql_conf/parsed_spec.rb index 5055043..24e31c1 100644 --- a/spec/unit/provider/postgresql_conf/parsed_spec.rb +++ b/spec/unit/provider/postgresql_conf/parsed_spec.rb @@ -1,147 +1,147 @@ require 'spec_helper' require "tempfile" provider_class = Puppet::Type.type(:postgresql_conf).provider(:parsed) describe provider_class do let(:title) { 'postgresql_conf' } let(:provider) { conf_class = Puppet::Type.type(:postgresql_conf) provider = conf_class.provider(:parsed) conffile = tmpfilename('postgresql.conf') - provider.any_instance.stub(:target).and_return conffile + allow_any_instance_of(provider).to receive(:target).and_return conffile provider } before do end after :each do provider.initvars end describe "simple configuration that should be allowed" do it "should parse a simple ini line" do expect(provider.parse_line("listen_addreses = '*'")).to eq( { :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed } ) end it "should parse a simple ini line (2)" do expect(provider.parse_line(" listen_addreses = '*'")).to eq( { :name=>"listen_addreses", :value=>"*", :comment=>nil, :record_type=>:parsed } ) end it "should parse a simple ini line (3)" do expect(provider.parse_line("listen_addreses = '*' # dont mind me")).to eq( { :name=>"listen_addreses", :value=>"*", :comment=>"dont mind me", :record_type=>:parsed } ) end it "should parse a comment" do expect(provider.parse_line("# dont mind me")).to eq( { :line=>"# dont mind me", :record_type=>:comment } ) end it "should parse a comment (2)" do expect(provider.parse_line(" \t# dont mind me")).to eq( { :line=>" \t# dont mind me", :record_type=>:comment } ) end it "should allow includes" do expect(provider.parse_line("include puppetextra")).to eq( { :name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed } ) end it "should allow numbers through without quotes" do expect(provider.parse_line("wal_keep_segments = 32")).to eq( { :name=>"wal_keep_segments", :value=>"32", :comment=>nil, :record_type=>:parsed } ) end it "should allow blanks through " do expect(provider.parse_line("")).to eq( { :line=>"", :record_type=>:blank } ) end it "should parse keys with dots " do expect(provider.parse_line("auto_explain.log_min_duration = 1ms")).to eq( { :name => "auto_explain.log_min_duration", :value => "1ms", :comment => nil, :record_type => :parsed } ) end end describe "configuration that should be set" do it "should set comment lines" do expect(provider.to_line({ :line=>"# dont mind me", :record_type=>:comment })).to eq( '# dont mind me' ) end it "should set blank lines" do expect(provider.to_line({ :line=>"", :record_type=>:blank })).to eq( '' ) end it "should set simple configuration" do expect(provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>nil, :record_type=>:parsed })).to eq( "listen_addresses = '*'" ) end it "should set simple configuration with period in name" do expect(provider.to_line({:name => "auto_explain.log_min_duration", :value => '100ms', :comment => nil, :record_type => :parsed })).to eq( "auto_explain.log_min_duration = 100ms" ) end it "should set simple configuration even with comments" do expect(provider.to_line({:name=>"listen_addresses", :value=>"*", :comment=>'dont mind me', :record_type=>:parsed })).to eq( "listen_addresses = '*' # dont mind me" ) end it 'should quote includes' do expect(provider.to_line( {:name=>"include", :value=>"puppetextra", :comment=>nil, :record_type=>:parsed })).to eq( "include 'puppetextra'" ) end it 'should quote multiple words' do expect(provider.to_line( {:name=>"archive_command", :value=>"rsync up", :comment=>nil, :record_type=>:parsed })).to eq( "archive_command = 'rsync up'" ) end it 'shouldn\'t quote numbers' do expect(provider.to_line( {:name=>"wal_segments", :value=>"32", :comment=>nil, :record_type=>:parsed })).to eq( "wal_segments = 32" ) end it "should allow numbers" do expect(provider.to_line( {:name=>"integer", :value=>42, :comment=>nil, :record_type=>:parsed })).to eq( "integer = 42" ) end it "should allow floats" do expect(provider.to_line( {:name=>"float", :value=>2.71828182845, :comment=>nil, :record_type=>:parsed })).to eq( "float = 2.71828182845" ) end it "quotes addresses" do expect(provider.to_line( {:name=>"listen_addresses", :value=>"0.0.0.0", :comment=>nil, :record_type=>:parsed })).to eq( "listen_addresses = '0.0.0.0'" ) end end end diff --git a/spec/unit/type/postgresql_conf_spec.rb b/spec/unit/type/postgresql_conf_spec.rb index 4214fac..a406b0c 100644 --- a/spec/unit/type/postgresql_conf_spec.rb +++ b/spec/unit/type/postgresql_conf_spec.rb @@ -1,50 +1,50 @@ #! /usr/bin/env ruby require 'spec_helper' describe Puppet::Type.type(:postgresql_conf) do before do @provider_class = described_class.provide(:simple) { mk_resource_methods } - @provider_class.stub(:suitable?).and_return true - described_class.stub(:defaultprovider).and_return @provider_class + allow(@provider_class).to receive(:suitable?).and_return true + allow(described_class).to receive(:defaultprovider).and_return @provider_class end describe "namevar validation" do it "should have :name as its namevar" do expect(described_class.key_attributes).to eq([:name]) end it "should not invalid names" do expect { described_class.new(:name => 'foo bar') }.to raise_error(Puppet::Error, /Invalid value/) end it "should allow dots in names" do expect { described_class.new(:name => 'foo.bar') }.to_not raise_error end end describe "when validating attributes" do [:name, :provider].each do |param| it "should have a #{param} parameter" do expect(described_class.attrtype(param)).to eq(:param) end end [:value, :target].each do |property| it "should have a #{property} property" do expect(described_class.attrtype(property)).to eq(:property) end end end describe "when validating values" do describe "ensure" do it "should support present as a value for ensure" do expect { described_class.new(:name => 'foo', :ensure => :present) }.to_not raise_error end it "should support absent as a value for ensure" do expect { described_class.new(:name => 'foo', :ensure => :absent) }.to_not raise_error end it "should not support other values" do expect { described_class.new(:name => 'foo', :ensure => :foo) }.to raise_error(Puppet::Error, /Invalid value/) end end end end