require 'spec_helper'

describe 'apt::cacher-client' do
  context 'no server' do
    let(:chef_run) { ChefSpec::ServerRunner.new.converge(described_recipe) }

    # it 'does not create 01proxy file' do
    #   expect(chef_run).not_to create_file('/etc/apt/apt.conf.d/01proxy')
    # end
  end

  context 'server provided' do
    let(:chef_run) do
      runner = ChefSpec::ServerRunner.new
      runner.node.set['apt']['cacher_ipaddress'] = '22.33.44.55'
      runner.node.set['apt']['cacher_port'] = '9876'
      runner.converge('apt::cacher-client')
    end

    # it 'creates 01proxy file' do
    #   expect(chef_run).to render_file('/etc/apt/apt.conf.d/01proxy').with_content()
    #   expect(chef_run).to create_file_with_content('/etc/apt/apt.conf.d/01proxy', 'Acquire::http::Proxy "http://22.33.44.55:9876";')
    # end
  end
end

require 'spec_helper'

describe 'apt::cacher-client' do
  context 'no server' do
    let(:chef_run) { ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04').converge(described_recipe) }

    before do
      stub_command("grep Acquire::http::Proxy /etc/apt/apt.conf").and_return(false)
    end

    it 'does not create 01proxy file' do
      expect(chef_run).not_to create_file('/etc/apt/apt.conf.d/01proxy')
    end
  end

  context 'server provided' do
    let(:chef_run) do
      runner = ChefSpec::ServerRunner.new(platform: 'ubuntu', version: '16.04')
      runner.node.set['apt']['cacher_client']['cacher_server'] = {
        host: 'localhost',
        port: 9876,
        proxy_ssl: true
      }
      runner.converge('apt::cacher-client')
    end

    before do
      stub_command("grep Acquire::http::Proxy /etc/apt/apt.conf").and_return(false)
    end

    it 'creates 01proxy file' do
      expect(chef_run).to render_file('/etc/apt/apt.conf.d/01proxy').with_content('Acquire::http::Proxy "http://localhost:9876";')
    end
  end
end

Fix the cacher client specs
Fix the cacher client specs

Signed-off-by: Tim Smith <764ef62106582a09ed09dfa0b6bff7c05fd7d1e4@chef.io>
