X-Git-Url: https://git.adam-barratt.org.uk/?a=blobdiff_plain;f=3rdparty%2Fmodules%2Fpostgresql%2Fspec%2Funit%2Fpuppet%2Ftype%2Fpostgresql_conn_validator.rb;fp=3rdparty%2Fmodules%2Fpostgresql%2Fspec%2Funit%2Fpuppet%2Ftype%2Fpostgresql_conn_validator.rb;h=ef3a1edde5ced3ab43662fba23c107159ecd3f0f;hb=a69999e580f8b3abd12446c2d6ad59e517651813;hp=0000000000000000000000000000000000000000;hpb=e7b6b352165009c385c52fcfe5a1055690dbfa4b;p=mirror%2Fdsa-puppet.git diff --git a/3rdparty/modules/postgresql/spec/unit/puppet/type/postgresql_conn_validator.rb b/3rdparty/modules/postgresql/spec/unit/puppet/type/postgresql_conn_validator.rb new file mode 100644 index 000000000..ef3a1edde --- /dev/null +++ b/3rdparty/modules/postgresql/spec/unit/puppet/type/postgresql_conn_validator.rb @@ -0,0 +1,42 @@ +#! /usr/bin/env ruby +require 'spec_helper' + +describe Puppet::Type.type(:postgresql_conn_validator) 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 + end + + describe "when validating attributes" do + [:name, :db_name, :db_username, :command, :host, :port, :connect_settings, :sleep, :tries, :psql_path].each do |param| + it "should have a #{param} parameter" do + expect(described_class.attrtype(param)).to eq(:param) + end + end + end + + describe "when validating values" do + describe "tries and sleep" do + [:tries, :sleep, :port].each do |param| + it "#{param} should be able to cast value as integer" do + expect { described_class.new(:name => 'test', param => '1') }.to_not raise_error + expect { described_class.new(:name => 'test', param => 1) }.to_not raise_error + end + it "#{param} should not accept non-numeric string" do + expect { described_class.new(:name => 'test', param => 'test') }.to raise_error Puppet::ResourceError + end + end + end + describe "connect_settings" do + it "should accept a hash" do + expect { described_class.new(:name => 'test', :connect_settings => { "PGPASSWORD" => "test1" }) }.to_not raise_error + end + end + describe "port" do + it "does not accept a word" do + expect { described_class.new(:name => 'test', :port => 'test')}.to raise_error Puppet::Error + end + end + end +end