Skip to content

Commit 41a7297

Browse files
committed
Merge pull request #495 from puppetlabs/4.7.x
4.7.x
2 parents 4d889cb + 956c329 commit 41a7297

5 files changed

Lines changed: 123 additions & 155 deletions

File tree

spec/acceptance/ensure_packages_spec.rb

Lines changed: 0 additions & 22 deletions
This file was deleted.

spec/acceptance/fqdn_rand_string_spec.rb

Lines changed: 45 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -3,81 +3,59 @@
33

44
describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
55
describe 'success' do
6-
let(:facts_d) do
7-
puppet_version = (on default, puppet('--version')).output.chomp
8-
if puppet_version < '4.0.0' && fact('is_pe', '--puppet') == "true"
9-
if fact('osfamily') =~ /windows/i
10-
if fact('kernelmajversion').to_f < 6.0
11-
'c:/documents and settings/all users/application data/puppetlabs/facter/facts.d'
12-
else
13-
'c:/programdata/puppetlabs/facter/facts.d'
14-
end
15-
else
16-
'/etc/puppetlabs/facter/facts.d'
17-
end
18-
else
19-
'/etc/facter/facts.d'
20-
end
21-
end
22-
after :each do
23-
shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi")
24-
end
25-
before :each do
26-
#no need to create on windows, pe creates by default
27-
if fact('osfamily') !~ /windows/i
28-
shell("mkdir -p '#{facts_d}'")
6+
include_context "with faked facts"
7+
context "when the FQDN is 'fakehost.localdomain'" do
8+
before :each do
9+
fake_fact("fqdn", "fakehost.localdomain")
2910
end
30-
end
31-
it 'generates random alphanumeric strings' do
32-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
33-
pp = <<-eos
34-
$l = 10
35-
$o = fqdn_rand_string($l)
36-
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
37-
eos
3811

39-
apply_manifest(pp, :catch_failures => true) do |r|
40-
expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/)
12+
it 'generates random alphanumeric strings' do
13+
pp = <<-eos
14+
$l = 10
15+
$o = fqdn_rand_string($l)
16+
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
17+
eos
18+
19+
apply_manifest(pp, :catch_failures => true) do |r|
20+
expect(r.stdout).to match(/fqdn_rand_string is "7oDp0KOr1b"/)
21+
end
4122
end
42-
end
43-
it 'generates random alphanumeric strings with custom charsets' do
44-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
45-
pp = <<-eos
46-
$l = 10
47-
$c = '0123456789'
48-
$o = fqdn_rand_string($l, $c)
49-
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
50-
eos
23+
it 'generates random alphanumeric strings with custom charsets' do
24+
pp = <<-eos
25+
$l = 10
26+
$c = '0123456789'
27+
$o = fqdn_rand_string($l, $c)
28+
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
29+
eos
5130

52-
apply_manifest(pp, :catch_failures => true) do |r|
53-
expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/)
31+
apply_manifest(pp, :catch_failures => true) do |r|
32+
expect(r.stdout).to match(/fqdn_rand_string is "7203048515"/)
33+
end
5434
end
55-
end
56-
it 'generates random alphanumeric strings with custom seeds' do
57-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
58-
pp = <<-eos
59-
$l = 10
60-
$s = 'seed'
61-
$o = fqdn_rand_string($l, undef, $s)
62-
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
63-
eos
35+
it 'generates random alphanumeric strings with custom seeds' do
36+
pp = <<-eos
37+
$l = 10
38+
$s = 'seed'
39+
$o = fqdn_rand_string($l, undef, $s)
40+
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
41+
eos
6442

65-
apply_manifest(pp, :catch_failures => true) do |r|
66-
expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/)
43+
apply_manifest(pp, :catch_failures => true) do |r|
44+
expect(r.stdout).to match(/fqdn_rand_string is "3HS4mbuI3E"/)
45+
end
6746
end
68-
end
69-
it 'generates random alphanumeric strings with custom charsets and seeds' do
70-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
71-
pp = <<-eos
72-
$l = 10
73-
$c = '0123456789'
74-
$s = 'seed'
75-
$o = fqdn_rand_string($l, $c, $s)
76-
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
77-
eos
47+
it 'generates random alphanumeric strings with custom charsets and seeds' do
48+
pp = <<-eos
49+
$l = 10
50+
$c = '0123456789'
51+
$s = 'seed'
52+
$o = fqdn_rand_string($l, $c, $s)
53+
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
54+
eos
7855

79-
apply_manifest(pp, :catch_failures => true) do |r|
80-
expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/)
56+
apply_manifest(pp, :catch_failures => true) do |r|
57+
expect(r.stdout).to match(/fqdn_rand_string is "3104058232"/)
58+
end
8159
end
8260
end
8361
end

spec/acceptance/fqdn_rotate_spec.rb

Lines changed: 43 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -3,79 +3,57 @@
33

44
describe 'fqdn_rotate function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
55
describe 'success' do
6-
let(:facts_d) do
7-
puppet_version = (on default, puppet('--version')).output.chomp
8-
if puppet_version < '4.0.0' && fact('is_pe', '--puppet') == "true"
9-
if fact('osfamily') =~ /windows/i
10-
if fact('kernelmajversion').to_f < 6.0
11-
'C:/Documents and Settings/All Users/Application Data/PuppetLabs/facter/facts.d'
12-
else
13-
'C:/ProgramData/PuppetLabs/facter/facts.d'
14-
end
15-
else
16-
'/etc/puppetlabs/facter/facts.d'
17-
end
18-
else
19-
'/etc/facter/facts.d'
20-
end
21-
end
22-
after :each do
23-
shell("if [ -f '#{facts_d}/fqdn.txt' ] ; then rm '#{facts_d}/fqdn.txt' ; fi")
24-
end
25-
before :each do
26-
#No need to create on windows, PE creates by default
27-
if fact('osfamily') !~ /windows/i
28-
shell("mkdir -p '#{facts_d}'")
6+
include_context "with faked facts"
7+
context "when the FQDN is 'fakehost.localdomain'" do
8+
before :each do
9+
fake_fact("fqdn", "fakehost.localdomain")
2910
end
30-
end
31-
it 'rotates arrays' do
32-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
33-
pp = <<-EOS
34-
$a = ['a','b','c','d']
35-
$o = fqdn_rotate($a)
36-
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
37-
EOS
3811

