require 'spec_helper'

supported_oses = {}.merge!(on_supported_os)
RspecPuppetFacts.meta_supported_os.each do |os|
  if os['operatingsystem'] =~ /windows/i
    os['operatingsystemrelease'].each do |release|
      os_string = "#{os['operatingsystem']}-#{release}"
      supported_oses[os_string] = {
        :operatingsystem => 'windows',
        :kernelversion => '6.3.9600', # Just defaulting to 2012r2
      }
    end
  end
end

describe 'accounts' do
  context 'supported operating systems' do
    supported_oses.each do |os, facts|
      context "on #{os}" do
        let(:facts) do
          facts
        end

        context 'accounts class without any parameters' do
          it { is_expected.to compile.with_all_deps }

          it { is_expected.to contain_class('accounts::params') }
          it { is_expected.to contain_class('accounts::install').that_comes_before('accounts::config') }
          it { is_expected.to contain_class('accounts::config') }
          it { is_expected.to contain_class('accounts::service').that_subscribes_to('accounts::config') }

          it { is_expected.to contain_service('accounts') }
          it { is_expected.to contain_package('accounts').with_ensure('present') }
        end
      end
    end
  end

  context 'unsupported operating system' do
    describe 'accounts class without any parameters on Solaris/Nexenta' do
      let(:facts) do
        {
          :osfamily        => 'Solaris',
          :operatingsystem => 'Nexenta',
        }
      end

      it { expect { is_expected.to contain_package('accounts') }.to raise_error(Puppet::Error, /Nexenta not supported/) }
    end
  end
end
