diff options
Diffstat (limited to 'spec')
-rw-r--r-- | spec/classes/ca_params_spec.rb | 8 | ||||
-rw-r--r-- | spec/classes/config_spec.rb | 114 | ||||
-rw-r--r-- | spec/classes/master_hiera_spec.rb | 11 | ||||
-rw-r--r-- | spec/classes/master_spec.rb | 52 | ||||
-rw-r--r-- | spec/classes/params_spec.pp | 8 | ||||
-rw-r--r-- | spec/classes/yaml_spec.rb | 47 | ||||
-rw-r--r-- | spec/spec_helper.rb | 34 |
7 files changed, 249 insertions, 25 deletions
diff --git a/spec/classes/ca_params_spec.rb b/spec/classes/ca_params_spec.rb new file mode 100644 index 0000000..5277972 --- /dev/null +++ b/spec/classes/ca_params_spec.rb @@ -0,0 +1,8 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'trocla::ca::params', :type => 'class' do + context 'with default params' do + it { should compile.with_all_deps } + end +end + diff --git a/spec/classes/config_spec.rb b/spec/classes/config_spec.rb new file mode 100644 index 0000000..fc0a33a --- /dev/null +++ b/spec/classes/config_spec.rb @@ -0,0 +1,114 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'trocla::config', :type => 'class' do + let(:facts){ + { + :domain => 'example.com', + } + } + context 'with default params' do + it { should contain_class('trocla::params') } + it { should contain_class('trocla::master') } + it { should contain_file('/etc/puppet/troclarc.yaml').with( + :owner => 'root', + :group => 'puppet', + :mode => '0640' + )} + it { should contain_file('/etc/puppet/troclarc.yaml').with_content("--- +profiles: + sysdomain_nc: + name_constraints: + - example.com +") } + it { should contain_file('/etc/troclarc.yaml').with( + :ensure => 'link', + :target => '/etc/puppet/troclarc.yaml' + )} + + it { should compile.with_all_deps } + end + + context 'with other params' do + let(:params) { + { + :options => { + 'length' => 24, + 'profiles' => 'mydefaultprofile', + 'random' => false, + 'expires' => 60*60*24, #1day + }, + :profiles => { + 'mydefaultprofile' => { + 'length' => 20, + }, + 'anotherprofile' => { + 'random' => true, + 'expires' => false, + }, + }, + :x509_profile_domain_constraints => ['domain1.com','domain2.com'], + :store => 'moneta', + :store_options => { + 'adapter' => 'Sequel', + 'adapter_options' => { + 'db' => 'mysql://db.server.name', + 'user' => 'trocla', + 'password' => 'secret_password', + 'database' => 'trocladb', + 'table' => 'trocla', + }, + }, + :encryption => 'ssl', + :encryption_options => { + 'private_key' => '/var/lib/puppet/ssl/private_keys/trocla.pem', + 'public_key' => '/var/lib/puppet/ssl/public_keys/trocla.pem', + }, + :manage_dependencies => false, + } + } + it { should contain_class('trocla::params') } + it { should_not contain_class('trocla::master') } + it { should contain_file('/etc/puppet/troclarc.yaml').with( + :owner => 'root', + :group => 'puppet', + :mode => '0640' + )} + it { should contain_file('/etc/puppet/troclarc.yaml').with_content("--- +encryption: :ssl +encryption_options: + :private_key: /var/lib/puppet/ssl/private_keys/trocla.pem + :public_key: /var/lib/puppet/ssl/public_keys/trocla.pem +options: + expires: 86400 + length: 24 + profiles: mydefaultprofile + random: false +profiles: + anotherprofile: + expires: false + random: true + mydefaultprofile: + length: 20 + sysdomain_nc: + name_constraints: + - domain1.com + - domain2.com +store: :moneta +store_options: + adapter: :Sequel + adapter_options: + :database: trocladb + :db: mysql://db.server.name + :password: secret_password + :table: trocla + :user: trocla +") } + it { should contain_file('/etc/troclarc.yaml').with( + :ensure => 'link', + :target => '/etc/puppet/troclarc.yaml' + )} + + it { should compile.with_all_deps } + end +end + diff --git a/spec/classes/master_hiera_spec.rb b/spec/classes/master_hiera_spec.rb new file mode 100644 index 0000000..287abaa --- /dev/null +++ b/spec/classes/master_hiera_spec.rb @@ -0,0 +1,11 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'trocla::master::hiera', :type => 'class' do + context 'with default params' do + it { should compile.with_all_deps } + it { should contain_package('rubygem-hiera-backend-trocla').with( + :ensure => 'present' + )} + end +end + diff --git a/spec/classes/master_spec.rb b/spec/classes/master_spec.rb new file mode 100644 index 0000000..ad99c86 --- /dev/null +++ b/spec/classes/master_spec.rb @@ -0,0 +1,52 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'trocla::master', :type => 'class' do + context 'with default params' do + context 'on RedHat' do + let(:facts) { + { + :osfamily => 'RedHat', + } + } + it { should contain_package('trocla').with( + :name => 'rubygem-trocla', + :ensure => 'installed' + )} + it { should compile.with_all_deps } + end + context 'on Debian' do + let(:facts) { + { + :osfamily => 'Debian', + } + } + it { should contain_package('trocla').with( + :ensure => 'installed' + )} + it { should compile.with_all_deps } + end + end + context 'with gem provider' do + let(:params){ + { + :provider => 'gem' + } + } + it { should contain_package('trocla').with( + :ensure => 'installed', + :provider => 'gem' + )} + + it { should compile.with_all_deps } + context 'on RedHat' do + it { should contain_package('trocla').with( + :name => 'trocla', + :ensure => 'installed', + :provider => 'gem' + )} + + it { should compile.with_all_deps } + end + end +end + diff --git a/spec/classes/params_spec.pp b/spec/classes/params_spec.pp new file mode 100644 index 0000000..4d05e1f --- /dev/null +++ b/spec/classes/params_spec.pp @@ -0,0 +1,8 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'trocla::params', :type => 'class' do + context 'with default params' do + it { should compile.with_all_deps } + end +end + diff --git a/spec/classes/yaml_spec.rb b/spec/classes/yaml_spec.rb new file mode 100644 index 0000000..49d2cb5 --- /dev/null +++ b/spec/classes/yaml_spec.rb @@ -0,0 +1,47 @@ +require File.expand_path(File.join(File.dirname(__FILE__),'../spec_helper')) + +describe 'trocla::yaml', :type => 'class' do + let(:facts){ + { + :domain => 'example.com', + } + } + context 'with default params' do + it { should contain_class('trocla::config').with( + 'store' => 'moneta', + 'store_options' => { + 'adapter' => 'YAML', + 'adapter_options' => { + 'file' => '/var/lib/trocla/trocla_data.yaml', + } + } + )} + it { should contain_file('/etc/puppet/troclarc.yaml').with_content("--- +profiles: + sysdomain_nc: + name_constraints: + - example.com +store: :moneta +store_options: + adapter: :YAML + adapter_options: + :file: /var/lib/trocla/trocla_data.yaml +") } + it { should contain_file('/var/lib/trocla').with( + :ensure => 'directory', + :owner => 'puppet', + :group => 0, + :mode => '0600', + :require => 'Package[trocla]' + )} + it { should contain_file('/var/lib/trocla/trocla_data.yaml').with( + :ensure => 'file', + :owner => 'puppet', + :group => 0, + :mode => '0600', + :require => 'Package[trocla]' + )} + it { should compile.with_all_deps } + end +end + diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 461a858..381f972 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,29 +1,13 @@ -$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib')) -$LOAD_PATH.unshift(File.dirname(__FILE__)) -require 'rspec' -require 'mocha' -require 'trocla' +require 'puppetlabs_spec_helper/module_spec_helper' +require 'rake' -# Requires supporting files with custom matchers and macros, etc, -# in ./support/ and its subdirectories. -Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f} +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) -RSpec.configure do |config| - +RSpec.configure do |c| + c.module_path = File.join(fixture_path, 'modules') + c.manifest_dir = File.join(fixture_path, 'manifests') + c.pattern = FileList[c.pattern].exclude(/^spec\/fixtures/) end -def default_config - @default_config ||= YAML.load(File.read(File.expand_path(base_dir+'/lib/trocla/default_config.yaml'))) -end - -def test_config - return @config unless @config.nil? - @config = default_config - @config.delete('adapter_options') - @config['adapter'] = :Memory - @config -end - -def base_dir - File.dirname(__FILE__)+'/../' -end +Puppet::Util::Log.level = :warning +Puppet::Util::Log.newdestination(:console) |