39-
apply_manifest(pp, :catch_failures => true) do |r|
40-
expect(r.stdout).to match(/fqdn_rotate is \["d", "a", "b", "c"\]/)
12+
it 'rotates arrays' do
13+
pp = <<-EOS
14+
$a = ['a','b','c','d']
15+
$o = fqdn_rotate($a)
16+
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
17+
EOS
18+
19+
apply_manifest(pp, :catch_failures => true) do |r|
20+
expect(r.stdout).to match(/fqdn_rotate is \["d", "a", "b", "c"\]/)
21+
end
4122
end
42-
end
43-
it 'rotates arrays with custom seeds' do
44-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
45-
pp = <<-EOS
46-
$a = ['a','b','c','d']
47-
$s = 'seed'
48-
$o = fqdn_rotate($a, $s)
49-
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
50-
EOS
23+
it 'rotates arrays with custom seeds' do
24+
pp = <<-EOS
25+
$a = ['a','b','c','d']
26+
$s = 'seed'
27+
$o = fqdn_rotate($a, $s)
28+
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
29+
EOS
5130

52-
apply_manifest(pp, :catch_failures => true) do |r|
53-
expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/)
31+
apply_manifest(pp, :catch_failures => true) do |r|
32+
expect(r.stdout).to match(/fqdn_rotate is \["c", "d", "a", "b"\]/)
33+
end
5434
end
55-
end
56-
it 'rotates strings' do
57-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
58-
pp = <<-EOS
59-
$a = 'abcd'
60-
$o = fqdn_rotate($a)
61-
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
62-
EOS
35+
it 'rotates strings' do
36+
pp = <<-EOS
37+
$a = 'abcd'
38+
$o = fqdn_rotate($a)
39+
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
40+
EOS
6341

64-
apply_manifest(pp, :catch_failures => true) do |r|
65-
expect(r.stdout).to match(/fqdn_rotate is "dabc"/)
42+
apply_manifest(pp, :catch_failures => true) do |r|
43+
expect(r.stdout).to match(/fqdn_rotate is "dabc"/)
44+
end
6645
end
67-
end
68-
it 'rotates strings with custom seeds' do
69-
shell("echo fqdn=fakehost.localdomain > '#{facts_d}/fqdn.txt'")
70-
pp = <<-EOS
71-
$a = 'abcd'
72-
$s = 'seed'
73-
$o = fqdn_rotate($a, $s)
74-
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
75-
EOS
46+
it 'rotates strings with custom seeds' do
47+
pp = <<-EOS
48+
$a = 'abcd'
49+
$s = 'seed'
50+
$o = fqdn_rotate($a, $s)
51+
notice(inline_template('fqdn_rotate is <%= @o.inspect %>'))
52+
EOS
7653

77-
apply_manifest(pp, :catch_failures => true) do |r|
78-
expect(r.stdout).to match(/fqdn_rotate is "cdab"/)
54+
apply_manifest(pp, :catch_failures => true) do |r|
55+
expect(r.stdout).to match(/fqdn_rotate is "cdab"/)
56+
end
7957
end
8058
end
8159
end

spec/acceptance/pw_hash_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
require 'spec_helper_acceptance'
33

44
# Windows and OS X do not have useful implementations of crypt(3)
5-
describe 'pw_hash function', :unless => (UNSUPPORTED_PLATFORMS + ['windows', 'Darwin']).include?(fact('operatingsystem')) do
5+
describe 'pw_hash function', :unless => (UNSUPPORTED_PLATFORMS + ['windows', 'Darwin', 'SLES']).include?(fact('operatingsystem')) do
66
describe 'success' do
77
it 'hashes passwords' do
88
pp = <<-EOS

spec/spec_helper_acceptance.rb

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,37 @@ def is_future_parser_enabled?
3232
end
3333
return false
3434
end
35+
36+
RSpec.shared_context "with faked facts" do
37+
let(:facts_d) do
38+
puppet_version = (on default, puppet('--version')).output.chomp
39+
if Puppet::Util::Package.versioncmp(puppet_version, '4.0.0') < 0 && fact('is_pe', '--puppet') == "true"
40+
if fact('osfamily') =~ /windows/i
41+
if fact('kernelmajversion').to_f < 6.0
42+
'C:/Documents and Settings/All Users/Application Data/PuppetLabs/facter/facts.d'
43+
else
44+
'C:/ProgramData/PuppetLabs/facter/facts.d'
45+
end
46+
else
47+
'/etc/puppetlabs/facter/facts.d'
48+
end
49+
else
50+
'/etc/facter/facts.d'
51+
end
52+
end
53+
54+
before :each do
55+
#No need to create on windows, PE creates by default
56+
if fact('osfamily') !~ /windows/i
57+
shell("mkdir -p '#{facts_d}'")
58+
end
59+
end
60+
61+
after :each do
62+
shell("rm -f '#{facts_d}/fqdn.txt'")
63+
end
64+
65+
def fake_fact(name, value)
66+
shell("echo #{name}=#{value} > '#{facts_d}/#{name}.txt'")
67+
end
68+
end

0 commit comments

Comments
 (0)