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

    corpsite_backup_file = node['default']['corpsite']['file_path']

    describe file corpsite_backup_file do
      it { should exist }
      its('owner') { should eq node['default']['corpsite']['backup_user'] }
      its('group') { should eq node['default']['corpsite']['backup_user'] }
      its('mode') { should cmp '0750' }
      # TODO: compare content with local file
    end

    describe crontab(node['default']['corpsite']['backup_user']) do
      its('commands') { should include "#{corpsite_backup_file} -i daily" }
      its('commands') { should include "#{corpsite_backup_file} -i weekly" }
      its('commands') { should include "#{corpsite_backup_file} -i monthly" }
    end

    describe crontab('root').commands("#{corpsite_backup_file} -i daily") do
      its('hours') { should cmp '2' }
      its('minutes') { should cmp '0' }
    end

    describe crontab('root').commands("#{corpsite_backup_file} -i weekly") do
      its('weekdays') { should cmp '1' }
      its('hours') { should cmp '3' }
      its('minutes') { should cmp '0' }
    end

    describe crontab('root').commands("#{corpsite_backup_file} -i monthly") do
      its('days') { should cmp '1' }
      its('hours') { should cmp '4' }
      its('minutes') { should cmp '0' }
    end

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