require 'spec_helper'

describe 'collectd::plugin::pcie_errors', type: :class do
  on_supported_os(baseline_os_hash).each do |os, facts|
    context "on #{os} " do
      let :facts do
        facts
      end

      options = os_specific_options(facts)

      context ':ensure => present, default params' do
        content = <<EOS
# Generated by Puppet
<LoadPlugin pcie_errors>
  Globals false
</LoadPlugin>

<Plugin pcie_errors>
  Source "sysfs"
  ReportMasked false
#  PersistentNotifications false
</Plugin>

EOS

        it "Will create #{options[:plugin_conf_dir]}/10-pcie_errors.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('pcie_errors.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-pcie_errors.conf",
            content: content
          )
        end
      end

      context ':ensure => present and :source => proc' do
        let :params do
          { source: 'proc' }
        end

        it "Will create #{options[:plugin_conf_dir]}/10-pcie_errors.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('pcie_errors.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-pcie_errors.conf",
            content: %r{Source "proc"}m
          )
        end
      end

      context ':ensure => present and :access_dir => /sys/bus/pci' do
        let :params do
          { access_dir: '/sys/bus/pci' }
        end

        it "Will create #{options[:plugin_conf_dir]}/10-pcie_errors.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('pcie_errors.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-pcie_errors.conf",
            content: %r{AccessDir "/sys/bus/pci"}m
          )
        end
      end

      context ':ensure => present and :report_masked => true' do
        let :params do
          { report_masked: true }
        end

        it "Will create #{options[:plugin_conf_dir]}/10-pcie_errors.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('pcie_errors.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-pcie_errors.conf",
            content: %r{ReportMasked true}m
          )
        end
      end

      context ':ensure => present and :persistent_notifications => true' do
        let :params do
          { persistent_notifications: true }
        end

        it "Will create #{options[:plugin_conf_dir]}/10-pcie_errors.conf" do
          is_expected.to compile.with_all_deps
          is_expected.to contain_file('pcie_errors.load').with(
            ensure: 'present',
            path: "#{options[:plugin_conf_dir]}/10-pcie_errors.conf",
            content: %r{PersistentNotifications true}m
          )
        end
      end
    end
  end
end
