Skip to content

Commit

Permalink
Add more tests
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Scherer <[email protected]>
  • Loading branch information
StefanScherer committed Apr 28, 2019
1 parent 201b91e commit 78e69f5
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 2 deletions.
19 changes: 19 additions & 0 deletions test/unit/platforms/detect/os_windows_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,23 @@ def initialize
detector.platform[:release].must_equal('4.10.1998')
end
end

describe 'windows 2019 Microsoft OpenSSH' do
let(:detector) {
detector = OsDetectWindowsTester.new
detector.backend.mock_command('cmd /c ver', "\'ver\"\' is not recognized as an internal or external command,\r\noperable program or batch file.", '', 1)
detector.backend.mock_command('ver', "\r\nMicrosoft Windows [Version 10.0.17763.437]\r\n", '', 0)
detector.backend.mock_command('wmic os get * /format:list',"\r\r\nBuildNumber=17763\r\r\nCaption=Microsoft Windows Server 2019 Standard\r\r\nOSArchitecture=64-bit\r\r\nVersion=10.0.17763\r\r\n" , '', 0)
detector.backend.mock_command('wmic cpu get architecture /format:list',"\r\r\nArchitecture=9\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 2019 Standard')
detector.platform[:arch].must_equal('x86_64')
detector.platform[:release].must_equal('10.0.17763')
end
end
end
20 changes: 18 additions & 2 deletions test/unit/platforms/os_detect_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@
require 'helper'
require 'train/transports/mock'

class OsDetectLinuxTester
class OsDetectTester
include Train::Platforms::Detect::Helpers::OSCommon
end

describe 'os_detect' do
let(:detector) { OsDetectLinuxTester.new }
let(:detector) { OsDetectTester.new }

def scan_with_files(uname, files)
mock = Train::Transports::Mock::Connection.new
Expand All @@ -20,6 +20,12 @@ def scan_with_files(uname, files)
Train::Platforms::Detect.scan(mock)
end

def scan_with_windows()
mock = Train::Transports::Mock::Connection.new
mock.mock_command('cmd /c ver', 'Microsoft Windows [Version 6.3.9600]')
Train::Platforms::Detect.scan(mock)
end

## Detect all linux distros
describe '/etc/enterprise-release' do
it 'sets the correct family/release for oracle' do
Expand Down Expand Up @@ -148,6 +154,16 @@ def debian_scan(id, version)
end
end

describe 'windows' do
it 'sets the correct family/release for windows ' do
platform = scan_with_windows()

platform[:name].must_equal('windows_6.3.9600')
platform[:family].must_equal('windows')
platform[:release].must_equal('6.3.9600')
end
end

describe 'everything else' do
it 'sets the correct family/release for debian ' do
platform = debian_scan('some_debian', '12.99')
Expand Down

0 comments on commit 78e69f5

Please sign in to comment.