Update stdlib
[mirror/dsa-puppet.git] / 3rdparty / modules / stdlib / spec / acceptance / fqdn_rand_string_spec.rb
1 #! /usr/bin/env ruby -S rspec
2 require 'spec_helper_acceptance'
3
4 describe 'fqdn_rand_string function' do
5   describe 'success' do
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")
10       end
11
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|9Acvnhkt4J)"/)
21         end
22       end
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
30
31         apply_manifest(pp, :catch_failures => true) do |r|
32           expect(r.stdout).to match(/fqdn_rand_string is "(7203048515|2383756694)"/)
33         end
34       end
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
42
43         apply_manifest(pp, :catch_failures => true) do |r|
44           expect(r.stdout).to match(/fqdn_rand_string is "(3HS4mbuI3E|1jJtAMs94d)"/)
45         end
46       end
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
55
56         apply_manifest(pp, :catch_failures => true) do |r|
57           expect(r.stdout).to match(/fqdn_rand_string is "(3104058232|7100592312)"/)
58         end
59       end
60     end
61   end
62   describe 'failure' do
63     it 'handles improper argument counts'
64     it 'handles non-numbers for length argument'
65   end
66 end