# InSpec test for recipe irrigate-sonarqube::default

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

# # encoding: utf-8

# Inspec test for recipe irrigate-sonarqube::default

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

if os.name == 'centos'
  packages = %w(
    unzip
    java-11-openjdk
  )
elsif os.name == 'amazon'
  packages = %w(
    unzip
    java-11-amazon-corretto
  )
end

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

# Check if sonar service is running.
describe systemd_service('sonar') do
  it { should be_installed }
  it { should be_enabled }
  it { should be_running }
end

# Check if sonar.properties exists for sonar server to start.
describe file('/opt/sonarqube/conf/sonar.properties') do
  it { should exist }
end

# Make sure diectory is own by sonar.
describe file('/opt/sonarqube') do
  it { should exist }
  its('owner') { should eq 'sonar_user' }
  its('group') { should eq 'sonar_group' }
  its('mode') { should cmp '0755' }
end

# Check if systemd_unit exist for sonar.
describe file('/etc/systemd/system/sonar.service') do
  it { should exist }
end
