# Inspec test for recipe irrigate-php::wp-cli

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

control 'wp-cli' do
  # For using node attributes in tests
  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')
        file_content = File.read('files/default/wp-cli-install.sh')
        describe file '/root/wp-cli-install.sh' do
          its('owner') { should eq 'root' }
          its('group') { should eq 'root' }
          its('mode') { should cmp '0755' }
          its('content') { should eq file_content }
        end

        describe file '/usr/local/bin/wp' do
          it { should exist }
        end
      end
    end
  else
    puts "File #{attribute_file} does not exist, skiping attribute-depending checks"
  end
end
