require 'spec_helper'

describe 'lm_sensors' do
  context 'Redhat' do
    let(:facts) do
      {
        :osfamily => 'RedHat',
        :virtual  => 'physical'
      }
    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)
    it do
      is_expected.to compile.with_all_deps
    end

    it do
      is_expected.to contain_package('lm_sensors')
      .with(
        'ensure' => 'installed',
        'name'   => 'lm_sensors',
        'notify' => 'Exec[sensors-detect]'
        )
    end
    it do
      is_expected.to contain_exec('sensors-detect')
      .with(
        'command' => '/usr/sbin/sensors-detect < /dev/null',
        'notify'  => 'Service[lm_sensors]',
        'require' => 'Package[lm_sensors]',
        'unless'  => "/bin/grep \"Generated by sensors-detect\" /etc/sysconfig/lm_sensors"
        )
    end
    it do
      is_expected.to contain_service('lm_sensors')
      .with(
        'enable'     => 'true',
        'ensure'     => 'running',
        'hasrestart' => 'true',
        'name'       => 'lm_sensors',
        'require'    => ['Package[lm_sensors]', 'Exec[sensors-detect]']
        )
    end
  end
  context 'Debian' do
    let(:facts) do
      {
        :osfamily => 'Debian',
        :virtual  => 'physical'
      }
    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)
    it do
      is_expected.to compile.with_all_deps
    end

    it do
      is_expected.to contain_package('lm_sensors')
      .with(
        'ensure' => 'installed',
        'name'   => 'lm-sensors',
        'notify' => 'Exec[sensors-detect]'
        )
    end
    it do
      is_expected.to contain_exec('sensors-detect')
      .with(
        'command' => '/usr/bin/yes "yes" | /usr/sbin/sensors-detect > /dev/null',
        'notify'  => 'Service[lm_sensors]',
        'require' => 'Package[lm_sensors]',
        'unless'  => "/bin/grep \"Generated by sensors-detect\" /etc/modules"
        )
    end
    it do
      is_expected.to contain_service('lm_sensors')
      .with(
        'enable'     => 'true',
        'ensure'     => 'running',
        'hasrestart' => 'true',
        'name'       => 'lm-sensors',
        'require'    => ['Package[lm_sensors]', 'Exec[sensors-detect]']
        )
    end
  end
end
