<commit_before>require 'spec_helper'

describe 'prometheus::source' do
  let(:chef_run) do
    ChefSpec::SoloRunner.new(file_cache_path: '/var/chef/cache') do |node|
      node.set['prometheus']['source']['version'] = '0.12.0'
    end.converge(described_recipe)
  end

  it 'includes build-essential' do
    expect(chef_run).to include_recipe('build-essential::default')
  end

  it 'creates a user with correct attributes' do
    expect(chef_run).to create_user('prometheus').with(
      system: true,
      shell: '/bin/false',
      home: '/opt/prometheus'
    )
  end

  it 'creates a directory at /opt/prometheus' do
    expect(chef_run).to create_directory('/opt/prometheus').with(
      owner: 'prometheus',
      group: 'prometheus',
      mode: '0755',
      recursive: true
    )
  end

  %w( curl git-core mercurial gzip sed ).each do |pkg|
    it 'installs #{pkg}' do
      expect(chef_run).to install_package(pkg)
    end
  end

  it 'checks out prometheus from github' do
    expect(chef_run).to checkout_git("#{Chef::Config[:file_cache_path]}/prometheus-0.12.0").with(
      repository: 'https://github.com/prometheus/prometheus.git',
      revision: '0.12.0'
    )
  end

  it 'compiles prometheus source' do
    expect(chef_run).to run_bash('compile_prometheus_source')
  end

  it 'notifies prometheus to restart' do
    resource = chef_run.bash('compile_prometheus_source')
    expect(resource).to notify('service[prometheus]').to(:restart)
  end

  it 'renders a prometheus job configuration file and notifies prometheus to restart' do
    resource = chef_run.template('/opt/prometheus/prometheus.conf')
    expect(chef_run).to render_file('/opt/prometheus/prometheus.conf').with_content(start_with('# Global default settings.'))
    expect(resource).to notify('service[prometheus]').to(:restart)
  end

  context 'runit' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new do |node|
        node.set['prometheus']['init_style'] = 'runit'
      end.converge(described_recipe)
    end

    it 'includes runit::default recipe' do
      expect(chef_run).to include_recipe('runit::default')
    end

    it 'enables runit_service' do
      expect(chef_run).to enable_runit_service('prometheus')
    end
  end

  context 'bluepill' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new do |node|
        node.set['prometheus']['init_style'] = 'bluepill'
      end.converge(described_recipe)
    end

    it 'includes bluepill::default recipe' do
      expect(chef_run).to include_recipe('bluepill::default')
    end

    it 'renders a bluepill configuration file' do
      expect(chef_run).to render_file("#{chef_run.node['bluepill']['conf_dir']}/prometheus.pill")
    end
  end
end<commit_msg>Added matching spec test for init config<commit_after>require 'spec_helper'

describe 'prometheus::source' do
  let(:chef_run) do
    ChefSpec::SoloRunner.new(file_cache_path: '/var/chef/cache') do |node|
      node.set['prometheus']['source']['version'] = '0.12.0'
    end.converge(described_recipe)
  end

  it 'includes build-essential' do
    expect(chef_run).to include_recipe('build-essential::default')
  end

  it 'creates a user with correct attributes' do
    expect(chef_run).to create_user('prometheus').with(
      system: true,
      shell: '/bin/false',
      home: '/opt/prometheus'
    )
  end

  it 'creates a directory at /opt/prometheus' do
    expect(chef_run).to create_directory('/opt/prometheus').with(
      owner: 'prometheus',
      group: 'prometheus',
      mode: '0755',
      recursive: true
    )
  end

  %w( curl git-core mercurial gzip sed ).each do |pkg|
    it 'installs #{pkg}' do
      expect(chef_run).to install_package(pkg)
    end
  end

  it 'checks out prometheus from github' do
    expect(chef_run).to checkout_git("#{Chef::Config[:file_cache_path]}/prometheus-0.12.0").with(
      repository: 'https://github.com/prometheus/prometheus.git',
      revision: '0.12.0'
    )
  end

  it 'compiles prometheus source' do
    expect(chef_run).to run_bash('compile_prometheus_source')
  end

  it 'notifies prometheus to restart' do
    resource = chef_run.bash('compile_prometheus_source')
    expect(resource).to notify('service[prometheus]').to(:restart)
  end

  it 'renders a prometheus job configuration file and notifies prometheus to restart' do
    resource = chef_run.template('/opt/prometheus/prometheus.conf')
    expect(chef_run).to render_file('/opt/prometheus/prometheus.conf').with_content(start_with('# Global default settings.'))
    expect(resource).to notify('service[prometheus]').to(:restart)
  end

  context 'runit' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new do |node|
        node.set['prometheus']['init_style'] = 'runit'
      end.converge(described_recipe)
    end

    it 'includes runit::default recipe' do
      expect(chef_run).to include_recipe('runit::default')
    end

    it 'enables runit_service' do
      expect(chef_run).to enable_runit_service('prometheus')
    end
  end

  context 'bluepill' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new do |node|
        node.set['prometheus']['init_style'] = 'bluepill'
      end.converge(described_recipe)
    end

    it 'includes bluepill::default recipe' do
      expect(chef_run).to include_recipe('bluepill::default')
    end

    it 'renders a bluepill configuration file' do
      expect(chef_run).to render_file("#{chef_run.node['bluepill']['conf_dir']}/prometheus.pill")
    end
  end

  context 'init' do
    let(:chef_run) do
      ChefSpec::SoloRunner.new do |node|
        node.set['prometheus']['init_style'] = 'init'
      end.converge(described_recipe)
    end

    it 'renders an init.d configuration file' do
      expect(chef_run).to render_file('/etc/init.d/prometheus')
    end
  end
end
{'fraction_non_alphanumeric': 0.12916088765603329, 'fraction_numerical': 0.005547850208044383, 'mean_word_length': 3.675040518638574, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2341818', 'n_tokens_mistral': 2042, 'n_tokens_neox': 1922, 'n_words': 408}