# encoding: utf-8

describe 'et_nginx::http_geoip_module' do
  cached(:chef_run) do
    ChefSpec::SoloRunner.new do |node|
      node.set['nginx']['modules'] = ['et_nginx::http_geoip_module']
    end.converge(described_recipe)
  end

  it 'retrieves remote files to cache' do
    geoip_version = chef_run.node.attributes['nginx']['geoip']['lib_version']

    expect(chef_run).to create_remote_file("#{Chef::Config['file_cache_path']}/GeoIP-#{geoip_version}.tar.gz")
    expect(chef_run).to create_remote_file("#{Chef::Config['file_cache_path']}/GeoIP.dat.gz")
    expect(chef_run).to create_remote_file("#{Chef::Config['file_cache_path']}/GeoLiteCity.dat.gz")
  end

  it 'creates lib directory' do
    expect(chef_run).to create_directory('/srv/geoip')
  end

  it 'expands the retrieved files' do
    expect(chef_run).to run_bash('extract_geolib')
    expect(chef_run).to run_bash('gunzip_geo_lite_country_dat')
    expect(chef_run).to run_bash('gunzip_geo_lite_city_dat')
  end

  it 'creates config file' do
    expect(chef_run).to create_template('/etc/nginx/conf.d/http_geoip.conf')
  end
end

# encoding: utf-8

describe 'et_nginx::module_http_geoip' do
  cached(:chef_run) do
    ChefSpec::SoloRunner.new do |node|
      node.set['nginx']['modules'] = ['et_nginx::module_http_geoip']
    end.converge(described_recipe)
  end

  it 'retrieves remote files to cache' do
    geoip_version = chef_run.node.attributes['nginx']['geoip']['lib_version']

    expect(chef_run).to create_remote_file("#{Chef::Config['file_cache_path']}/GeoIP-#{geoip_version}.tar.gz")
    expect(chef_run).to create_remote_file("#{Chef::Config['file_cache_path']}/GeoIP.dat.gz")
    expect(chef_run).to create_remote_file("#{Chef::Config['file_cache_path']}/GeoLiteCity.dat.gz")
  end

  it 'creates lib directory' do
    expect(chef_run).to create_directory('/srv/geoip')
  end

  it 'expands the retrieved files' do
    expect(chef_run).to run_bash('extract_geolib')
    expect(chef_run).to run_bash('gunzip_geo_lite_country_dat')
    expect(chef_run).to run_bash('gunzip_geo_lite_city_dat')
  end

  it 'creates config file' do
    expect(chef_run).to create_template('/etc/nginx/conf.d/http_geoip.conf')
  end
end

Fix module recipe name in geoip spec test
Fix module recipe name in geoip spec test
