# Inspec test for recipe irrigate-php::sugarcrm

# The Inspec reference, with examples and extensive documentation, can be
# found at http://inspec.io/docs/reference/resources/

control 'sugarcrm' do
  attribute_file = '/tmp/kitchen/node_attributes.json'
  if file(attribute_file).exist?
    node = json(attribute_file).params

    case node['automatic']['platform_family']
    when 'rhel'
      if node['automatic']['platform_version'].to_s.start_with?('7')
        packages = %w(
          php56-php-imap
        )
        packages.each do |name|
          describe package name do
            it { should be_installed }
          end
        end

        jsmin_lib_location = '/opt/remi/php56/root/usr/lib64/php/modules/jsmin.so'

        describe file jsmin_lib_location do
          its('mode') { should cmp '0755' }
        end

        describe file '/opt/remi/php56/root/etc/php.d/10-jsmin.ini' do
          its('mode') { should cmp '0644' }
          its('owner') { should eq 'root' }
          its('group') { should eq 'root' }
          its('content') { should eq 'extension=jsmin.so' }
        end

      end
    end
  else
    puts "File #{attribute_file} does not exist, skiping attribute-depending checks"
  end
end
