Skip to content

Commit

Permalink
Ensure metadata.json returns the correct Solaris arch value
Browse files Browse the repository at this point in the history
This is an additional fix for #554
  • Loading branch information
schisamo committed Oct 6, 2015
1 parent 191d5b1 commit 67fe6ed
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 7 deletions.
15 changes: 12 additions & 3 deletions lib/omnibus/metadata.rb
Expand Up @@ -18,6 +18,9 @@

module Omnibus
class Metadata
extend Sugarable
include Sugarable

class << self
#
# Render the metadata for the package at the given path, generated by the
Expand Down Expand Up @@ -108,8 +111,14 @@ def path_for(package)
# @return [String]
#
def arch
if (Ohai['platform'] == 'windows') && (Config.windows_arch.to_sym == :x86)
if windows? && windows_arch_i386?
'i386'
elsif solaris?
if intel?
'i386'
elsif sparc?
'sparc'
end
else
Ohai['kernel']['machine']
end
Expand All @@ -132,9 +141,9 @@ def platform_version
# the platform family short name
#
def platform_shortname
if Ohai['platform_family'] == 'rhel'
if rhel?
'el'
elsif Ohai['platform'] == 'suse'
elsif suse?
'sles'
else
Ohai['platform']
Expand Down
41 changes: 37 additions & 4 deletions spec/unit/metadata_spec.rb
Expand Up @@ -22,18 +22,51 @@ module Omnibus
subject { described_class.new(package, data) }

describe '.arch' do
it 'returns the architecture' do
let(:architecture) { 'x86_64' }

before do
stub_ohai(platform: 'ubuntu', version: '12.04') do |data|
data['kernel']['machine'] = 'x86_64'
data['kernel']['machine'] = architecture
end
end

it 'returns the architecture' do
expect(described_class.arch).to eq('x86_64')
end

context 'on solaris' do
before do
stub_ohai(platform: 'solaris2', version: '5.11') do |data|
data['platform'] = 'solaris2'
data['kernel']['machine'] = architecture
end
end

context 'architecture is Intel-based' do
let(:architecture) { 'i86pc' }

it 'returns i386' do
expect(described_class.arch).to eq('i386')
end
end

context 'architecture is SPARC-based' do
let(:architecture) { 'sun4v' }

it 'returns sparc' do
expect(described_class.arch).to eq('sparc')
end
end
end

context 'on windows' do
it 'returns a 32-bit value based on Config.windows_arch being set to x86' do
before do
stub_ohai(platform: 'windows', version: '2012R2') do |data|
data['kernel']['machine'] = 'x86_64'
data['kernel']['machine'] = architecture
end
end

it 'returns a 32-bit value based on Config.windows_arch being set to x86' do
expect(Config).to receive(:windows_arch).and_return(:x86)
expect(described_class.arch).to eq('i386')
end
Expand Down
16 changes: 16 additions & 0 deletions spec/unit/sugarable_spec.rb
Expand Up @@ -7,6 +7,22 @@ module Omnibus
end
end

describe Metadata do
it 'extends Sugarable' do
expect(described_class.singleton_class.included_modules).to include(Sugarable)
end

it 'includes Sugarable' do
expect(described_class.ancestors).to include(Sugarable)
end
end

describe Packager::Base do
it 'is a sugarable' do
expect(described_class.ancestors).to include(Sugarable)
end
end

describe Project do
it 'is a sugarable' do
expect(described_class.ancestors).to include(Sugarable)
Expand Down

0 comments on commit 67fe6ed

Please sign in to comment.