control 'base_default' do
  # describe package 'chrony' do
  #   it { should be_installed }
  # end

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

    if node['directories'] && !node['directories'].empty?
      node['directories'].each do |_directory_name, directory_info|
        describe directory directory_info['path'] do
          its('owner') { should eq directory_info['owner'] || 'root' }
          its('group') { should eq directory_info['group'] || 'root' }
          its('mode') { should cmp directory_info['mode'] }
        end
      end
    else
      puts 'There are no managed directories. Nothing to test...'
    end

    if node['files'] && !node['directories'].empty?
      node['files'].each do |_file_name, file_info|
        describe file file_info['path'] do
          its('owner') { should eq file_info['owner'] || 'root' }
          its('group') { should eq file_info['group'] || 'root' }
          its('mode') { should cmp file_info['mode'] }
          its('content') { should eq file_info['content'] }
        end
      end
    else
      puts 'There are no managed files. Nothing to test...'
    end
  else
    puts "File #{attribute_file} does not exist, skiping attribute-depending checks"
  end
end
