Skip to content

Commit

Permalink
Fixes for the specs
Browse files Browse the repository at this point in the history
Signed-off-by: Tim Smith <tsmith@chef.io>
  • Loading branch information
tas50 committed Apr 29, 2018
1 parent c5e13e9 commit 75993ff
Show file tree
Hide file tree
Showing 6 changed files with 10 additions and 62 deletions.
2 changes: 1 addition & 1 deletion recipes/_install_package.rb
Expand Up @@ -30,7 +30,7 @@
cache_rebuild node['grafana']['package']['apt_rebuild']
trusted node['grafana']['package']['trusted']
end

package 'grafana' do
version node['grafana']['package']['version']
options '-o Dpkg::Options::="--force-confdef" -o Dpkg::Options::="--force-confold"'
Expand Down
2 changes: 0 additions & 2 deletions spec/spec_helper.rb
@@ -1,4 +1,2 @@
require 'chefspec'
require 'chefspec/berkshelf'

at_exit { ChefSpec::Coverage.report! }
15 changes: 4 additions & 11 deletions spec/unit/default_spec.rb
Expand Up @@ -40,7 +40,7 @@
stub_command 'which nginx'
end

let(:chef_run) do
cached(:chef_run) do
ChefSpec::SoloRunner.new(chef_solo_opts).converge described_recipe
end

Expand Down Expand Up @@ -125,8 +125,7 @@
expect(chef_run).to create_remote_file "/var/chef/cache/grafana-#{grafana_version}.rpm"
expect(chef_run).to install_rpm_package "grafana-#{grafana_version}"
else
expect(chef_run).to install_package 'adduser'
expect(chef_run).to install_package 'libfontconfig'
expect(chef_run).to install_package %(adduser, libfontconfig)
expect(chef_run).to create_remote_file "/var/chef/cache/grafana-#{grafana_version}.deb"
expect(chef_run).to install_dpkg_package "grafana-#{grafana_version}"
end
Expand All @@ -141,10 +140,7 @@
end

it 'generate grafana.ini' do
expect(chef_run).to create_template('/etc/grafana/grafana.ini').with(
mode: '0644',
user: 'root'
)
expect(chef_run).to create_template('/etc/grafana/grafana.ini')

expect(chef_run).to render_file('/etc/grafana/grafana.ini').with_content(/^\[database\]/)
expect(chef_run).to render_file('/etc/grafana/grafana.ini').with_content(%r{^data = /var/lib/grafana})
Expand Down Expand Up @@ -202,10 +198,7 @@
end

it 'generate grafana.ini' do
expect(chef_run).to create_template('/etc/grafana/grafana.ini').with(
mode: '0644',
user: 'root'
)
expect(chef_run).to create_template('/etc/grafana/grafana.ini')
expect(chef_run).to render_file('/etc/grafana/grafana.ini').with_content(/^\[database\]/)
expect(chef_run).to render_file('/etc/grafana/grafana.ini').with_content(%r{^data = /var/lib/grafana})
expect(chef_run).to render_file('/etc/grafana/grafana.ini').with_content(/^host = 127.0.0.1:3306/)
Expand Down
4 changes: 2 additions & 2 deletions spec/unit/install_package_spec.rb
Expand Up @@ -19,7 +19,7 @@
stub_command('which nginx').and_return('1')
end
context "on #{platform} #{version}" do
let(:chef_run) do
cached(:chef_run) do
ChefSpec::SoloRunner.new(platform: platform, version: version) do |node|
node.override['grafana']['install_type'] = 'package'
end.converge 'grafana::default'
Expand All @@ -41,7 +41,7 @@
end
end
context "on #{platform} #{version} with grafana version older than 2.0.2" do
let(:chef_run) do
cached(:chef_run) do
ChefSpec::SoloRunner.new(platform: platform, version: version) do |node|
node.override['grafana']['install_type'] = 'package'
node.override['grafana']['file']['version'] = '2.0.1'
Expand Down
34 changes: 0 additions & 34 deletions spec/unit/install_source_spec.rb

This file was deleted.

15 changes: 3 additions & 12 deletions spec/unit/nginx_spec.rb
@@ -1,20 +1,11 @@
require 'spec_helper'

describe 'grafana::_nginx' do
let(:chef_run) do
cached(:chef_run) do
ChefSpec::SoloRunner.new.converge described_recipe
end

it 'creates a template with attributes' do
stub_command('which nginx').and_return('/usr/bin/nginx')
expect(chef_run).to create_template('/etc/nginx/sites-available/grafana')
end

it 'creates a template with auth basic attributes' do
stub_command('which nginx').and_return('/usr/bin/nginx')
chef_run.node.override['grafana']['nginx']['auth_basic'] = true
chef_run.converge(described_recipe)
expect(chef_run).to create_template('/etc/nginx/sites-available/grafana')
expect(chef_run).to render_file('/etc/nginx/sites-available/grafana').with_content(/auth_basic_user_file.+/)
it 'enables a nginx site' do
expect(chef_run).to enable_nginx_site('Grafana')
end
end

0 comments on commit 75993ff

Please sign in to comment.