summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLouis-Philippe VĂ©ronneau <pollito@riseup.net>2017-10-11 15:52:10 -0400
committerLouis-Philippe VĂ©ronneau <pollito@riseup.net>2017-10-11 15:52:10 -0400
commit10767a0016b0f46aceab9ac97738390035a112dc (patch)
tree53db5cf52694e7e4e09b37479c04e04693a4533c
parent5ef29012dccc90e68afc215be9521629a0903bc6 (diff)
copy CI infra from the shared apt module as-is
-rw-r--r--.fixtures.yml6
-rw-r--r--.gitlab-ci.yml39
-rw-r--r--Gemfile22
-rw-r--r--Rakefile19
-rw-r--r--spec/acceptance/apt_spec.rb21
-rw-r--r--spec/acceptance/nodesets/debian-8-x86_64-docker.yml19
l---------spec/acceptance/nodesets/default.yml1
-rw-r--r--spec/classes/init_spec.rb18
-rw-r--r--spec/defines/conf_spec.rb74
-rw-r--r--spec/defines/preferences_snippet_spec.rb66
-rw-r--r--spec/spec_helper.rb12
-rw-r--r--spec/spec_helper_acceptance.rb18
-rw-r--r--spec/unit/custom_facts_spec.rb86
13 files changed, 401 insertions, 0 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}"
diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml
new file mode 100644
index 0000000..05430fd
--- /dev/null
+++ b/.gitlab-ci.yml
@@ -0,0 +1,39 @@
+image: ruby:2.1
+before_script:
+ - bundle install --jobs $(nproc) --without system_tests --path=/var/cache/gitlab-runner/ "${FLAGS[@]}"
+
+.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
diff --git a/Gemfile b/Gemfile
new file mode 100644
index 0000000..226d7ae
--- /dev/null
+++ b/Gemfile
@@ -0,0 +1,22 @@
+source "https://rubygems.org"
+
+group :development, :unit_tests do
+ gem "rake"
+ gem "rspec-puppet", "~> 2.1", :require => false
+ gem "rspec-core"
+ gem "puppetlabs_spec_helper"
+ gem "metadata-json-lint"
+ gem "rspec-puppet-facts"
+ gem "mocha"
+end
+
+group :system_tests do
+ gem 'beaker'
+ gem 'beaker-rspec'
+ gem 'beaker_spec_helper'
+ gem 'serverspec'
+end
+
+gem "puppet", ENV['PUPPET_VERSION'] || ENV['GEM_PUPPET_VERSION'] || ENV['PUPPET_GEM_VERSION'] || '~> 3.7.0'
+gem "facter", ENV['FACTER_VERSION'] || ENV['GEM_FACTER_VERSION'] || ENV['FACTER_GEM_VERSION'] || '~> 2.2.0'
+
diff --git a/Rakefile b/Rakefile
new file mode 100644
index 0000000..85326bb
--- /dev/null
+++ b/Rakefile
@@ -0,0 +1,19 @@
+require 'puppetlabs_spec_helper/rake_tasks'
+require 'puppet-lint/tasks/puppet-lint'
+PuppetLint.configuration.send('disable_80chars')
+PuppetLint.configuration.ignore_paths = ["spec/**/*.pp", "pkg/**/*.pp"]
+
+desc "Validate manifests, templates, and ruby files"
+task :validate do
+ Dir['manifests/**/*.pp'].each do |manifest|
+ sh "puppet parser validate --noop #{manifest}"
+ end
+ Dir['spec/**/*.rb','lib/**/*.rb'].each do |ruby_file|
+ sh "ruby -c #{ruby_file}" unless ruby_file =~ /spec\/fixtures/
+ end
+ Dir['templates/**/*.erb'].each do |template|
+ sh "erb -P -x -T '-' #{template} | ruby -c"
+ end
+end
+
+task :test => [:lint, :syntax , :validate, :spec]
diff --git a/spec/acceptance/apt_spec.rb b/spec/acceptance/apt_spec.rb
new file mode 100644
index 0000000..a976a56
--- /dev/null
+++ b/spec/acceptance/apt_spec.rb
@@ -0,0 +1,21 @@
+require 'spec_helper_acceptance'
+
+describe 'apt class' do
+
+ context 'default parameters' do
+ it 'should work idempotently with no errors' do
+ pp = <<-EOS
+ class { 'apt': }
+ EOS
+
+ # Run it twice and test for idempotency
+ apply_manifest(pp, :catch_failures => true)
+ apply_manifest(pp, :catch_changes => true)
+ end
+
+ describe package('apt') do
+ it { is_expected.to be_installed }
+ end
+
+ end
+end
diff --git a/spec/acceptance/nodesets/debian-8-x86_64-docker.yml b/spec/acceptance/nodesets/debian-8-x86_64-docker.yml
new file mode 100644
index 0000000..f09ad62
--- /dev/null
+++ b/spec/acceptance/nodesets/debian-8-x86_64-docker.yml
@@ -0,0 +1,19 @@
+HOSTS:
+ debian-8-x64:
+ platform: debian-8-amd64
+ image: debian:8
+ hypervisor: docker
+ docker_preserve_image: true
+ docker_cmd: '["/sbin/init"]'
+ docker_image_commands:
+ - 'apt-get install -y wget locales-all puppet git'
+ - 'rm -f /usr/sbin/policy-rc.d'
+
+CONFIG:
+ type: foss
+ #log_level: verbose
+ #log_level: debug
+
+ssh:
+ password: root
+ auth_methods: ["password"]
diff --git a/spec/acceptance/nodesets/default.yml b/spec/acceptance/nodesets/default.yml
new file mode 120000
index 0000000..b125a96
--- /dev/null
+++ b/spec/acceptance/nodesets/default.yml
@@ -0,0 +1 @@
+debian-8-x86_64-docker.yml \ No newline at end of file
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/defines/preferences_snippet_spec.rb b/spec/defines/preferences_snippet_spec.rb
new file mode 100644
index 0000000..012a5f6
--- /dev/null
+++ b/spec/defines/preferences_snippet_spec.rb
@@ -0,0 +1,66 @@
+require 'spec_helper'
+describe 'apt::preferences_snippet', :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
+ 'test'
+ end
+
+ describe "when creating a preferences_snippet" do
+ let :default_params do
+ {
+ :ensure => 'present',
+ :release => "jessie-backports",
+ :priority => '999'
+ }
+ end
+ let :params do
+ default_params
+ end
+ let :filename do
+ "/etc/apt/preferences.d/test"
+ end
+
+ it { is_expected.to contain_file(filename).with({
+ 'ensure' => 'present',
+ 'content' => /Package: test\nPin: release a=jessie-backports\nPin-Priority: 999/,
+ 'owner' => 'root',
+ 'group' => '0',
+ 'mode' => '0644',
+ })
+ }
+
+ end
+
+ describe "when using both pin and release parameters" do
+ let :default_params do
+ {
+ :ensure => 'present',
+ :priority => '999',
+ :release => "jessie-backports",
+ :pin => '1.0'
+ }
+ end
+ let :params do
+ default_params
+ end
+ let :filename do
+ "/etc/apt/preferences.d/test"
+ end
+
+ it 'fails' do
+ expect { subject.call } .to raise_error(Puppet::Error, /apt::preferences_snippet requires either a 'pin' or 'release' argument, not both/)
+ end
+ end
+
+end
diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb
new file mode 100644
index 0000000..3cca63a
--- /dev/null
+++ b/spec/spec_helper.rb
@@ -0,0 +1,12 @@
+# https://puppetlabs.com/blog/testing-modules-in-the-puppet-forge
+require 'puppetlabs_spec_helper/module_spec_helper'
+
+fixture_path = File.expand_path(File.join(__FILE__, '..', 'fixtures'))
+
+RSpec.configure do |c|
+
+ c.manifest_dir = File.join(fixture_path, 'manifests')
+ c.module_path = File.join(fixture_path, 'modules')
+
+ c.color = true
+end
diff --git a/spec/spec_helper_acceptance.rb b/spec/spec_helper_acceptance.rb
new file mode 100644
index 0000000..1ccd84d
--- /dev/null
+++ b/spec/spec_helper_acceptance.rb
@@ -0,0 +1,18 @@
+require 'beaker-rspec'
+
+RSpec.configure do |c|
+ module_root = File.expand_path(File.join(File.dirname(__FILE__), '..'))
+ module_name = module_root.split('-').last
+
+ # Readable test descriptions
+ c.formatter = :documentation
+
+ # Configure all nodes in nodeset
+ c.before :suite do
+ # Install module and dependencies
+ puppet_module_install(:source => module_root, :module_name => module_name)
+ hosts.each do |host|
+ shell('git clone https://gitlab.com/shared-puppet-modules-group/common.git /etc/puppet/modules/common')
+ end
+ end
+end
diff --git a/spec/unit/custom_facts_spec.rb b/spec/unit/custom_facts_spec.rb
new file mode 100644
index 0000000..9a28d92
--- /dev/null
+++ b/spec/unit/custom_facts_spec.rb
@@ -0,0 +1,86 @@
+require "spec_helper"
+
+describe "Facter::Util::Fact" do
+ before {
+ Facter.clear
+ }
+
+ describe 'custom facts' do
+
+ context 'Debian 7' do
+ before do
+ Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("7.8")
+ Facter.fact(:lsbdistcodename).stubs(:value).returns("wheezy")
+ end
+
+ it "debian_release = oldstable" do
+ expect(Facter.fact(:debian_release).value).to eq('oldstable')
+ end
+
+ it "debian_codename = wheezy" do
+ expect(Facter.fact(:debian_codename).value).to eq('wheezy')
+ end
+
+ it "debian_nextcodename = jessie" do
+ expect(Facter.fact(:debian_nextcodename).value).to eq('jessie')
+ end
+
+ it "debian_nextrelease = stable" do
+ expect(Facter.fact(:debian_nextrelease).value).to eq('stable')
+ end
+ end
+
+ context 'Debian 8' do
+ before do
+ Facter.fact(:operatingsystem).stubs(:value).returns("Debian")
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("8.0")
+ Facter.fact(:lsbdistcodename).stubs(:value).returns("jessie")
+ end
+
+ it "debian_release = stable" do
+ expect(Facter.fact(:debian_release).value).to eq('stable')
+ end
+
+ it "debian_codename = jessie" do
+ expect(Facter.fact(:debian_codename).value).to eq('jessie')
+ end
+
+ it "debian_nextcodename = stretch" do
+ expect(Facter.fact(:debian_nextcodename).value).to eq('stretch')
+ end
+
+ it "debian_nextrelease = testing" do
+ expect(Facter.fact(:debian_nextrelease).value).to eq('testing')
+ end
+ end
+
+ context 'Ubuntu 15.10' do
+ before do
+ Facter.fact(:operatingsystem).stubs(:value).returns("Ubuntu")
+ Facter.fact(:operatingsystemrelease).stubs(:value).returns("15.10")
+ Facter.fact(:lsbdistcodename).stubs(:value).returns("wily")
+ end
+
+ it "ubuntu_codename = wily" do
+ expect(Facter.fact(:ubuntu_codename).value).to eq('wily')
+ end
+
+ it "ubuntu_nextcodename = xenial" do
+ expect(Facter.fact(:ubuntu_nextcodename).value).to eq('xenial')
+ end
+ end
+ end
+
+ describe "Test 'apt_running' fact" do
+ it "should return true when apt-get is running" do
+ Facter::Util::Resolution.stubs(:exec).with("pgrep apt-get >/dev/null 2>&1 && echo true || echo false").returns("true")
+ expect(Facter.fact(:apt_running).value).to eq('true')
+ end
+ it "should return false when apt-get is not running" do
+ Facter::Util::Resolution.stubs(:exec).with("pgrep apt-get >/dev/null 2>&1 && echo true || echo false").returns("false")
+ expect(Facter.fact(:apt_running).value).to eq('false')
+ end
+ end
+
+end