Skip to content

Commit 3769b1e

Browse files
authored
Merge pull request #58 from puppetlabs/maint-add_acceptance_tests
Maint add acceptance tests
2 parents 3670bb7 + 5f80b77 commit 3769b1e

File tree

55 files changed

+121
-6
lines changed

Some content is hidden

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

55 files changed

+121
-6
lines changed

.fixtures.yml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
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+
symlinks: []

.github/workflows/ci.yml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,5 @@ on:
1414
jobs:
1515
ci:
1616
uses: "puppetlabs/cat-github-actions/.github/workflows/gem_ci.yml@main"
17-
with:
18-
with_acceptance: false
1917
secrets: "inherit"
2018

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ coverage/
1111
/*.pp
1212
/tmp/
1313
.vendor/
14+
spec/fixtures/

Gemfile

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,18 @@ group :test do
1515
gem 'simplecov', :require => false if ENV['COVERAGE'] == 'yes'
1616
end
1717

18+
group :acceptance do
19+
gem 'serverspec'
20+
gem 'puppetlabs_spec_helper'
21+
gem 'puppet_litmus'
22+
end
23+
1824
group :development do
1925
gem 'github_changelog_generator', require: false
2026
gem 'faraday-retry', require: false
2127
gem 'pry', require: false
28+
gem 'pry-byebug', require: false
29+
gem 'pry-stack_explorer', require: false
2230
end
2331

2432
group :rubocop do

Rakefile

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,18 @@ else
2020
end
2121
end
2222

23-
RSpec::Core::RakeTask.new(:spec)
23+
begin
24+
require 'puppet_litmus/rake_tasks'
25+
rescue LoadError
26+
# Gem not present
27+
end
28+
29+
require 'puppetlabs_spec_helper/tasks/fixtures'
30+
31+
32+
RSpec::Core::RakeTask.new(:spec) do |t|
33+
t.exclude_pattern = 'spec/acceptance/**/*_spec.rb'
34+
end
35+
2436
task :default => :test
2537

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
# frozen_string_literal: true
2+
3+
require 'spec_helper_acceptance'
4+
5+
describe 'When executing puppet-lint' do
6+
let(:manifest_root) { File.join(File.dirname(__FILE__), '..', 'fixtures', 'test', 'manifests') }
7+
8+
context 'with no manifest provided' do
9+
it 'returns an exit code of 1 with no arguments' do
10+
result = puppet_lint
11+
expect(result[:exit_code]).to eq(1)
12+
end
13+
14+
it 'returns an exit code of 0 when given a single flag' do
15+
result = puppet_lint(['--help'])
16+
expect(result[:exit_code]).to eq(0)
17+
end
18+
19+
it 'returns the correct version number with the --version flag' do
20+
result = puppet_lint(['--version'])
21+
expect(result[:stdout]).to match(PuppetLint::VERSION)
22+
end
23+
end
24+
25+
context 'with a manifest provided' do
26+
it 'returns one error when there is one problem' do
27+
result = puppet_lint([File.join(manifest_root, 'fail.pp')])
28+
expect(result[:stdout]).to have_errors(1)
29+
end
30+
31+
it 'returns zero errors when there is an ignore comment present' do
32+
result = puppet_lint([File.join(manifest_root, 'ignore.pp')])
33+
expect(result[:stdout]).to have_errors(0)
34+
end
35+
36+
it 'returns one warning when there is one problem' do
37+
result = puppet_lint([File.join(manifest_root, 'warning.pp')])
38+
expect(result[:stdout]).to have_warnings(1)
39+
end
40+
41+
it 'contains two warnings when there are two problems' do
42+
result = puppet_lint([File.join(manifest_root, 'two_warnings.pp')])
43+
expect(result[:stdout]).to have_warnings(2)
44+
end
45+
end
46+
end

spec/spec_helper.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def subject
134134
config.include(
135135
RSpec::LintExampleGroup,
136136
type: :lint,
137-
file_path: Regexp.compile(['spec', 'puppet-lint', 'plugins'].join('[\\\/]')),
137+
file_path: Regexp.compile(['spec', 'unit', 'puppet-lint', 'plugins'].join('[\\\/]')),
138138
)
139139

140140
config.expect_with(:rspec) do |c|

spec/spec_helper_acceptance.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# frozen_string_literal: true
2+
3+
require 'puppet_litmus'
4+
require 'spec_helper_acceptance_local' if File.file?(File.join(File.dirname(__FILE__), 'spec_helper_acceptance_local.rb'))
5+
6+
PuppetLitmus.configure!
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
# frozen_string_literal: true
2+
3+
require 'Shellwords'
4+
require 'open3'
5+
require 'rspec/expectations'
6+
7+
def puppet_lint(args = [])
8+
raise "Parameter 'args' should an Array but it was of type #{args.class}." unless args.is_a?(Array) || args.empty?
9+
10+
bin_path = File.join(File.dirname(__FILE__), '..', 'bin', 'puppet-lint')
11+
12+
command = [bin_path]
13+
command.concat(args) unless args.empty?
14+
15+
stdout, stderr, status = Open3.capture3(*command)
16+
17+
{
18+
stdout: stdout.chomp,
19+
stderr: stderr.chomp,
20+
exit_code: status.exitstatus,
21+
}
22+
end
23+
24+
RSpec::Matchers.define :have_errors do |expected|
25+
match do |actual|
26+
actual.split("\n").count { |line| line.include?('ERROR') } == expected
27+
end
28+
29+
diffable
30+
end
31+
32+
RSpec::Matchers.define :have_warnings do |expected|
33+
match do |actual|
34+
actual.split("\n").count { |line| line.include?('WARNING') } == expected
35+
end
36+
37+
diffable
38+
end

spec/puppet-lint/bin_spec.rb renamed to spec/unit/puppet-lint/bin_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -587,7 +587,7 @@ def initialize(args)
587587

588588
context 'and command-line does not override "--only-checks"' do
589589
let(:args) do
590-
File.join(File.dirname(__FILE__), '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp')
590+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp')
591591
end
592592

593593
its(:exitstatus) { is_expected.to eq(0) }
@@ -600,7 +600,7 @@ def initialize(args)
600600
let(:args) do
601601
[
602602
'--only-checks=variable_is_lowercase',
603-
File.join(File.dirname(__FILE__), '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp'),
603+
File.join(File.dirname(__FILE__), '..', '..', 'fixtures', 'test', 'manifests', 'two_warnings.pp'),
604604
]
605605
end
606606

0 commit comments

Comments
 (0)