describe_recipe 'elasticsearch::default' do

  include MiniTest::Chef::Assertions
  include MiniTest::Chef::Context
  include MiniTest::Chef::Resources

  describe "Installation" do

    it "installs libraries to versioned directory" do
      version = node[:elasticsearch][:version]

      directory("/usr/local/elasticsearch-#{node[:elasticsearch][:version]}").
        must_exist.
        with(:owner, 'elasticsearch')
    end

    it "installs elasticsearch jar" do
      version = node[:elasticsearch][:version]

      file("/usr/local/elasticsearch-#{version}/lib/elasticsearch-#{version}.jar").
        must_exist.
        with(:owner, 'elasticsearch')
    end if Chef::VERSION > '10.14'

    it "has a link to versioned directory" do
      version = node[:elasticsearch][:version]

      link("/usr/local/elasticsearch").
        must_exist.
        with(:link_type, :symbolic).
        and(:to, "/usr/local/elasticsearch-#{version}")
    end

    it "creates configuration files" do
      file("/usr/local/etc/elasticsearch/elasticsearch.yml").
        must_exist.
        must_include("cluster.name: 'elasticsearch_vagrant'").
        must_include("path.data: /usr/local/var/data/elasticsearch")

      file("/usr/local/etc/elasticsearch/elasticsearch-env.sh").
        must_exist.
        must_include("ES_HOME='/usr/local/elasticsearch'")
    end

  end

end

describe_recipe 'elasticsearch::default' do

  include MiniTest::Chef::Assertions
  include MiniTest::Chef::Context
  include MiniTest::Chef::Resources

  describe "Installation" do

    it "installs libraries to versioned directory" do
      version = node[:elasticsearch][:version]

      directory("/usr/local/elasticsearch-#{node[:elasticsearch][:version]}").
        must_exist.
        with(:owner, 'elasticsearch')
    end

    it "installs elasticsearch jar" do
      version = node[:elasticsearch][:version]

      file("/usr/local/elasticsearch-#{version}/lib/elasticsearch-#{version}.jar").
        must_exist.
        with(:owner, 'elasticsearch')
    end if Chef::VERSION > '10.14'

    it "has a link to versioned directory" do
      version = node[:elasticsearch][:version]

      link("/usr/local/elasticsearch").
        must_exist.
        with(:link_type, :symbolic).
        and(:to, "/usr/local/elasticsearch-#{version}")
    end

    it "creates configuration files" do
      file("/usr/local/etc/elasticsearch/elasticsearch.yml").
        must_exist

      file("/usr/local/etc/elasticsearch/elasticsearch-env.sh").
        must_exist.
        must_include("ES_HOME='/usr/local/elasticsearch'")
    end

    it "creates the configuration file with proper content" do
      file("/usr/local/etc/elasticsearch/elasticsearch.yml").
        must_include("cluster.name: elasticsearch_vagrant").
        must_include("path.data: /usr/local/var/data/elasticsearch/disk1").
        must_include("bootstrap.mlockall: false")

      if node.name == 'precise64'
        file("/usr/local/etc/elasticsearch/elasticsearch.yml").
          must_include("node.name: precise64")
      end
    end

  end

end

Add better test coverage for the attributes in the elasticsearch.yml file
[FIX] Add better test coverage for the attributes in the elasticsearch.yml file

Related: #39
