Skip to content
Snippets Groups Projects
Select Git revision
  • 08048aacaa0c1f9558b833c23e68d47989f73843
  • master default protected
  • cleanup_fixtures
  • add-openvox
  • freebsd-14
  • remove-legacy-top-scope-syntax
  • rel430
  • tests
  • revert-363-augeas-module-cleanup
  • release-4.1.0
  • puppet8
  • relax-dependencies
  • rel400
  • mode
  • puppet7
  • release-3.1.0
  • freebsd13
  • freebsd11
  • stdlib
  • centos
  • fedora
  • v5.1.0
  • v5.0.0
  • v4.5.0
  • v4.4.0
  • v4.3.0
  • v4.2.1
  • v4.2.0
  • v4.1.0
  • v4.0.0
  • v3.1.0
  • v3.0.0
  • v2.0.0
  • 1.12.0
  • 1.11.0
  • 1.10.0
  • 1.9.0
  • 1.8.0
  • 1.7.0
  • 1.6.0
  • 1.5.0
41 results

postfix_hash_spec.rb

Blame
  • user avatar
    treydock authored and Raphaël Pinson committed
    May address #130
    08048aac
    History
    Code owners
    Assign users and groups as approvers for specific file changes. Learn more.
    postfix_hash_spec.rb 3.33 KiB
    require 'spec_helper'
    
    describe 'postfix::hash' do
      let (:title) { '/tmp/foo' }
    
      let :pre_condition do
        "class { '::postfix': }"
      end
    
      on_supported_os.each do |os, facts|
        context "on #{os}" do
          let(:facts) do
            facts
          end
    
          context 'when passing wrong type for ensure' do
            let (:params) { {
              :ensure => ['present'],
            } }
            it 'should fail' do
              expect {
                is_expected.to contain_file('/tmp/foo')
              }.to raise_error(Puppet::Error, /\["present"\] is not a string/)
            end
          end
    
          context 'when passing wrong value for ensure' do
            let (:params) { {
              :ensure => 'running',
            } }
            it 'should fail' do
              expect {
                is_expected.to contain_file('/tmp/foo')
              }.to raise_error(Puppet::Error, /must be either 'present' or 'absent'/)
            end
          end
    
          context 'when passing wrong value for title' do
            let (:title) { 'foo' }
            it 'should fail' do
              expect {
                is_expected.to contain_file('/tmp/foo')
              }.to raise_error(Puppet::Error, /"foo" is not an absolute path/)
            end
          end
    
          context 'when passing both source and content' do
            let (:params) { {
              :source  => '/tmp/bar',
              :content => 'bar',
            } }
    
            it 'should fail' do
              expect {
                is_expected.to contain_file('/tmp/foo')
              }.to raise_error(Puppet::Error, /You must provide either 'source' or 'content'/)
            end
          end
    
          context 'when passing source' do
            let (:params) { {
              :source  => '/tmp/bar',
            } }
    
            it { is_expected.to contain_file('/tmp/foo').with(
              :ensure => 'present',
              :source => '/tmp/bar'
            ).without(:content)
            }
            it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
            it { is_expected.to contain_exec('generate /tmp/foo.db') }
            it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
          end
    
          context 'when passing content' do
            let (:params) { {
              :content => 'bar',
            } }
    
            it { is_expected.to contain_file('/tmp/foo').with(
              :ensure  => 'present',
              :content => 'bar'
            ).without(:source)
            }
            it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
            it { is_expected.to contain_exec('generate /tmp/foo.db') }
            it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
          end
    
          context 'when not passing source or content' do
            it { is_expected.to contain_file('/tmp/foo').with(
              :ensure  => 'present'
            ).without(:source).without(:content)
            }
            it { is_expected.to contain_file('/tmp/foo.db').with_ensure('present') }
            it { is_expected.to contain_exec('generate /tmp/foo.db') }
            it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
          end
    
          context 'when ensuring absence' do
            let (:params) { {
              :ensure => 'absent',
            } }
    
            it { is_expected.to contain_file('/tmp/foo').with_ensure('absent') }
            it { is_expected.to contain_file('/tmp/foo.db').with_ensure('absent') }
            it { is_expected.to contain_exec('generate /tmp/foo.db') }
            it { is_expected.to contain_exec('regenerate /tmp/foo.db') }
          end
        end
      end
    end