require_relative 'spec_helper'

describe 'pentester::automacchanger' do
  let(:subject) do
    ChefSpec::SoloRunner.new do |node|
      node.override['pentester']['automacchanger']['ifaces'] = %w(wlan0 wlan1)
    end.converge(described_recipe)
  end

  it 'creates template[/usr/local/bin/automacchanger]' do
    expect(subject).to create_template('/usr/local/bin/automacchanger')
      .with(owner: 'root',
            group: 'root',
            source: 'automacchanger.sh.erb',
            mode: '0750',
            variables: { ifaces: %w(wlan0 wlan1) })

    %w(wlan0 wlan1).each do |i|
      expect(subject).to render_file('/usr/local/bin/automacchanger').with_content(/^ifconfig #{i} down$/)
      expect(subject).to render_file('/usr/local/bin/automacchanger').with_content(/^macchanger -r #{i}$/)
      expect(subject).to render_file('/usr/local/bin/automacchanger').with_content(/^ifconfig #{i} up$/)
    end
  end

  it 'creates cookbook_file[/etc/systemd/system/automacchanger.service]' do
    expect(subject).to create_cookbook_file('/etc/systemd/system/automacchanger.service')
      .with(owner: 'root',
            group: 'root',
            source: 'automacchanger.service',
            mode: '0640')
  end

  it 'enables service[automacchanger]' do
    expect(subject).to enable_service('automacchanger')
  end
end
