rspec-puppetlabs-facts 7.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.changelog.yml +20 -0
- data/.github/dependabot.yml +17 -0
- data/.github/workflows/ci.yml +51 -0
- data/.github/workflows/release.yml +20 -0
- data/.github/workflows/release_prep.yml +24 -0
- data/.gitignore +12 -0
- data/.rspec +4 -0
- data/.rubocop.yml +16 -0
- data/.rubocop_todo.yml +94 -0
- data/CHANGELOG.md +274 -0
- data/Gemfile +60 -0
- data/HISTORY.md +490 -0
- data/LICENSE +201 -0
- data/README.md +625 -0
- data/Rakefile +88 -0
- data/ext/puppet_agent_facter_versions.json +74 -0
- data/lib/rspec-puppetlabs-facts/version.rb +9 -0
- data/lib/rspec-puppetlabs-facts.rb +440 -0
- data/rspec-puppetlabs-facts.gemspec +32 -0
- data/scripts/rename-to-puppetlabs.sh +66 -0
- data/spec/acceptance/build_spec.rb +22 -0
- data/spec/acceptance/install_spec.rb +29 -0
- data/spec/acceptance/scripts/facts_check.rb +15 -0
- data/spec/fixtures/metadata.json +41 -0
- data/spec/fixtures/metadata.json_with_missing_operatingsystem_support +25 -0
- data/spec/spec_helper.rb +5 -0
- data/spec/spec_helper_acceptance.rb +54 -0
- data/spec/unit/rspec_puppetlabs_facts_spec.rb +1055 -0
- metadata +197 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
#!/usr/bin/env bash
|
|
2
|
+
# Rename rspec-puppet-facts -> rspec-puppetlabs-facts (gem, require path, module).
|
|
3
|
+
# Replayable on a fresh upstream tag. Edits code paths only (lib, spec, Rakefile,
|
|
4
|
+
# gemspec, rubocop files); docs, .github, ext and the gemspec homepage are left alone.
|
|
5
|
+
# Never stages, commits or pushes.
|
|
6
|
+
#
|
|
7
|
+
# Precondition: run on a clean upstream tree where the upstream file names exist and the
|
|
8
|
+
# renamed ones do not. After merging a future upstream tag into the renamed branch the
|
|
9
|
+
# old-named files reappear beside the renamed ones and `move` stops with an error; that
|
|
10
|
+
# merge case needs the manual handling documented under DOC-04 (Phase 4).
|
|
11
|
+
set -euo pipefail
|
|
12
|
+
cd "$(git rev-parse --show-toplevel)"
|
|
13
|
+
|
|
14
|
+
move() { # src dst
|
|
15
|
+
[ -e "$1" ] || return 0
|
|
16
|
+
if [ -e "$2" ]; then
|
|
17
|
+
echo "move: both $1 and $2 exist (merge case, see DOC-04)" >&2
|
|
18
|
+
exit 1
|
|
19
|
+
fi
|
|
20
|
+
git mv "$1" "$2"
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
move rspec-puppet-facts.gemspec rspec-puppetlabs-facts.gemspec
|
|
24
|
+
move lib/rspec-puppet-facts lib/rspec-puppetlabs-facts
|
|
25
|
+
move lib/rspec-puppet-facts.rb lib/rspec-puppetlabs-facts.rb
|
|
26
|
+
mkdir -p spec/unit
|
|
27
|
+
move spec/rspec_puppet_facts_spec.rb spec/unit/rspec_puppetlabs_facts_spec.rb
|
|
28
|
+
|
|
29
|
+
subst() {
|
|
30
|
+
local f
|
|
31
|
+
for f in "$@"; do
|
|
32
|
+
sed -i.bak \
|
|
33
|
+
-e '/homepage/!s/rspec-puppet-facts/rspec-puppetlabs-facts/g' \
|
|
34
|
+
-e 's/rspec_puppet_facts/rspec_puppetlabs_facts/g' \
|
|
35
|
+
-e 's/RspecPuppetFacts/RspecPuppetlabsFacts/g' \
|
|
36
|
+
"$f"
|
|
37
|
+
rm -f "$f.bak"
|
|
38
|
+
done
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
files=(Rakefile rspec-puppetlabs-facts.gemspec .rubocop.yml .rubocop_todo.yml)
|
|
42
|
+
while IFS= read -r f; do files+=("$f"); done < <(find lib spec -type f -name '*.rb')
|
|
43
|
+
subst "${files[@]}"
|
|
44
|
+
|
|
45
|
+
# Unit specs live in spec/unit, one level deeper than upstream's flat layout.
|
|
46
|
+
if [ -e spec/unit/rspec_puppetlabs_facts_spec.rb ]; then
|
|
47
|
+
sed -i.bak "s/__dir__, '\.\.', 'ext'/__dir__, '..', '..', 'ext'/g" spec/unit/rspec_puppetlabs_facts_spec.rb
|
|
48
|
+
rm -f spec/unit/rspec_puppetlabs_facts_spec.rb.bak
|
|
49
|
+
fi
|
|
50
|
+
if [ -e .rubocop_todo.yml ]; then
|
|
51
|
+
sed -i.bak "s#'spec/rspec_puppetlabs_facts_spec.rb'#'spec/unit/rspec_puppetlabs_facts_spec.rb'#g" .rubocop_todo.yml
|
|
52
|
+
rm -f .rubocop_todo.yml.bak
|
|
53
|
+
fi
|
|
54
|
+
|
|
55
|
+
if [ -e rspec-puppet-facts.gemspec ]; then
|
|
56
|
+
echo 'leftover old names found' >&2
|
|
57
|
+
exit 1
|
|
58
|
+
fi
|
|
59
|
+
|
|
60
|
+
if grep -rnE 'RspecPuppetFacts|rspec-puppet-facts|rspec_puppet_facts' \
|
|
61
|
+
lib spec Rakefile rspec-puppetlabs-facts.gemspec .rubocop.yml .rubocop_todo.yml \
|
|
62
|
+
| grep -v '^rspec-puppetlabs-facts\.gemspec:[0-9]*:.*homepage'; then
|
|
63
|
+
echo 'leftover old names found' >&2
|
|
64
|
+
exit 1
|
|
65
|
+
fi
|
|
66
|
+
echo 'rename complete, no leftovers'
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper_acceptance'
|
|
4
|
+
require 'fileutils'
|
|
5
|
+
require 'rubygems/package'
|
|
6
|
+
|
|
7
|
+
RSpec.describe 'gem build' do
|
|
8
|
+
after(:all) { FileUtils.rm_f(BUILT_GEM) } # rubocop:disable RSpec/BeforeAfterAll
|
|
9
|
+
|
|
10
|
+
describe command("gem build rspec-puppetlabs-facts.gemspec --output \"#{BUILT_GEM}\"") do
|
|
11
|
+
its(:exit_status) { is_expected.to eq(0) }
|
|
12
|
+
|
|
13
|
+
it 'includes the renamed files' do
|
|
14
|
+
expect(subject.exit_status).to eq(0)
|
|
15
|
+
expect(Gem::Package.new(BUILT_GEM).contents).to include(
|
|
16
|
+
'lib/rspec-puppetlabs-facts.rb',
|
|
17
|
+
'lib/rspec-puppetlabs-facts/version.rb',
|
|
18
|
+
'ext/puppet_agent_facter_versions.json',
|
|
19
|
+
)
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'spec_helper_acceptance'
|
|
4
|
+
require 'json'
|
|
5
|
+
|
|
6
|
+
RSpec.describe 'rspec-puppetlabs-facts' do
|
|
7
|
+
describe command('bundle exec ruby spec/acceptance/scripts/facts_check.rb spec/fixtures/metadata.json') do
|
|
8
|
+
let(:result) { JSON.parse(subject.stdout.lines.last) }
|
|
9
|
+
let(:expected_os) do
|
|
10
|
+
JSON.parse(File.read(File.join(REPO_ROOT, 'spec', 'fixtures', 'metadata.json'), encoding: 'UTF-8'))['operatingsystem_support'].flat_map do |entry|
|
|
11
|
+
entry['operatingsystemrelease'].map { |release| "#{entry['operatingsystem'].downcase}-#{release.split('.').first}-" }
|
|
12
|
+
end
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
its(:exit_status) { is_expected.to eq(0) }
|
|
16
|
+
|
|
17
|
+
it 'loads the version in lib' do
|
|
18
|
+
expect(result['version']).to eq(File.read(File.join(REPO_ROOT, 'lib', 'rspec-puppetlabs-facts', 'version.rb'))[/STRING = '([^']+)'/, 1])
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
it 'returns non-empty facts for each supported OS' do
|
|
22
|
+
expect(result['facts']).not_to be_empty
|
|
23
|
+
expect(result['facts'].values).to all(be > 0)
|
|
24
|
+
expected_os.each do |prefix|
|
|
25
|
+
expect(result['facts'].keys.any? { |key| key.start_with?(prefix) }).to be(true), "no facts for #{prefix}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# Run with `bundle exec ruby`: loads the gem as installed by the bundle and prints
|
|
4
|
+
# a JSON summary of the facts it returns for the given metadata.json.
|
|
5
|
+
require 'json'
|
|
6
|
+
require 'rspec'
|
|
7
|
+
require 'rspec-puppetlabs-facts'
|
|
8
|
+
|
|
9
|
+
metadata = JSON.parse(File.read(ARGV.fetch(0), encoding: 'UTF-8'))
|
|
10
|
+
facts = Object.new.extend(RspecPuppetlabsFacts).on_supported_os(supported_os: metadata['operatingsystem_support'])
|
|
11
|
+
|
|
12
|
+
puts JSON.generate( # rubocop:disable RSpec/Output
|
|
13
|
+
'version' => RspecPuppetlabsFacts::Version::STRING,
|
|
14
|
+
'facts' => facts.transform_values(&:size),
|
|
15
|
+
)
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcanevet-mymodule",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "Mickaël Canévet",
|
|
5
|
+
"summary": "My puppet modules",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"source": "https://github.com/mcanevet/puppet-mymodule",
|
|
8
|
+
"project_page": "https://github.com/mcanevet/puppet-mymodule",
|
|
9
|
+
"issues_url": "https://github.com/mcanevet/puppet-mymodule/issues",
|
|
10
|
+
"dependencies": [
|
|
11
|
+
],
|
|
12
|
+
"requirements": [
|
|
13
|
+
],
|
|
14
|
+
"operatingsystem_support": [
|
|
15
|
+
{
|
|
16
|
+
"operatingsystem": "Debian",
|
|
17
|
+
"operatingsystemrelease": [
|
|
18
|
+
"11",
|
|
19
|
+
"12"
|
|
20
|
+
]
|
|
21
|
+
},
|
|
22
|
+
{
|
|
23
|
+
"operatingsystem": "RedHat",
|
|
24
|
+
"operatingsystemrelease": [
|
|
25
|
+
"8",
|
|
26
|
+
"9"
|
|
27
|
+
]
|
|
28
|
+
}
|
|
29
|
+
],
|
|
30
|
+
"puppet_version": [
|
|
31
|
+
"2.7",
|
|
32
|
+
"3.0",
|
|
33
|
+
"3.1",
|
|
34
|
+
"3.2",
|
|
35
|
+
"3.3",
|
|
36
|
+
"3.4",
|
|
37
|
+
"3.5",
|
|
38
|
+
"3.6",
|
|
39
|
+
"3.7"
|
|
40
|
+
]
|
|
41
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "mcanevet-mymodule",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"author": "Mickaël Canévet",
|
|
5
|
+
"summary": "My puppet modules",
|
|
6
|
+
"license": "Apache-2.0",
|
|
7
|
+
"source": "https://github.com/mcanevet/puppet-mymodule",
|
|
8
|
+
"project_page": "https://github.com/mcanevet/puppet-mymodule",
|
|
9
|
+
"issues_url": "https://github.com/mcanevet/puppet-mymodule/issues",
|
|
10
|
+
"dependencies": [
|
|
11
|
+
],
|
|
12
|
+
"requirements": [
|
|
13
|
+
],
|
|
14
|
+
"puppet_version": [
|
|
15
|
+
"2.7",
|
|
16
|
+
"3.0",
|
|
17
|
+
"3.1",
|
|
18
|
+
"3.2",
|
|
19
|
+
"3.3",
|
|
20
|
+
"3.4",
|
|
21
|
+
"3.5",
|
|
22
|
+
"3.6",
|
|
23
|
+
"3.7"
|
|
24
|
+
]
|
|
25
|
+
}
|
data/spec/spec_helper.rb
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'open3'
|
|
4
|
+
require 'serverspec'
|
|
5
|
+
require 'tmpdir'
|
|
6
|
+
|
|
7
|
+
REPO_ROOT = File.expand_path('..', __dir__)
|
|
8
|
+
BUILT_GEM = File.join(Dir.tmpdir, "rspec-puppetlabs-facts-#{Process.pid}.gem")
|
|
9
|
+
|
|
10
|
+
set :backend, (Gem.win_platform? ? :cmd : :exec)
|
|
11
|
+
|
|
12
|
+
module Specinfra
|
|
13
|
+
module Backend
|
|
14
|
+
class Cmd
|
|
15
|
+
def execute_script(script)
|
|
16
|
+
if Open3.respond_to?(:capture3)
|
|
17
|
+
stdout, stderr, status = Open3.capture3(script)
|
|
18
|
+
{ stdout: stdout, stderr: stderr, status: status }
|
|
19
|
+
else
|
|
20
|
+
stdout = `#{script} 2>&1`
|
|
21
|
+
{ stdout: stdout, stderr: nil, status: $? } # rubocop:disable Style/SpecialGlobalVars
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
ENV['LANG'] = 'en_US.UTF-8'
|
|
29
|
+
ENV['LANGUAGE'] = 'en_US.UTF-8'
|
|
30
|
+
ENV['LC_ALL'] = 'en_US.UTF-8'
|
|
31
|
+
|
|
32
|
+
# Save the bundle environment from being purged by specinfra. This is restored after every
|
|
33
|
+
# example, as specinfra does not reset the environment after a `describe command()` block.
|
|
34
|
+
bundler_keys = %w[BUNDLER_EDITOR BUNDLE_BIN_PATH BUNDLE_GEMFILE RUBYOPT GEM_HOME GEM_PATH GEM_CACHE LANG LANGUAGE LC_ALL]
|
|
35
|
+
bundler_env = bundler_keys.select { |key| ENV.key?(key) }.to_h { |key| [key, ENV.fetch(key)] }
|
|
36
|
+
|
|
37
|
+
Specinfra.configuration.env = bundler_env.dup
|
|
38
|
+
|
|
39
|
+
RSpec.configure do |c|
|
|
40
|
+
c.before(:suite) { Dir.chdir(REPO_ROOT) }
|
|
41
|
+
|
|
42
|
+
c.after do |example|
|
|
43
|
+
# Dump stderr into the failure message to help with debugging
|
|
44
|
+
if example.exception && subject.respond_to?(:stderr) && subject.stderr != ''
|
|
45
|
+
example.exception.message << "\nDumping stderr output:\n\n#{subject.stderr}\n"
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
bundler_env.each { |key, value| ENV[key] = value }
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
c.expect_with(:rspec) do |e|
|
|
52
|
+
e.include_chain_clauses_in_custom_matcher_descriptions = true
|
|
53
|
+
end
|
|
54
|
+
end
|