|
3 | 3 |
|
4 | 4 | describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do |
5 | 5 | 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") |
29 | 10 | 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 |
38 | 11 |
|
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 |
41 | 22 | 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 |
51 | 30 |
|
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 |
54 | 34 | 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 |
64 | 42 |
|
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 |
67 | 46 | 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 |
78 | 55 |
|
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 |
81 | 59 | end |
82 | 60 | end |
83 | 61 | end |
|
0 commit comments