puppet-tripleo/spec/functions/is_ip_addresses_spec.rb
Michele Baldessari 4c7ca4cbc3 Fail more gracefully when passed an empty ip
Introduce a new function called is_ip_addresses which will verify
if a string or an array of strings are composed of correct ip addresses.

We do this in order to fail a bit more clearly if we are passed an empty
or broken ip address. Without this the failure will be in pacemaker
failing to start a VIP called 'ip-'.

Also convert the only use of legacy is_ip_address stdlib function in
mysql::client to this new function (for consistency reasons).

Suggested-by: Rhys Oxenham <roxenham@redhat.com>

Change-Id: Ie15c585a9a902b577f35a75de191bfa91c132668
2018-03-13 17:08:34 +01:00

13 lines
625 B
Ruby

require 'spec_helper'
require 'puppet'
describe 'is_ip_addresses' do
it { should run.with_params('192.168.2.1').and_return(true) }
it { should run.with_params('::1').and_return(true) }
it { should run.with_params('192.168.2.256').and_return(false) }
it { should run.with_params(['192.168.2.1']).and_return(true) }
it { should run.with_params(['192.168.2.1', '5a40:79cf:8251:5dc5:1624:3c03:3c04:9ba8', 'fe80::204:acff:fe17:bf38', '::1:2']).and_return(true) }
it { should run.with_params(['192.168.2.1', 'a.b.c.d']).and_return(false) }
it { should run.with_params(['c.d.d.e', 'a.b.c.d']).and_return(false) }
end