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

    # TODO: we skip included recipes for now
    # May be we should check if there are tests for included cookbook and add it here??

    case node['automatic']['platform_family']
    when 'rhel'
      if node['automatic']['platform_version'].to_s.start_with?('7')

        packages = %w(
          autoconf
          bzip2-devel
          gcc-c++
          glibc
          gmp-devel
          httpd-devel
          ImageMagick
          ImageMagick-devel
          libcurl-devel
          libdb4-devel
          libevent
          libjpeg-turbo
          libjpeg-turbo-devel
          libmcrypt
          libmcrypt-devel
          libpng-devel
          libtiff
          libtiff-devel
          make
          zip
        )

        packages.each do |name|
          describe package name do
            it { should be_installed }
          end
        end

        # TODO: ideally we should render template using Chef::Resource::Template and check its content with created one
        # Skipping context checking now
        describe file '/opt/remi/php56/root/etc/php.ini' do
          its('mode') { should cmp '0644' }
          its('owner') { should eq 'root' }
          its('group') { should eq 'root' }
        end

        apache_dir = node['default']['apache']['dir']
        conf_path = "#{apache_dir}/conf-available"
        # Check only if such file exists
        describe file "#{conf_path}/images.conf" do
          it { should exist }
        end

        # Ensure the default vhost is disabled
        %w(default default.conf 000-default 000-default.conf).each do |site|
          describe file "#{apache_dir}/sites-enabled/#{site}" do
            it { should_not exist }
          end
        end

        # Vhost attributes are contained in roles
        node['normal']['webapps'].each do |vhost, vhost_info|
          describe file "#{apache_dir}/sites-available/#{vhost}.conf" do
            its('content') { should include "<VirtualHost *:#{vhost_info['port']}>" }
            its('content') { should include "ServerAdmin #{vhost_info['server_admin']}" }
            its('content') { should include "ServerName #{vhost_info['server_name']}" }
            its('content') { should include "DocumentRoot #{vhost_info['docroot']}" }
            # TODO: noto all params are checked, bette to use template rendering
          end
        end
      end
    else
      puts 'Unsupported platform'
    end

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