Skip to content

Commit

Permalink
Various fixes for rspec tests
Browse files Browse the repository at this point in the history
  • Loading branch information
silug committed Oct 18, 2023
1 parent 8031b56 commit 0fabe0b
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 2 deletions.
2 changes: 2 additions & 0 deletions lib/simp/cli/config/items/data/simp_options_ldap_master.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@ def get_recommended_value
end

def validate item
return false unless item.class == String

result = false
if ( ( item =~ %r{^ldap[s]*://.+} ) ? true : false )
i = item.sub( %r{^ldap[s]*://}, '' )
Expand Down
1 change: 1 addition & 0 deletions lib/simp/cli/config/items/data/simp_options_ldap_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ def get_recommended_value


def validate_item item
return false unless item.class == String
result = false
if ( ( item =~ %r{^ldap[s]*://.+} ) ? true : false )
i = item.sub( %r{^ldap[s]*://}, '' )
Expand Down
3 changes: 3 additions & 0 deletions lib/simp/cli/config/utils.rb
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def validate_fqdn fqdn


def validate_ip ip
return false unless ip.respond_to?(:=~)
# using the native 'resolv' class in order to minimize non-EL rubygems
# snarfed from:
# http://stackoverflow.com/questions/3634998/how-do-i-check-whether-a-value-in-a-string-is-an-ip-address
Expand All @@ -49,6 +50,7 @@ def validate_ip ip


def validate_hostname hostname
return false unless hostname.respond_to?(:=~)
# based on:
# http://stackoverflow.com/questions/2532053/validate-a-hostname-string
#
Expand All @@ -62,6 +64,7 @@ def validate_hostname hostname


def validate_netmask( x )
return false unless x.respond_to?(:=~)
# a brute-force regexp that validates all possible valid netmasks
nums = '(128|192|224|240|248|252|254)'
znums = '(0|128|192|224|240|248|252|254)'
Expand Down
9 changes: 7 additions & 2 deletions spec/lib/simp/cli/config/yaml_utils_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ class YamlUtilsTester

describe '#pair_to_yaml_tag' do
{
'nil' => { :value => nil, :exp => "key: \n" },
'nil' => { :value => nil, :exp => %r{\Akey:\s?\n\z} }, # Ruby 2 returns a space after the colon
'boolean' => { :value => true, :exp => "key: true\n" },
'integer' => { :value => 1, :exp => "key: 1\n" },
'float' => { :value => 1.5, :exp => "key: 1.5\n" },
Expand All @@ -89,7 +89,11 @@ class YamlUtilsTester
}
}.each do |type, attr|
it "returns a valid YAML tag for a #{type} value" do
expect( @tester.pair_to_yaml_tag('key', attr[:value]) ).to eq(attr[:exp])
if attr[:exp].is_a?(Regexp)
expect( @tester.pair_to_yaml_tag('key', attr[:value]) ).to match(attr[:exp])
else
expect( @tester.pair_to_yaml_tag('key', attr[:value]) ).to eq(attr[:exp])
end
end
end
end
Expand Down Expand Up @@ -326,6 +330,7 @@ class YamlUtilsTester
result = @tester.merge_or_replace_yaml_tag('pam::access::users', nil, file_info)
expect( result ).to eq :replace
expected = File.join(@files_dir, 'base_nil_replace.yaml')
pending('Minor whitespace change with Ruby 3') if Gem::Version.new(RUBY_VERSION) >= Gem::Version.new('3.0.0')
expect( IO.read(@test_file) ).to eq IO.read(expected)
YAML.load(IO.read(@test_file)) # verifies modified file is still valid YAML
end
Expand Down

0 comments on commit 0fabe0b

Please sign in to comment.