# Validate the Storage resources and test recipes
sd_path = '/etc/bareos/bareos-sd.d'

describe package('bareos-storage') do
  it { should be_installed }
end

describe directory(sd_path) do
  it { should exist }
end

%w(
  /autochanger
  /device
  /director
  /messages
  /ndmp
  /storage
).each do |dir|
  describe directory(sd_path + dir) do
    it { should exist }
  end
end

%w(
  /storage/bareos-sd.conf
  /director/bareos-dir.conf
  /director/bareos-mon.conf
  /messages/Standard.conf
  /device/FileStorage.conf
  /ndmp/bareos-dir-isilon.conf
).each do |config|
  describe file(sd_path + config) do
    it { should exist }
    its('content') { should match(/Generated by Chef/) }
    its('content') { should match(/Name = bareos-sd/) } if config == '/storage/bareos-sd.conf'
    its('content') { should match(/Director, who is permitted to contact this storage daemon/) } if config == '/director/bareos-dir.conf'
    its('content') { should match(/Restricted Director, used by tray-monitor to get the status of this storage daemon/) } if config == '/director/bareos-mon.conf'
    its('content') { should match(/Send all messages to the Director/) } if config == '/messages/Standard.conf'
    its('content') { should match(/File device/) } if config == '/device/FileStorage.conf'
    its('content') { should match(/Name = bareos-dir-isilon/) } if config == '/ndmp/bareos-dir-isilon.conf'
  end
end

describe service('bareos-sd') do
  it { should be_installed }
  it { should be_enabled }
  it { should be_running }
end
