require 'spec_helper_acceptance'

describe 'cassandra class' do
  install_pp = <<-EOS
    class { '::cassandra::datastax_repo': } ->
    class { '::cassandra::java': } ->
    class { 'cassandra':
      service_ensure              => 'stopped',
      service_enable              => false,
      cassandra_9822              => true,
      commitlog_directory_mode    => '0770',
      data_file_directories_mode  => '0770',
      saved_caches_directory_mode => '0770'
    } ->
    class { '::cassandra::optutils': } ->
    class { '::cassandra::datastax_agent':
      service_ensure => 'stopped',
      service_enable => false,
    } ->
    class { '::cassandra::opscenter::pycrypto':
      manage_epel => true,
    } ->
    class { '::cassandra::opscenter':
      service_ensure => 'stopped',
      service_enable => false,
    } ->
    class { '::cassandra::firewall_ports': }

    # A workaround for Issue79.
    if $::osfamily == 'Debian' {
      exec { '/bin/chown root:root /etc/apt/sources.list.d/datastax.list':
        refreshonly => true,
        subscribe   => Class[::cassandra::datastax_agent]
      }
    }
  EOS

  describe 'Initial install.' do
    it 'should work with no errors' do
      apply_manifest(install_pp, :catch_failures => true)
    end
  end

  idempotent_pp = <<-EOS
    class { '::cassandra::datastax_repo': } ->
    class { '::cassandra::java': } ->
    class { 'cassandra':
      service_ensure              => 'stopped',
      service_enable              => false,
      cassandra_9822              => true,
      commitlog_directory_mode    => '0770',
      data_file_directories_mode  => '0770',
      saved_caches_directory_mode => '0770'
    } ->
    class { '::cassandra::optutils': } ->
    class { '::cassandra::datastax_agent':
      service_ensure => 'stopped',
      service_enable => false,
    } ->
    class { '::cassandra::opscenter::pycrypto':
      manage_epel => true,
    } ->
    class { '::cassandra::opscenter':
      service_ensure => 'stopped',
      service_enable => false,
    }
  EOS

  describe 'Idempotency test.' do
    it 'should work with no errors' do
      expect(apply_manifest(idempotent_pp, :catch_failures => true).exit_code).to be_zero
    end
  end

  #describe service('cassandra') do
    #it { is_expected.to be_running }
    #it { is_expected.to be_enabled }
  #end

  #describe service('datastax-agent') do
    #it { is_expected.to be_running }
    #it { is_expected.to be_enabled }
  #end

  #describe service('opscenterd') do
    #it { is_expected.to be_running }
    #it { is_expected.to be_enabled }
  #end
end
