Commit 0aed640e authored by Nathan Ward's avatar Nathan Ward
Browse files

Rework rspec tests quite a lot for the classes and facts.

There is still a lot more to do here to get full coverage, and a lot of work to figure out testing across multiple OSes etc. however this is a solid start.
parent 72386004
Loading
Loading
Loading
Loading
+6 −7
Original line number Diff line number Diff line
fixtures:
    symlinks:
      freeradius: "#{source_dir}"
    repositories:
      stdlib:
        repo: https://github.com/puppetlabs/puppetlabs-stdlib.git
        ref: 4.3.2
  forge_modules:
    concat: "puppetlabs/concat"
    firewall: "puppetlabs/firewall"
    logrotate: "puppet/logrotate"
    rsyslog: "saz/rsyslog"
    stdlib: "puppetlabs/stdlib"
+24 −17
Original line number Diff line number Diff line
# Grab the FreeRADIUS version from the output of radiusd -v

module Facter::Util::FreeradiusVersion
  class << self
    def version_string
      # Set path to binary for our platform
      dist = Facter.value(:osfamily)
      case dist
@@ -11,24 +14,28 @@ else
        binary = 'radiusd'
      end

# Execute call to fetch version info
version = Facter::Core::Execution.exec("#{binary} -v")
      Facter::Core::Execution.exec("#{binary} -v")
    end
  end
end

# Extract full version number
Facter.add(:freeradius_version) do
  setcode do
    if !version.nil?
      minver = version.split(/\n/)[0].match(/FreeRADIUS Version (\d+\.\d+\.\d+)/)[1].to_s
    version_string = Facter::Util::FreeradiusVersion.version_string
    if !version_string.nil?
      version = version_string.split(/\n/)[0].match(/FreeRADIUS Version (\d+\.\d+\.\d+)/)[1].to_s
    end
    minver
    version
  end
end

# Extract major version number
Facter.add(:freeradius_maj_version) do
  setcode do
    if !version.nil?
      majver = version.split(/\n/)[0].match(/FreeRADIUS Version (\d+)\.\d+\.\d+/)[1].to_s
    version_string = Facter::Util::FreeradiusVersion.version_string
    if !version_string.nil?
      majver = version_string.split(/\n/)[0].match(/FreeRADIUS Version (\d+)\.\d+\.\d+/)[1].to_s
    end
    majver
  end
+8 −6
Original line number Diff line number Diff line
@@ -63,6 +63,8 @@ class freeradius (
    "${freeradius::fr_basepath}/mods-config/attr_filter",
    "${freeradius::fr_basepath}/mods-config/preprocess",
    "${freeradius::fr_basepath}/mods-config/sql",
    "${freeradius::fr_basepath}/sites-available",
    "${freeradius::fr_basepath}/mods-available",
  ]:
    ensure  => directory,
    mode    => '0755',
@@ -138,12 +140,12 @@ class freeradius (
  }
  concat::fragment { 'policy_header':
    target  => "${freeradius::fr_basepath}/policy.conf",
    content => "policy {\n",
    content => 'policy {',
    order   => 10,
  }
  concat::fragment { 'policy_footer':
    target  => "${freeradius::fr_basepath}/policy.conf",
    content => "}\n",
    content => '}',
    order   => '99',
  }

@@ -162,7 +164,7 @@ class freeradius (
  }
  concat::fragment { 'template_footer':
    target  => "${freeradius::fr_basepath}/templates.conf",
    content => "}\n",
    content => '}',
    order   => '95',
  }

@@ -177,7 +179,7 @@ class freeradius (
  }
  concat::fragment { 'proxy_header':
    target  => "${freeradius::fr_basepath}/proxy.conf",
    content => "# Proxy config\n\n",
    content => '# Proxy config\n',
    order   => '05',
  }

@@ -341,7 +343,7 @@ class freeradius (
  # Syslog rules
  if $syslog == true {
    rsyslog::snippet { '12-radiusd-log':
      content => "if \$programname == \'radiusd\' then ${freeradius::fr_logpath}/radius.log\n&~",
      content => "if \$programname == \'radiusd\' then ${freeradius::fr_logpath}/radius.log\n\&\~",
    }
  }

@@ -434,7 +436,7 @@ class freeradius (
    "${freeradius::fr_basepath}/clients.conf",
    "${freeradius::fr_basepath}/sql.conf",
  ]:
    content => "# FILE INTENTIONALLY BLANK\n",
    content => '# FILE INTENTIONALLY BLANK\n',
    mode    => '0644',
    owner   => 'root',
    group   => $freeradius::fr_group,
+15 −30
Original line number Diff line number Diff line
require 'spec_helper'
require 'shared_contexts'

describe 'freeradius::control_socket' do
  # by default the hiera integration uses hiera data from the shared_contexts.rb file
  # but basically to mock hiera you first need to add a key/value pair
  # to the specific context in the spec/shared_contexts.rb file
  # Note: you can only use a single hiera context per describe/context block
  # rspec-puppet does not allow you to swap out hiera data on a per test block
  #include_context :hiera
  on_supported_os.each do |os, os_facts|
    context "on #{os}" do
      include_context 'redhat_params'
      include_context 'freeradius_default'

      let(:facts) { os_facts }

  # below is the facts hash that gives you the ability to mock
  # facts on a per describe/context block.  If you use a fact in your
  # manifest you should mock the facts below.
  let(:facts) do
    {}
  end
  # below is a list of the resource parameters that you can override.
  # By default all non-required parameters are commented out,
  # while all required parameters will require you to add a value
  let(:params) do
    {
      #:mode => "ro",
    }
  end
  # add these two lines in a single test block to enable puppet and hiera debug mode
  # Puppet::Util::Log.level = :debug
  # Puppet::Util::Log.newdestination(:console)
      # Empty params hash by default so we can super().merge
      let(:params) { {} }

      describe 'freeradius::control_socket' do
        it do
          is_expected.to contain_freeradius__site('control-socket')
      .with(
        'content' => 'template(freeradius/sites-enabled/control-socket.erb)'
      )
        end
      end
    end
  end
end
+531 −371

File changed.

Preview size limit exceeded, changes collapsed.

Loading