Skip to content

Commit 97815f8

Browse files
authored
Merge pull request puppetlabs#8 from glennsarti/add-acceptance-tests
(maint) Add acceptance tests
2 parents 6ea46e9 + cd2480b commit 97815f8

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

48 files changed

+3036
-21
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ AllCops:
1010
# package testing gems
1111
- package-testing/vendor/**/*
1212
- package-testing/vendor/**/.*
13+
# Any thing in test fixtures
14+
- spec/fixtures/**/*
1315

1416
# Metrics, excludes complexity and sizing metrics for now, as ruby's defaults are very strict
1517
Metrics/AbcSize:

Gemfile

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,25 @@ source 'https://rubygems.org'
55
# Specify your gem's dependencies in puppet-modulebuilder.gemspec
66
gemspec
77

8-
gem 'rake', '~> 12.0'
9-
gem 'rspec', '~> 3.0'
10-
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')
11-
gem 'rubocop', '~> 0.68'
12-
gem 'rubocop-rspec', '~> 1.38'
8+
group :development do
9+
gem 'rake', '~> 12.0'
10+
gem 'rspec', '~> 3.0'
11+
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.3.0')
12+
gem 'rubocop', '~> 0.68'
13+
gem 'rubocop-rspec', '~> 1.38'
1314

14-
gem 'codecov', '~> 0.1'
15-
gem 'simplecov', '~> 0.18'
16-
gem 'simplecov-console', '~> 0.6'
15+
gem 'codecov', '~> 0.1'
16+
gem 'simplecov', '~> 0.18'
17+
gem 'simplecov-console', '~> 0.6'
18+
end
19+
20+
if Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.5.0')
21+
gem 'puppet', '~> 6.0'
22+
elsif Gem::Version.new(RUBY_VERSION.dup) >= Gem::Version.new('2.4.0')
23+
gem 'puppet', '~> 5.0' # rubocop:disable Bundler/DuplicatedGem Nope, not a duplicate!
24+
else
25+
gem 'puppet', '~> 4.0' # rubocop:disable Bundler/DuplicatedGem Nope, not a duplicate!
26+
end
1727
end
1828

1929
# Evaluate Gemfile.local and ~/.gemfile if they exist

Rakefile

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,12 @@ rescue LoadError => e
1515
puts "Can't load 'rubocop/rake_task': #{e.inspect}"
1616
end
1717

18-
RSpec::Core::RakeTask.new(:spec)
18+
RSpec::Core::RakeTask.new(:spec) do |t|
19+
t.pattern = 'spec/unit/**/*_spec.rb'
20+
end
21+
22+
RSpec::Core::RakeTask.new(:acceptance) do |t|
23+
t.pattern = 'spec/acceptance/**/*_spec.rb'
24+
end
1925

20-
task default: [:spec]
26+
task default: [:spec, :acceptance]
Lines changed: 94 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,100 @@
11
# frozen_string_literal: true
22

3-
require 'spec_helper'
3+
require 'spec_helper_acceptance'
44
require 'puppet/modulebuilder/builder'
5+
require 'tmpdir'
56

