Skip to content

Commit

Permalink
Improve unit tests
Browse files Browse the repository at this point in the history
Ensure all tests can compile
Use parallel_spec for faster unit tests in travis
  • Loading branch information
treydock committed Sep 1, 2019
1 parent 7bd59b2 commit 2460d81
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 28 deletions.
1 change: 1 addition & 0 deletions .rspec
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
--format documentation
--format ParallelTests::RSpec::SummaryLogger
46 changes: 25 additions & 21 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,20 +15,24 @@ before_install:
- 'if [ -n "$encrypted_f942601034d6_key" -a -n "$encrypted_f942601034d6_iv" ]; then openssl aes-256-cbc -K $encrypted_f942601034d6_key -iv $encrypted_f942601034d6_iv -in tests/secrets.tar.enc -out tests/secrets.tar -d; cd tests && tar xvf secrets.tar ; fi'
sudo: false

script: 'SPEC_OPTS="--format documentation" bundle exec rake validate lint spec strings:generate reference'
script: 'bundle exec rake $CHECK'

matrix:
fast_finish: true
include:
- rvm: 2.4.4
env: PUPPET_GEM_VERSION="~> 5"
- rvm: 2.4.4
env: PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.4.5
env: CHECK="validate lint strings:generate reference" PUPPET_GEM_VERSION="~> 5"
- rvm: 2.5.3
env: PUPPET_GEM_VERSION="~> 6"
env: CHECK="validate lint strings:generate reference" PUPPET_GEM_VERSION="~> 6"
- rvm: 2.4.5
env: CHECK="parallel_spec" PUPPET_GEM_VERSION="~> 5"
- rvm: 2.4.5
env: CHECK="parallel_spec" PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.5.3
env: PUPPET_GEM_VERSION="~> 6" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.4.4
env: CHECK="parallel_spec" PUPPET_GEM_VERSION="~> 6"
- rvm: 2.5.3
env: CHECK="parallel_spec" PUPPET_GEM_VERSION="~> 6" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="centos-6" BEAKER_PUPPET_COLLECTION=puppet5
Expand All @@ -46,7 +50,7 @@ matrix:
env: BEAKER_set="centos-6" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="centos-7" BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_sensu_full=yes
Expand All @@ -64,7 +68,7 @@ matrix:
env: BEAKER_set="centos-7" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_full=yes BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="centos-7" BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_sensu_full=yes BEAKER_sensu_use_agent=yes
Expand All @@ -76,7 +80,7 @@ matrix:
env: BEAKER_set="centos-7" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_full=yes BEAKER_sensu_use_agent=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="centos-7-cluster" BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_sensu_cluster=yes
Expand All @@ -88,7 +92,7 @@ matrix:
env: BEAKER_set="centos-7-cluster" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_cluster=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="centos-7-cluster" BEAKER_PUPPET_COLLECTION=puppet5 BEAKER_sensu_cluster=yes BEAKER_sensu_use_agent=yes
Expand All @@ -106,7 +110,7 @@ matrix:
env: BEAKER_set="centos-7-cluster" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_cluster=yes BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="debian-9" BEAKER_PUPPET_COLLECTION=puppet5
Expand Down Expand Up @@ -136,7 +140,7 @@ matrix:
env: BEAKER_set="debian-10" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="ubuntu-1604" BEAKER_PUPPET_COLLECTION=puppet5
Expand All @@ -154,7 +158,7 @@ matrix:
env: BEAKER_set="ubuntu-1604" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="debian-8" BEAKER_PUPPET_COLLECTION=puppet5
Expand All @@ -172,7 +176,7 @@ matrix:
env: BEAKER_set="debian-8" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="ubuntu-1804" BEAKER_PUPPET_COLLECTION=puppet5
Expand All @@ -190,7 +194,7 @@ matrix:
env: BEAKER_set="ubuntu-1804" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="amazonlinux-2" BEAKER_PUPPET_COLLECTION=puppet5
Expand All @@ -208,7 +212,7 @@ matrix:
env: BEAKER_set="amazonlinux-2" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
bundler_args:
script: bundle exec rake beaker
- rvm: 2.4.4
- rvm: 2.4.5
sudo: required
services: docker
env: BEAKER_set="amazonlinux-201803" BEAKER_PUPPET_COLLECTION=puppet5
Expand All @@ -227,10 +231,10 @@ matrix:
bundler_args:
script: bundle exec rake beaker
allow_failures:
- rvm: 2.4.4
env: PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.4.5
env: CHECK="parallel_spec" PUPPET_GEM_VERSION="~> 5" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.5.3
env: PUPPET_GEM_VERSION="~> 6" FIXTURES_YML=".fixtures-latest.yml"
env: CHECK="parallel_spec" PUPPET_GEM_VERSION="~> 6" FIXTURES_YML=".fixtures-latest.yml"
- rvm: 2.5.3
env: BEAKER_set="centos-6" BEAKER_PUPPET_COLLECTION=puppet6 BEAKER_sensu_ci_build=yes
- rvm: 2.5.3
Expand Down
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ group :development, :unit_tests do
gem 'rspec-puppet', :require => false
gem 'rspec-puppet-facts', :require => false
gem 'rspec-mocks', :require => false
gem 'parallel_tests', :require => false
gem 'puppetlabs_spec_helper', :require => false
gem 'metadata-json-lint', :require => false
gem 'puppet-blacksmith', :require => false
Expand Down
6 changes: 6 additions & 0 deletions spec/classes/agent_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -157,6 +157,12 @@
let(:pre_condition) do
"class { 'sensu': manage_repo => false }"
end
# Unknown bug in rspec-puppet fails to compile windows paths
# when they are used for file source of sensu_ssl_ca, issue with windows mocking
# https://github.com/rodjek/rspec-puppet/issues/750
if facts[:os]['family'] != 'windows'
it { should compile.with_all_deps }
end
it { should contain_package('sensu-go-agent').without_require }
end

Expand Down
2 changes: 2 additions & 0 deletions spec/classes/backend_datastore_postgresql_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ class { '::sensu::backend':
END
content
end
it { should compile.with_all_deps }
it { should contain_file('/etc/sensu/postgresql.yaml').with_ensure('file').with_content(config_content) }
it { should contain_exec('sensuctl-postgresql').with_command('sensuctl delete --file /etc/sensu/postgresql.yaml') }
it { should_not contain_postgresql__server__db('sensu') }
Expand All @@ -103,6 +104,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should_not contain_postgresql__server__db('sensu') }
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/classes/backend_default_resources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
context "on #{os}" do
let(:facts) { facts }
context 'with default values for all parameters' do
it { should compile }
it { should compile.with_all_deps }
it { should have_sensu_namespace_resource_count(1) }
it { should contain_sensu_namespace('default').with_ensure('present') }
it { should have_sensu_user_resource_count(2) }
Expand Down
19 changes: 19 additions & 0 deletions spec/classes/backend_resources_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_ad_auth('ad') }
end
context 'assets defined' do
Expand All @@ -37,6 +38,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_asset('test') }
end
context 'checks defined' do
Expand All @@ -54,6 +56,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_check('test') }
end
context 'cluster_members defined' do
Expand All @@ -68,6 +71,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_cluster_member('test') }
end
context 'cluster_role_bindings defined' do
Expand All @@ -83,6 +87,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_cluster_role_binding('test') }
end
context 'cluster_roles defined' do
Expand All @@ -97,6 +102,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_cluster_role('test') }
end
context 'configs defined' do
Expand All @@ -111,6 +117,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_config('format') }
end
context 'entities defined' do
Expand All @@ -125,6 +132,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_entity('test') }
end
context 'events defined' do
Expand All @@ -137,6 +145,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_event('checkalive for test') }
end
context 'filters defined' do
Expand All @@ -152,6 +161,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_filter('test') }
end
context 'handlers defined' do
Expand All @@ -169,6 +179,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_handler('test') }
end
context 'hooks defined' do
Expand All @@ -181,6 +192,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_hook('test') }
end
context 'ldap_auths defined' do
Expand All @@ -198,6 +210,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_ldap_auth('ldap') }
end
context 'mutators defined' do
Expand All @@ -210,6 +223,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_mutator('test') }
end
context 'namespaces defined' do
Expand All @@ -222,6 +236,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_namespace('test') }
end
context 'role_bindings defined' do
Expand All @@ -237,6 +252,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_role_binding('test') }
end
context 'roles defined' do
Expand All @@ -251,6 +267,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_role('test') }
end
context 'silencings defined' do
Expand All @@ -263,6 +280,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_silenced('test') }
end
context 'users defined' do
Expand All @@ -275,6 +293,7 @@ class { '::sensu::backend':
}
EOS
end
it { should compile.with_all_deps }
it { should contain_sensu_user('test') }
end
end
Expand Down
Loading

0 comments on commit 2460d81

Please sign in to comment.