Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Return platform name that is lower case and underscored #228

Merged
merged 2 commits into from
Jan 3, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions lib/train/platforms/platform.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,16 @@ def direct_families
def name
# Override here incase a updated name was set
# during the detect logic
@platform[:name] || @name
clean_name
end

def clean_name(force: false)
@cleaned_name = nil if force
@cleaned_name ||= begin
name = (@platform[:name] || @name)
name.downcase!.tr!(' ', '_') if name =~ /[A-Z ]/
name
end
end

# This is for backwords compatability with
Expand Down Expand Up @@ -53,6 +62,10 @@ def to_hash
# This is done later to add any custom
# families/properties that were created
def add_platform_methods
# Redo clean name if there is a detect override
clean_name(force: true) unless @platform[:name].nil?

# Add in family methods
family_list = Train::Platforms.families
family_list.each_value do |k|
next if respond_to?(k.name + '?')
Expand All @@ -70,9 +83,9 @@ def add_platform_methods
end

# Create method for name if its not already true
plat_name = name.downcase.tr(' ', '_') + '?'
return if respond_to?(plat_name)
define_singleton_method(plat_name) do
m = name + '?'
return if respond_to?(m)
define_singleton_method(m) do
true
end
end
Expand Down
12 changes: 9 additions & 3 deletions test/unit/platforms/platform_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,19 @@ def mock_os_hierarchy(plat)
plat.title.must_equal('The Best Mock')
end

it 'clean init name' do
plat = mock_platform_family('Mo ck')
plat.name.must_equal('mo_ck')
end

it 'set name and name override' do
plat = mock_platform_family('mock')
plat.name.must_equal('mock')
plat[:name].must_equal('mock')
plat.platform[:name] = 'mock2020'
plat.name.must_equal('mock2020')
plat[:name].must_equal('mock2020')
plat.platform[:name] = 'Mock 2020'
plat.add_platform_methods
plat.name.must_equal('mock_2020')
plat[:name].must_equal('mock_2020')
end

it 'check families' do
Expand Down
2 changes: 1 addition & 1 deletion test/windows/local_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@

it 'verify os' do
os = conn.os
os[:name].must_equal 'Windows Server 2012 R2 Datacenter'
os[:name].must_equal 'windows_server_2012_r2_datacenter'
os[:family].must_equal "windows"
os[:release].must_equal '6.3.9600'
os[:arch].must_equal 'x86_64'
Expand Down
2 changes: 1 addition & 1 deletion test/windows/winrm_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@

it 'verify os' do
os = conn.os
os[:name].must_equal 'Windows Server 2012 R2 Datacenter'
os[:name].must_equal 'windows_server_2012_r2_datacenter'
os[:family].must_equal 'windows'
os[:release].must_equal '6.3.9600'
os[:arch].must_equal 'x86_64'
Expand Down