-
Notifications
You must be signed in to change notification settings - Fork 87
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from chef/chris-rock/win-detection
complete rewrite of windows version detection
- Loading branch information
Showing
7 changed files
with
147 additions
and
73 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,4 @@ | ||
# encoding: utf-8 | ||
require 'helper' | ||
require 'train/extras' | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
require 'train/extras' | ||
|
||
class OsDetectWindowsTester | ||
attr_reader :platform, :backend | ||
include Train::Extras::DetectWindows | ||
|
||
def initialize | ||
@platform = {} | ||
@backend = Train::Transports::Mock.new.connection | ||
@backend.mock_os({ family: 'windows' }) | ||
end | ||
end | ||
|
||
describe 'os_detect_windows' do | ||
describe 'windows 2012' do | ||
let(:detector) { | ||
detector = OsDetectWindowsTester.new | ||
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 6.3.9600]\r\n", '', 0) | ||
detector.backend.mock_command('wmic os get * /format:list',"\r\r\nBuildNumber=9600\r\r\nCaption=Microsoft Windows Server 2012 R2 Standard\r\r\nOSArchitecture=64-bit\r\r\nVersion=6.3.9600\r\r\n" , '', 0) | ||
detector | ||
} | ||
|
||
it 'sets the correct family/release for windows' do | ||
detector.detect_windows | ||
detector.platform[:family].must_equal('windows') | ||
detector.platform[:name].must_equal('Windows Server 2012 R2 Standard') | ||
detector.platform[:arch].must_equal('64-bit') | ||
detector.platform[:release].must_equal('6.3.9600') | ||
end | ||
end | ||
|
||
describe 'windows 2008' do | ||
let(:detector) { | ||
detector = OsDetectWindowsTester.new | ||
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 6.1.7601]\r\n", '', 0) | ||
detector.backend.mock_command('wmic os get * /format:list',"\r\r\nBuildNumber=7601\r\r\nCaption=Microsoft Windows Server 2008 R2 Standard \r\r\nOSArchitecture=64-bit\r\r\nVersion=6.1.7601\r\r\n" , '', 0) | ||
detector | ||
} | ||
|
||
it 'sets the correct family/release for windows' do | ||
detector.detect_windows | ||
detector.platform[:family].must_equal('windows') | ||
detector.platform[:name].must_equal('Windows Server 2008 R2 Standard') | ||
detector.platform[:arch].must_equal('64-bit') | ||
detector.platform[:release].must_equal('6.1.7601') | ||
end | ||
end | ||
|
||
describe 'windows 7' do | ||
let(:detector) { | ||
detector = OsDetectWindowsTester.new | ||
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 6.1.7601]\r\n", '', 0) | ||
detector.backend.mock_command('wmic os get * /format:list',"\r\r\nBuildNumber=7601\r\r\nCaption=Microsoft Windows 7 Enterprise \r\r\nOSArchitecture=32-bit\r\r\nVersion=6.1.7601\r\r\n\r\r\n" , '', 0) | ||
detector | ||
} | ||
|
||
it 'sets the correct family/release for windows' do | ||
detector.detect_windows | ||
detector.platform[:family].must_equal('windows') | ||
detector.platform[:name].must_equal('Windows 7 Enterprise') | ||
detector.platform[:arch].must_equal('32-bit') | ||
detector.platform[:release].must_equal('6.1.7601') | ||
end | ||
end | ||
|
||
describe 'windows 10' do | ||
let(:detector) { | ||
detector = OsDetectWindowsTester.new | ||
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 10.0.10240]\r\n", '', 0) | ||
detector.backend.mock_command('wmic os get * /format:list',"\r\r\nBuildNumber=10240\r\r\nCaption=Microsoft Windows 10 Pro\r\r\nOSArchitecture=64-bit\r\r\nVersion=10.0.10240\r\r\n\r\r\n" , '', 0) | ||
detector | ||
} | ||
|
||
it 'sets the correct family/release for windows' do | ||
detector.detect_windows | ||
detector.platform[:family].must_equal('windows') | ||
detector.platform[:name].must_equal('Windows 10 Pro') | ||
detector.platform[:arch].must_equal('64-bit') | ||
detector.platform[:release].must_equal('10.0.10240') | ||
end | ||
end | ||
|
||
describe 'windows 98' do | ||
let(:detector) { | ||
detector = OsDetectWindowsTester.new | ||
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 4.10.1998]\r\n", '', 0) | ||
detector.backend.mock_command('wmic os get * /format:list', nil , '', 1) | ||
detector | ||
} | ||
|
||
it 'fallback to version number if wmic is not available' do | ||
detector.detect_windows | ||
detector.platform[:family].must_equal('windows') | ||
detector.platform[:name].must_equal('Windows 4.10.1998') | ||
detector.platform[:arch].must_equal(nil) | ||
detector.platform[:release].must_equal('4.10.1998') | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters