diff options
author | Micah <micah@riseup.net> | 2016-11-04 13:18:22 +0000 |
---|---|---|
committer | Micah <micah@riseup.net> | 2016-11-04 13:18:22 +0000 |
commit | bd975e939717891b79fce1d7d91da4ce4528af12 (patch) | |
tree | b91c908b1fe6ab4cde4584fbd50d7aa45b2579a9 | |
parent | d4c87772bd31821c91f9ba149b5dc06959bc7155 (diff) | |
parent | 83c7034b8925d73a2c8157e2841ccf66c0ae23a7 (diff) |
Merge branch 'improve_tests' into 'master'
Improve tests
See merge request !53
-rw-r--r-- | .fixtures.yml | 6 | ||||
-rw-r--r-- | .gitignore | 5 | ||||
-rw-r--r-- | .gitlab-ci.yml | 39 | ||||
-rw-r--r-- | Gemfile | 4 | ||||
-rw-r--r-- | spec/classes/init_spec.rb | 18 | ||||
-rw-r--r-- | spec/defines/conf_spec.rb | 74 | ||||
-rw-r--r-- | spec/spec_helper.rb | 12 |
7 files changed, 141 insertions, 17 deletions
diff --git a/.fixtures.yml b/.fixtures.yml new file mode 100644 index 0000000..99efd66 --- /dev/null +++ b/.fixtures.yml @@ -0,0 +1,6 @@ +fixtures: + repositories: + "common": + "repo": "https://gitlab.com/shared-puppet-modules-group/common.git" + symlinks: + "apt": "#{source_dir}" @@ -1,10 +1,7 @@ /pkg/ /Gemfile.lock /vendor/ -/spec/fixtures/manifests/* -/spec/fixtures/modules/* -!/spec/fixtures/modules/apt -!/spec/fixtures/modules/apt/* +/spec/fixtures /log /.vagrant/ /.bundle/ diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index 2f381cd..49bf2e3 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -1,13 +1,42 @@ image: leapcode/ruby before_script: - - ruby -v - - sudo gem install bundler --no-ri --no-rdoc - - sudo bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}" + - "[ -d /var/cache/gitlab-runner ] || sudo mkdir /var/cache/gitlab-runner" + - sudo chown cirunner:cirunner -R /var/cache/gitlab-runner + - bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}" -# don't fail on lint warnings -rspec: +.job_template: &job_definition script: + # don't fail on lint warnings - bundle exec rake lint || /bin/true - bundle exec rake syntax - bundle exec rake validate - bundle exec rake spec + +# Default debian jessie versions +test:puppet37: + variables: + PUPPET_VERSION: "~> 3.7.2" + FACTER_VERSION: '~> 2.2.0' + <<: *job_definition + +test:puppet38_future_parser: + variables: + PUPPET_VERSION: '~> 3.8' + FACTER_VERSION: '~> 2.2.0' + FUTURE_PARSER: 'yes' + <<: *job_definition + +# Default debia stretch versions +test:puppet45: + variables: + PUPPET_VERSION: "~> 4.5.2" + FACTER_VERSION: '~> 2.4.6' + <<: *job_definition + +# Latest greatest +test:puppet4x: + variables: + PUPPET_VERSION: "> 4" + FACTER_VERSION: '> 2' + <<: *job_definition + @@ -2,8 +2,8 @@ source "https://rubygems.org" group :development, :unit_tests do gem "rake" - gem "rspec", '< 3.2.0' - gem "rspec-puppet" + gem "rspec-puppet", "~> 2.1", :require => false + gem "rspec-core", "3.1.7", :require => false gem "puppetlabs_spec_helper" gem "metadata-json-lint" gem "rspec-puppet-facts" diff --git a/spec/classes/init_spec.rb b/spec/classes/init_spec.rb new file mode 100644 index 0000000..9ba554f --- /dev/null +++ b/spec/classes/init_spec.rb @@ -0,0 +1,18 @@ +require 'spec_helper' + +describe 'apt', :type => :class do + let :pre_condition do + 'class { "apt": }' + end + let(:facts) { { + :lsbdistid => 'Debian', + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :debian_release => 'jessie', + :debian_codename => 'jessie', + :lsbdistcodename => 'jessie', + :virtual => 'physical', + :puppetversion => Puppet.version, } } + #it { is_expected.to compile.with_all_deps } + it { is_expected.to compile } +end diff --git a/spec/defines/conf_spec.rb b/spec/defines/conf_spec.rb new file mode 100644 index 0000000..cc4fb1f --- /dev/null +++ b/spec/defines/conf_spec.rb @@ -0,0 +1,74 @@ +require 'spec_helper' +describe 'apt::apt_conf', :type => :define do + let :pre_condition do + 'class { "apt": }' + end + let(:facts) { { + :lsbdistid => 'Debian', + :osfamily => 'Debian', + :operatingsystem => 'Debian', + :debian_release => 'jessie', + :debian_codename => 'jessie', + :lsbdistcodename => 'jessie', + :virtual => 'physical', + :puppetversion => Puppet.version, } } + let :title do + 'norecommends' + end + + describe "when creating an apt_conf snippet" do + let :default_params do + { + :ensure => 'present', + :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n" + } + end + let :params do + default_params + end + let :filename do + "/etc/apt/apt.conf.d/norecommends" + end + + it { is_expected.to contain_file(filename).with({ + 'ensure' => 'present', + 'content' => /Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;/, + 'owner' => 'root', + # default to '0', not 'root' + #'group' => 'root', + 'mode' => '0644', + }) + } + + end + + describe "when creating a preference without content" do + let :params do + { + :ensure => 'absent', + } + end + + it 'fails' do + expect { subject.call } .to raise_error(Puppet::Error, /One of \$source or \$content must be specified for apt_conf norecommends/) + end + end + + describe "when removing an apt preference" do + let :params do + { + :ensure => 'absent', + :content => "Apt::Install-Recommends 0;\nApt::AutoRemove::InstallRecommends 1;\n", + } + end + + let :filename do + "/etc/apt/apt.conf.d/norecommends" + end + + it { is_expected.to contain_file(filename).with({ + 'ensure' => 'absent', + }) + } + end +end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index 21d1a98..3cca63a 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -1,12 +1,12 @@ # https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge -require 'rspec-puppet' -require 'mocha/api' +require 'puppetlabs_spec_helper/module_spec_helper' -RSpec.configure do |c| +fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures')) - c.module_path = File.expand_path(File.join(File.dirname(__FILE__), '..', '..')) - c.color = true +RSpec.configure do |c| - #Puppet.features.stubs(:root? => true) + c.manifest_dir = File.join(fixture_path, 'manifests') + c.module_path = File.join(fixture_path, 'modules') + c.color = true end |