67
RSpec.describe Puppet::Modulebuilder::Builder do
7-
pending('Requires some acceptance tests to actually build a module and check the output')
8-
9-
# spec_helper_acceptance
10-
# - downloads an example module from git (maybe puppetlabs-stdlib?)
11-
# - places it in fixtures directory
12-
#
13-
# context 'for a real module' do
14-
# it 'creates the tarball'; end
15-
# it 'has the same content as the source'; end
16-
# end
8+
RSpec.shared_context 'with module source' do
9+
let(:tmp_module_dir) { Dir.mktmpdir }
10+
let(:module_source) { File.join(tmp_module_dir, File.basename(MODULE_FIXTURE)) }
11+
12+
before(:each) do
13+
# Copy the module
14+
FileUtils.cp_r(MODULE_FIXTURE, tmp_module_dir)
15+
end
16+
17+
after(:each) do
18+
FileUtils.rm_rf(tmp_module_dir) if Dir.exist?(tmp_module_dir)
19+
end
20+
end
21+
22+
let(:logger) { nil }
23+
24+
context 'with a real module that is built' do
25+
include_context 'with module source'
26+
27+
let(:tarball_name) do
28+
builder = described_class.new(module_source, tmp_module_dir, nil)
29+
builder.build
30+
end
31+
32+
it 'builds the module and returns the path to the tarball' do
33+
expect(tarball_name).to match(%r{#{tmp_module_dir}})
34+
end
35+
36+
context 'which is installed via Puppet' do
37+
let(:extract_path) { Dir.mktmpdir }
38+
let(:extracted_module_path) { File.join(extract_path, Dir.entries(extract_path).reject { |p| %w[. ..].include?(p) }.first) }
39+
40+
RSpec::Matchers.define :be_an_empty_glob do
41+
match do |actual|
42+
Dir.glob(extracted_module_path + actual).empty?
43+
end
44+
45+
failure_message do |actual|
46+
"expected that #{actual} would be empty but got #{Dir.glob(extracted_module_path + actual)}"
47+
end
48+
end
49+
50+
RSpec::Matchers.define :be_identical_as_soource do
51+
match do |actual|
52+
# Dir.glob(..., base: xxx) does not work, so need to use a crude method to get the relative directory path
53+
@source = Dir.glob(module_source + actual).map { |p| p.slice(module_source.length..-1) }
54+
@extracted = Dir.glob(extracted_module_path + actual).map { |p| p.slice(extracted_module_path.length..-1) }
55+
56+
@source == @extracted
57+
end
58+
59+
failure_message do
60+
"expected #{@source} but got #{@extracted}"
61+
end
62+
end
63+
64+
before(:each) do
65+
# Force the module to be built...
66+
built_tarball = tarball_name
67+
68+
# Use puppet to "install" it...
69+
require 'open3'
70+
output, status = Open3.capture2e("puppet module install --force --ignore-dependencies --target-dir #{extract_path} --verbose #{built_tarball}")
71+
72+
raise "Failed to install the module using Puppet. Exit code #{status.exitstatus}: #{output}" unless status.exitstatus.zero?
73+
raise 'Failed to install the module using Puppet. Missing extract directory' if extracted_module_path.nil?
74+
end
75+
76+
after(:each) do
77+
FileUtils.rm_rf(extract_path) if Dir.exist?(extract_path)
78+
end
79+
80+
it 'expands the expected paths' do # rubocop:disable RSpec/MultipleExpectations This is expected
81+
# No development directories
82+
expect('/spec/*').to be_an_empty_glob
83+
expect('/.vscode/*').to be_an_empty_glob
84+
expect('/tmp/*').to be_an_empty_glob
85+
# No development files
86+
expect('/.fixtures').to be_an_empty_glob
87+
expect('/.gitignore').to be_an_empty_glob
88+
expect('/Rakefile').to be_an_empty_glob
89+
# No CI files
90+
expect('/.travis.yml').to be_an_empty_glob
91+
expect('/appveyor.yml').to be_an_empty_glob
92+
93+
# Important Extracted files
94+
expect('/manifests/*').to be_identical_as_soource
95+
expect('/templates/*').to be_identical_as_soource
96+
expect('/lib/*').to be_identical_as_soource
97+
end
98+
end
99+
end
17100
end

spec/fixtures/module/.fixtures.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
fixtures:
2+
repositories:
3+
facts: 'https://github.com/puppetlabs/puppetlabs-facts.git'
4+
provision: 'https://github.com/puppetlabs/provision.git'
5+
puppet_agent: 'https://github.com/puppetlabs/puppetlabs-puppet_agent.git'
6+
registry: 'https://github.com/puppetlabs/puppetlabs-registry.git'
7+
translate: 'https://github.com/puppetlabs/puppetlabs-translate.git'
8+
stdlib: 'https://github.com/puppetlabs/puppetlabs-stdlib.git'
9+
symlinks:
10+
motd: "#{source_dir}"

spec/fixtures/module/.gitattributes

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
*.rb eol=lf
2+
*.erb eol=lf
3+
*.pp eol=lf
4+
*.sh eol=lf
5+
*.epp eol=lf
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
name: "release"
2+
3+
on:
4+
push:
5+
branches:
6+
- 'release'
7+
8+
jobs:
9+
LitmusAcceptance:
10+
env:
11+
HONEYCOMB_WRITEKEY: 7f3c63a70eecc61d635917de46bea4e6
12+
HONEYCOMB_DATASET: litmus tests
13+
runs-on: self-hosted
14+
strategy:
15+
matrix:
16+
ruby_version: [2.5.x]
17+
puppet_gem_version: [~> 6.0]
18+
platform: [release_checks]
19+
agent_family: ['puppet5', 'puppet6']
20+
21+
steps:
22+
- uses: actions/checkout@v1
23+
- name: Litmus Parallel
24+
uses: puppetlabs/action-litmus_parallel@master
25+
with:
26+
platform: ${{ matrix.platform }}
27+
agent_family: ${{ matrix.agent_family }}
28+
Spec:
29+
runs-on: self-hosted
30+
strategy:
31+
matrix:
32+
check: [parallel_spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop']
33+
ruby_version: [2.5.x]
34+
puppet_gem_version: [~> 5.0, ~> 6.0]
35+
exclude:
36+
- puppet_gem_version: ~> 5.0
37+
check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'
38+
- ruby_version: 2.5.x
39+
puppet_gem_version: ~> 5.0
40+
steps:
41+
- uses: actions/checkout@v1
42+
- name: Spec Tests
43+
uses: puppetlabs/action-litmus_spec@master
44+
with:
45+
puppet_gem_version: ${{ matrix.puppet_gem_version }}
46+
check: ${{ matrix.check }}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
name: "weekly"
2+
3+
on:
4+
schedule:
5+
- cron: '0 0 * * 6'
6+
7+
jobs:
8+
LitmusAcceptance:
9+
runs-on: self-hosted
10+
strategy:
11+
matrix:
12+
ruby_version: [2.5.x]
13+
puppet_gem_version: [~> 6.0]
14+
platform: [release_checks]
15+
agent_family: ['puppet5', 'puppet6']
16+
17+
steps:
18+
- uses: actions/checkout@v1
19+
- name: Litmus Parallel
20+
uses: puppetlabs/action-litmus_parallel@master
21+
with:
22+
platform: ${{ matrix.platform }}
23+
agent_family: ${{ matrix.agent_family }}
24+
Spec:
25+
runs-on: self-hosted
26+
strategy:
27+
matrix:
28+
check: [spec, 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop']
29+
ruby_version: [2.5.x]
30+
puppet_gem_version: [~> 5.0, ~> 6.0]
31+
exclude:
32+
- puppet_gem_version: ~> 5.0
33+
check: 'syntax lint metadata_lint check:symlinks check:git_ignore check:dot_underscore check:test_file rubocop'
34+
- ruby_version: 2.5.x
35+
puppet_gem_version: ~> 5.0
36+
steps:
37+
- uses: actions/checkout@v1
38+
- name: Spec Tests
39+
uses: puppetlabs/action-litmus_spec@master
40+
with:
41+
puppet_gem_version: ${{ matrix.puppet_gem_version }}
42+
check: ${{ matrix.check }}

spec/fixtures/module/.gitignore

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
.git/
2+
.*.sw[op]
3+
.metadata
4+
.yardoc
5+
.yardwarns
6+
*.iml
7+
/.bundle/
8+
/.idea/
9+
/.vagrant/
10+
/coverage/
11+
/bin/
12+
/doc/
13+
/Gemfile.local
14+
/Gemfile.lock
15+
/junit/
16+
/log/
17+
/pkg/
18+
/spec/fixtures/manifests/
19+
/spec/fixtures/modules/
20+
/tmp/
21+
/vendor/
22+
/convert_report.txt
23+
/update_report.txt
24+
.DS_Store
25+
.project
26+
.envrc
27+
/inventory.yaml

spec/fixtures/module/.pdkignore

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
.git/
2+
.*.sw[op]
3+
.metadata
4+
.yardoc
5+
.yardwarns
6+
*.iml
7+
/.bundle/
8+
/.idea/
9+
/.vagrant/
10+
/coverage/
11+
/bin/
12+
/doc/
13+
/Gemfile.local
14+
/Gemfile.lock
15+
/junit/
16+
/log/
17+
/pkg/
18+
/spec/fixtures/manifests/
19+
/spec/fixtures/modules/
20+
/tmp/
21+
/vendor/
22+
/convert_report.txt
23+
/update_report.txt
24+
.DS_Store
25+
.project
26+
.envrc
27+
/inventory.yaml
28+
/appveyor.yml
29+
/.fixtures.yml
30+
/Gemfile
31+
/.gitattributes
32+
/.gitignore
33+
/.gitlab-ci.yml
34+
/.pdkignore
35+
/Rakefile
36+
/rakelib/
37+
/.rspec
38+
/.rubocop.yml
39+
/.travis.yml
40+
/.yardopts
41+
/spec/
42+
/.vscode/

spec/fixtures/module/.pmtignore

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
docs/
2+
pkg/
3+
Gemfile.lock
4+
Gemfile.local
5+
vendor/
6+
.vendor/
7+
spec/fixtures/manifests/
8+
spec/fixtures/modules/
9+
.vagrant/
10+
.bundle/
11+
.ruby-version
12+
coverage/
13+
log/
14+
.idea/
15+
.dependencies/
16+
.librarian/
17+
Puppetfile.lock
18+
*.iml
19+
.*.sw?
20+
.yardoc/

spec/fixtures/module/.puppet-lint.rc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
--relative

spec/fixtures/module/.rspec

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
--color
2+
--format documentation
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
GetText/DecorateString:
2+
Enabled: false

0 commit comments

Comments
 (0)