2015-01-27 04:17:53 +01:00
|
|
|
#! /usr/bin/env ruby -S rspec
|
|
|
|
require 'spec_helper_acceptance'
|
|
|
|
|
2015-04-10 00:47:04 +02:00
|
|
|
describe 'fqdn_rand_string function', :unless => UNSUPPORTED_PLATFORMS.include?(fact('operatingsystem')) do
|
2015-01-27 04:17:53 +01:00
|
|
|
describe 'success' do
|
2015-07-22 18:30:39 +02:00
|
|
|
include_context "with faked facts"
|
|
|
|
context "when the FQDN is 'fakehost.localdomain'" do
|
|
|
|
before :each do
|
|
|
|
fake_fact("fqdn", "fakehost.localdomain")
|
2015-01-27 04:17:53 +01:00
|
|
|
end
|
|
|
|
|
2015-07-22 18:30:39 +02:00
|
|
|
it 'generates random alphanumeric strings' do
|
|
|
|
pp = <<-eos
|
|
|
|
$l = 10
|
|
|
|
$o = fqdn_rand_string($l)
|
|
|
|
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
|
|
|
|
eos
|
|
|
|
|
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
2016-03-16 21:57:36 +01:00
|
|
|
expect(r.stdout).to match(/fqdn_rand_string is "(7oDp0KOr1b|9Acvnhkt4J)"/)
|
2015-07-22 18:30:39 +02:00
|
|
|
end
|
2015-01-27 04:17:53 +01:00
|
|
|
end
|
2015-07-22 18:30:39 +02:00
|
|
|
it 'generates random alphanumeric strings with custom charsets' do
|
|
|
|
pp = <<-eos
|
|
|
|
$l = 10
|
|
|
|
$c = '0123456789'
|
|
|
|
$o = fqdn_rand_string($l, $c)
|
|
|
|
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
|
|
|
|
eos
|
2015-06-02 01:46:26 +02:00
|
|
|
|
2015-07-22 18:30:39 +02:00
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
2016-03-16 21:57:36 +01:00
|
|
|
expect(r.stdout).to match(/fqdn_rand_string is "(7203048515|2383756694)"/)
|
2015-07-22 18:30:39 +02:00
|
|
|
end
|
2015-06-02 01:46:26 +02:00
|
|
|
end
|
2015-07-22 18:30:39 +02:00
|
|
|
it 'generates random alphanumeric strings with custom seeds' do
|
|
|
|
pp = <<-eos
|
|
|
|
$l = 10
|
|
|
|
$s = 'seed'
|
|
|
|
$o = fqdn_rand_string($l, undef, $s)
|
|
|
|
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
|
|
|
|
eos
|
2015-01-27 04:17:53 +01:00
|
|
|
|
2015-07-22 18:30:39 +02:00
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
2016-03-16 21:57:36 +01:00
|
|
|
expect(r.stdout).to match(/fqdn_rand_string is "(3HS4mbuI3E|1jJtAMs94d)"/)
|
2015-07-22 18:30:39 +02:00
|
|
|
end
|
2015-01-27 04:17:53 +01:00
|
|
|
end
|
2015-07-22 18:30:39 +02:00
|
|
|
it 'generates random alphanumeric strings with custom charsets and seeds' do
|
|
|
|
pp = <<-eos
|
|
|
|
$l = 10
|
|
|
|
$c = '0123456789'
|
|
|
|
$s = 'seed'
|
|
|
|
$o = fqdn_rand_string($l, $c, $s)
|
|
|
|
notice(inline_template('fqdn_rand_string is <%= @o.inspect %>'))
|
|
|
|
eos
|
2015-06-02 01:46:26 +02:00
|
|
|
|
2015-07-22 18:30:39 +02:00
|
|
|
apply_manifest(pp, :catch_failures => true) do |r|
|
2016-03-16 21:57:36 +01:00
|
|
|
expect(r.stdout).to match(/fqdn_rand_string is "(3104058232|7100592312)"/)
|
2015-07-22 18:30:39 +02:00
|
|
|
end
|
2015-06-02 01:46:26 +02:00
|
|
|
end
|
|
|
|
end
|
2015-01-27 04:17:53 +01:00
|
|
|
end
|
|
|
|
describe 'failure' do
|
|
|
|
it 'handles improper argument counts'
|
|
|
|
it 'handles non-numbers for length argument'
|
|
|
|
end
|
|
|
|
end
|