train 1.5.11 → 1.6.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/train/transports/winrm.rb +16 -4
- data/lib/train/version.rb +1 -1
- metadata +3 -165
- data/.rubocop.yml +0 -77
- data/CHANGELOG.md +0 -900
- data/Gemfile +0 -41
- data/README.md +0 -212
- data/Rakefile +0 -73
- data/test/fixtures/plugins/train-test-fixture/LICENSE +0 -201
- data/test/fixtures/plugins/train-test-fixture/README.md +0 -5
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/connection.rb +0 -35
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/platform.rb +0 -18
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/transport.rb +0 -14
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture/version.rb +0 -5
- data/test/fixtures/plugins/train-test-fixture/lib/train-test-fixture.rb +0 -4
- data/test/fixtures/plugins/train-test-fixture/pkg/train-test-fixture-0.1.0.gem +0 -0
- data/test/fixtures/plugins/train-test-fixture/train-test-fixture.gemspec +0 -35
- data/test/integration/.kitchen.yml +0 -43
- data/test/integration/Berksfile +0 -3
- data/test/integration/bootstrap.sh +0 -22
- data/test/integration/chefignore +0 -1
- data/test/integration/cookbooks/test/metadata.rb +0 -1
- data/test/integration/cookbooks/test/recipes/default.rb +0 -100
- data/test/integration/cookbooks/test/recipes/prep_files.rb +0 -56
- data/test/integration/docker_run.rb +0 -153
- data/test/integration/docker_test.rb +0 -24
- data/test/integration/docker_test_container.rb +0 -24
- data/test/integration/helper.rb +0 -61
- data/test/integration/sudo/customcommand.rb +0 -15
- data/test/integration/sudo/nopasswd.rb +0 -16
- data/test/integration/sudo/passwd.rb +0 -21
- data/test/integration/sudo/reqtty.rb +0 -17
- data/test/integration/sudo/run_as.rb +0 -12
- data/test/integration/test-travis-centos.yml +0 -6
- data/test/integration/test-travis-debian.yml +0 -6
- data/test/integration/test-travis-fedora.yml +0 -8
- data/test/integration/test-travis-oel.yml +0 -6
- data/test/integration/test-travis-ubuntu.yml +0 -8
- data/test/integration/test_local.rb +0 -19
- data/test/integration/test_ssh.rb +0 -39
- data/test/integration/tests/path_block_device_test.rb +0 -74
- data/test/integration/tests/path_character_device_test.rb +0 -74
- data/test/integration/tests/path_file_test.rb +0 -99
- data/test/integration/tests/path_folder_test.rb +0 -90
- data/test/integration/tests/path_missing_test.rb +0 -76
- data/test/integration/tests/path_pipe_test.rb +0 -62
- data/test/integration/tests/path_symlink_test.rb +0 -95
- data/test/integration/tests/run_command_test.rb +0 -35
- data/test/unit/extras/command_wrapper_test.rb +0 -110
- data/test/unit/extras/stat_test.rb +0 -210
- data/test/unit/file/local/unix_test.rb +0 -224
- data/test/unit/file/local/windows_test.rb +0 -101
- data/test/unit/file/local_test.rb +0 -121
- data/test/unit/file/remote/aix_test.rb +0 -81
- data/test/unit/file/remote/linux_test.rb +0 -221
- data/test/unit/file/remote/qnx_test.rb +0 -80
- data/test/unit/file/remote/unix_test.rb +0 -119
- data/test/unit/file/remote/windows_test.rb +0 -72
- data/test/unit/file/remote_test.rb +0 -62
- data/test/unit/file_test.rb +0 -129
- data/test/unit/helper.rb +0 -7
- data/test/unit/platforms/detect/os_common_test.rb +0 -85
- data/test/unit/platforms/detect/os_linux_test.rb +0 -132
- data/test/unit/platforms/detect/os_windows_test.rb +0 -107
- data/test/unit/platforms/detect/scanner_test.rb +0 -61
- data/test/unit/platforms/detect/uuid_test.rb +0 -133
- data/test/unit/platforms/family_test.rb +0 -32
- data/test/unit/platforms/os_detect_test.rb +0 -249
- data/test/unit/platforms/platform_test.rb +0 -405
- data/test/unit/platforms/platforms_test.rb +0 -52
- data/test/unit/plugins/connection_test.rb +0 -219
- data/test/unit/plugins/transport_test.rb +0 -111
- data/test/unit/plugins_test.rb +0 -22
- data/test/unit/train_test.rb +0 -247
- data/test/unit/transports/aws_test.rb +0 -120
- data/test/unit/transports/azure_test.rb +0 -145
- data/test/unit/transports/cisco_ios_connection.rb +0 -92
- data/test/unit/transports/gcp_test.rb +0 -266
- data/test/unit/transports/helpers/azure/file_credentials_test.rb +0 -129
- data/test/unit/transports/local_test.rb +0 -183
- data/test/unit/transports/mock_test.rb +0 -150
- data/test/unit/transports/ssh_test.rb +0 -330
- data/test/unit/transports/vmware_test.rb +0 -159
- data/test/unit/version_test.rb +0 -8
- data/test/windows/local_test.rb +0 -243
- data/test/windows/winrm_test.rb +0 -187
- data/train.gemspec +0 -45
@@ -1,62 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
require 'train/file/remote'
|
3
|
-
|
4
|
-
describe Train::File::Remote do
|
5
|
-
let(:cls) { Train::File::Remote }
|
6
|
-
|
7
|
-
def mockup(stubs)
|
8
|
-
Class.new(cls) do
|
9
|
-
stubs.each do |k,v|
|
10
|
-
define_method k.to_sym do
|
11
|
-
v
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end.new(nil, nil, false)
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'basename helper' do
|
18
|
-
def fc(path)
|
19
|
-
mockup(type: :file, path: path)
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'works with an empty path' do
|
23
|
-
fc('').basename.must_equal ''
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'separates a simple path (defaults to unix mode)' do
|
27
|
-
fc('/dir/file').basename.must_equal 'file'
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'separates a simple path (Unix mode)' do
|
31
|
-
fc('/dir/file').basename(nil, '/').must_equal 'file'
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'separates a simple path (Windows mode)' do
|
35
|
-
fc('C:\dir\file').basename(nil, '\\').must_equal 'file'
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'identifies a folder name (Unix mode)' do
|
39
|
-
fc('/dir/file/').basename(nil, '/').must_equal 'file'
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'identifies a folder name (Windows mode)' do
|
43
|
-
fc('C:\dir\file\\').basename(nil, '\\').must_equal 'file'
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'ignores tailing separators (Unix mode)' do
|
47
|
-
fc('/dir/file///').basename(nil, '/').must_equal 'file'
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'ignores tailing separators (Windows mode)' do
|
51
|
-
fc('C:\dir\file\\\\\\').basename(nil, '\\').must_equal 'file'
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'doesnt work with backward slashes (Unix mode)' do
|
55
|
-
fc('C:\dir\file').basename(nil, '/').must_equal 'C:\\dir\file'
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'doesnt work with forward slashes (Windows mode)' do
|
59
|
-
fc('/dir/file').basename(nil, '\\').must_equal '/dir/file'
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
data/test/unit/file_test.rb
DELETED
@@ -1,129 +0,0 @@
|
|
1
|
-
require 'helper'
|
2
|
-
|
3
|
-
describe Train::File do
|
4
|
-
let(:cls) { Train::File }
|
5
|
-
let(:new_cls) { cls.new(nil, '/temp/file', false) }
|
6
|
-
|
7
|
-
def mockup(stubs)
|
8
|
-
Class.new(cls) do
|
9
|
-
stubs.each do |k,v|
|
10
|
-
define_method k.to_sym do
|
11
|
-
v
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end.new(nil, nil, false)
|
15
|
-
end
|
16
|
-
|
17
|
-
it 'has the default type of unknown' do
|
18
|
-
new_cls.type.must_equal :unknown
|
19
|
-
end
|
20
|
-
|
21
|
-
it 'throws Not implemented error for exist?' do
|
22
|
-
# proc { Train.validate_backend({ host: rand }) }.must_raise Train::UserError
|
23
|
-
proc { new_cls.exist?}.must_raise NotImplementedError
|
24
|
-
end
|
25
|
-
|
26
|
-
it 'throws Not implemented error for mode' do
|
27
|
-
proc { new_cls.mode }.must_raise NotImplementedError
|
28
|
-
end
|
29
|
-
|
30
|
-
it 'throws Not implemented error for owner' do
|
31
|
-
proc { new_cls.owner }.must_raise NotImplementedError
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'throws Not implemented error for group' do
|
35
|
-
proc { new_cls.group }.must_raise NotImplementedError
|
36
|
-
end
|
37
|
-
|
38
|
-
it 'throws Not implemented error for uid' do
|
39
|
-
proc { new_cls.uid }.must_raise NotImplementedError
|
40
|
-
end
|
41
|
-
|
42
|
-
it 'throws Not implemented error for gid' do
|
43
|
-
proc { new_cls.gid }.must_raise NotImplementedError
|
44
|
-
end
|
45
|
-
|
46
|
-
it 'throws Not implemented error for content' do
|
47
|
-
proc { new_cls.content }.must_raise NotImplementedError
|
48
|
-
end
|
49
|
-
|
50
|
-
it 'throws Not implemented error for mtime' do
|
51
|
-
proc { new_cls.mtime }.must_raise NotImplementedError
|
52
|
-
end
|
53
|
-
|
54
|
-
it 'throws Not implemented error for size' do
|
55
|
-
proc { new_cls.size }.must_raise NotImplementedError
|
56
|
-
end
|
57
|
-
|
58
|
-
it 'throws Not implemented error for selinux_label' do
|
59
|
-
proc { new_cls.selinux_label }.must_raise NotImplementedError
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'return path of file' do
|
63
|
-
new_cls.path.must_equal('/temp/file')
|
64
|
-
end
|
65
|
-
|
66
|
-
it 'set product_version to nil' do
|
67
|
-
new_cls.product_version.must_be_nil
|
68
|
-
end
|
69
|
-
|
70
|
-
it 'set product_version to nil' do
|
71
|
-
new_cls.file_version.must_be_nil
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'type' do
|
75
|
-
it 'recognized type == file' do
|
76
|
-
fc = mockup(type: :file)
|
77
|
-
fc.file?.must_equal true
|
78
|
-
end
|
79
|
-
|
80
|
-
it 'recognized type == block_device' do
|
81
|
-
fc = mockup(type: :block_device)
|
82
|
-
fc.block_device?.must_equal true
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'recognized type == character_device' do
|
86
|
-
fc = mockup(type: :character_device)
|
87
|
-
fc.character_device?.must_equal true
|
88
|
-
end
|
89
|
-
|
90
|
-
it 'recognized type == socket' do
|
91
|
-
fc = mockup(type: :socket)
|
92
|
-
fc.socket?.must_equal true
|
93
|
-
end
|
94
|
-
|
95
|
-
it 'recognized type == directory' do
|
96
|
-
fc = mockup(type: :directory)
|
97
|
-
fc.directory?.must_equal true
|
98
|
-
end
|
99
|
-
|
100
|
-
it 'recognized type == pipe' do
|
101
|
-
fc = mockup(type: :pipe)
|
102
|
-
fc.pipe?.must_equal true
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'recognized type == symlink' do
|
106
|
-
fc = mockup(type: :symlink)
|
107
|
-
fc.symlink?.must_equal true
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe 'version' do
|
112
|
-
it 'recognized wrong version' do
|
113
|
-
fc = mockup(product_version: rand, file_version: rand)
|
114
|
-
fc.version?(rand).must_equal false
|
115
|
-
end
|
116
|
-
|
117
|
-
it 'recognized product_version' do
|
118
|
-
x = rand
|
119
|
-
fc = mockup(product_version: x, file_version: rand)
|
120
|
-
fc.version?(x).must_equal true
|
121
|
-
end
|
122
|
-
|
123
|
-
it 'recognized file_version' do
|
124
|
-
x = rand
|
125
|
-
fc = mockup(product_version: rand, file_version: x)
|
126
|
-
fc.version?(x).must_equal true
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
data/test/unit/helper.rb
DELETED
@@ -1,85 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
|
5
|
-
class OsDetectLinuxTester
|
6
|
-
attr_reader :platform
|
7
|
-
include Train::Platforms::Detect::Helpers::OSCommon
|
8
|
-
|
9
|
-
def initialize
|
10
|
-
@platform = {}
|
11
|
-
end
|
12
|
-
end
|
13
|
-
|
14
|
-
describe 'os_common' do
|
15
|
-
let(:detector) { OsDetectLinuxTester.new }
|
16
|
-
|
17
|
-
describe 'winrm? check' do
|
18
|
-
it 'return winrm? true' do
|
19
|
-
require 'train/transports/winrm'
|
20
|
-
be = Train::Transports::WinRM::Connection.new(nil)
|
21
|
-
detector.instance_variable_set(:@backend, be)
|
22
|
-
detector.winrm?.must_equal(true)
|
23
|
-
end
|
24
|
-
|
25
|
-
it 'return winrm? false' do
|
26
|
-
be = mock('Backend')
|
27
|
-
detector.instance_variable_set(:@backend, be)
|
28
|
-
detector.winrm?.must_equal(false)
|
29
|
-
end
|
30
|
-
end
|
31
|
-
|
32
|
-
describe 'unix file contents' do
|
33
|
-
it 'return new file contents' do
|
34
|
-
be = mock('Backend')
|
35
|
-
output = mock('Output', exit_status: 0)
|
36
|
-
output.expects(:stdout).returns('test')
|
37
|
-
be.stubs(:run_command).with('test -f /etc/fstab && cat /etc/fstab').returns(output)
|
38
|
-
detector.instance_variable_set(:@backend, be)
|
39
|
-
detector.instance_variable_set(:@files, {})
|
40
|
-
detector.unix_file_contents('/etc/fstab').must_equal('test')
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'return new file contents cached' do
|
44
|
-
be = mock('Backend')
|
45
|
-
detector.instance_variable_set(:@backend, be)
|
46
|
-
detector.instance_variable_set(:@files, { '/etc/profile' => 'test' })
|
47
|
-
detector.unix_file_contents('/etc/profile').must_equal('test')
|
48
|
-
end
|
49
|
-
end
|
50
|
-
|
51
|
-
describe 'unix file exist?' do
|
52
|
-
it 'file does exist' do
|
53
|
-
be = mock('Backend')
|
54
|
-
be.stubs(:run_command).with('test -f /etc/test').returns(mock('Output', exit_status: 0))
|
55
|
-
detector.instance_variable_set(:@backend, be)
|
56
|
-
detector.unix_file_exist?('/etc/test').must_equal(true)
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
describe '#detect_linux_arch' do
|
61
|
-
it 'uname m call' do
|
62
|
-
be = mock('Backend')
|
63
|
-
be.stubs(:run_command).with('uname -m').returns(mock('Output', stdout: "x86_64\n"))
|
64
|
-
detector.instance_variable_set(:@backend, be)
|
65
|
-
detector.instance_variable_set(:@uname, {})
|
66
|
-
detector.unix_uname_m.must_equal('x86_64')
|
67
|
-
end
|
68
|
-
|
69
|
-
it 'uname s call' do
|
70
|
-
be = mock('Backend')
|
71
|
-
be.stubs(:run_command).with('uname -s').returns(mock('Output', stdout: "linux"))
|
72
|
-
detector.instance_variable_set(:@backend, be)
|
73
|
-
detector.instance_variable_set(:@uname, {})
|
74
|
-
detector.unix_uname_s.must_equal('linux')
|
75
|
-
end
|
76
|
-
|
77
|
-
it 'uname r call' do
|
78
|
-
be = mock('Backend')
|
79
|
-
be.stubs(:run_command).with('uname -r').returns(mock('Output', stdout: "17.0.0\n"))
|
80
|
-
detector.instance_variable_set(:@backend, be)
|
81
|
-
detector.instance_variable_set(:@uname, {})
|
82
|
-
detector.unix_uname_r.must_equal('17.0.0')
|
83
|
-
end
|
84
|
-
end
|
85
|
-
end
|
@@ -1,132 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'train/transports/mock'
|
5
|
-
|
6
|
-
class OsDetectLinuxTester
|
7
|
-
include Train::Platforms::Detect::Helpers::OSCommon
|
8
|
-
end
|
9
|
-
|
10
|
-
describe 'os_linux' do
|
11
|
-
let(:detector) { OsDetectLinuxTester.new }
|
12
|
-
|
13
|
-
describe 'redhatish_platform cleaner' do
|
14
|
-
it 'normal redhat' do
|
15
|
-
detector.redhatish_platform('Red Hattter').must_equal('redhat')
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'custom redhat' do
|
19
|
-
detector.redhatish_platform('Centos Pro 11').must_equal('centos')
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe 'redhatish_version cleaner' do
|
24
|
-
it 'normal rawhide' do
|
25
|
-
detector.redhatish_version('18 (Rawhide) Pro').must_equal('18 (rawhide)')
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'normal linux' do
|
29
|
-
detector.redhatish_version('derived from Ubuntu Linux 11').must_equal('11')
|
30
|
-
end
|
31
|
-
|
32
|
-
it 'amazon linux 2 new release naming schema' do
|
33
|
-
detector.redhatish_version('Amazon Linux release 2 (Karoo)').must_equal('2')
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'amazon linux 2 old release naming schema' do
|
37
|
-
detector.redhatish_version('Amazon Linux 2').must_equal('2')
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe 'lsb parse' do
|
42
|
-
it 'lsb config' do
|
43
|
-
lsb = "DISTRIB_ID=Ubuntu\nDISTRIB_RELEASE=14.06\nDISTRIB_CODENAME=xenial"
|
44
|
-
expect = { :id=>'Ubuntu', :release=>'14.06', :codename=>'xenial' }
|
45
|
-
detector.lsb_config(lsb).must_equal(expect)
|
46
|
-
end
|
47
|
-
|
48
|
-
it 'lsb releasel' do
|
49
|
-
lsb = "Distributor ID: Ubuntu\nRelease: 14.06\nCodename: xenial"
|
50
|
-
expect = { :id=>'Ubuntu', :release=>'14.06', :codename=>'xenial' }
|
51
|
-
detector.lsb_release(lsb).must_equal(expect)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
|
55
|
-
describe '#linux_os_release' do
|
56
|
-
describe 'when no os-release data is available' do
|
57
|
-
it 'returns nil' do
|
58
|
-
detector.expects(:unix_file_contents).with('/etc/os-release').returns(nil)
|
59
|
-
detector.linux_os_release.must_be_nil
|
60
|
-
end
|
61
|
-
end
|
62
|
-
end
|
63
|
-
|
64
|
-
describe 'when os-release data exists with no CISCO_RELEASE_INFO' do
|
65
|
-
let(:os_release) { { 'KEY1' => 'VALUE1' } }
|
66
|
-
|
67
|
-
it 'returns a correct hash' do
|
68
|
-
detector.expects(:unix_file_contents).with('/etc/os-release').returns('os-release data')
|
69
|
-
detector.expects(:parse_os_release_info).with('os-release data').returns(os_release)
|
70
|
-
detector.linux_os_release['KEY1'].must_equal('VALUE1')
|
71
|
-
end
|
72
|
-
end
|
73
|
-
|
74
|
-
describe 'when os-release data exists with CISCO_RELEASE_INFO' do
|
75
|
-
let(:os_release) { { 'KEY1' => 'VALUE1', 'CISCO_RELEASE_INFO' => 'cisco_file' } }
|
76
|
-
let(:cisco_release) { { 'KEY1' => 'NEWVALUE1', 'KEY2' => 'VALUE2' } }
|
77
|
-
|
78
|
-
it 'returns a correct hash' do
|
79
|
-
detector.expects(:unix_file_contents).with('/etc/os-release').returns('os-release data')
|
80
|
-
detector.expects(:unix_file_contents).with('cisco_file').returns('cisco data')
|
81
|
-
detector.expects(:parse_os_release_info).with('os-release data').returns(os_release)
|
82
|
-
detector.expects(:parse_os_release_info).with('cisco data').returns(cisco_release)
|
83
|
-
|
84
|
-
os_info = detector.linux_os_release
|
85
|
-
os_info['KEY1'].must_equal('NEWVALUE1')
|
86
|
-
os_info['KEY2'].must_equal('VALUE2')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe '#parse_os_release_info' do
|
91
|
-
describe 'when nil is supplied' do
|
92
|
-
it 'returns an empty hash' do
|
93
|
-
detector.parse_os_release_info(nil).must_equal({})
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
describe 'when unexpectedly-formatted data is supplied' do
|
98
|
-
let(:data) do
|
99
|
-
<<-EOL
|
100
|
-
blah blah
|
101
|
-
no good data here
|
102
|
-
EOL
|
103
|
-
end
|
104
|
-
|
105
|
-
it 'returns an empty hash' do
|
106
|
-
detector.parse_os_release_info(nil).must_equal({})
|
107
|
-
end
|
108
|
-
end
|
109
|
-
|
110
|
-
describe 'when properly-formatted data is supplied' do
|
111
|
-
let(:data) do
|
112
|
-
<<-EOL
|
113
|
-
KEY1=value1
|
114
|
-
KEY2=
|
115
|
-
KEY3=value3
|
116
|
-
KEY4="value4 with spaces"
|
117
|
-
KEY5="value5 with a = sign"
|
118
|
-
EOL
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'parses the data correctly' do
|
122
|
-
parsed_data = detector.parse_os_release_info(data)
|
123
|
-
|
124
|
-
parsed_data['KEY1'].must_equal('value1')
|
125
|
-
parsed_data.key?('KEY2').must_equal(false)
|
126
|
-
parsed_data['KEY3'].must_equal('value3')
|
127
|
-
parsed_data['KEY4'].must_equal('value4 with spaces')
|
128
|
-
parsed_data['KEY5'].must_equal('value5 with a = sign')
|
129
|
-
end
|
130
|
-
end
|
131
|
-
end
|
132
|
-
end
|
@@ -1,107 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'train/transports/mock'
|
5
|
-
|
6
|
-
class OsDetectWindowsTester
|
7
|
-
attr_reader :platform, :backend
|
8
|
-
include Train::Platforms::Detect::Helpers::Windows
|
9
|
-
|
10
|
-
def initialize
|
11
|
-
@platform = {}
|
12
|
-
@backend = Train::Transports::Mock.new.connection
|
13
|
-
@backend.mock_os({ family: 'windows' })
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
describe 'os_detect_windows' do
|
18
|
-
describe 'windows 2012' do
|
19
|
-
let(:detector) {
|
20
|
-
detector = OsDetectWindowsTester.new
|
21
|
-
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 6.3.9600]\r\n", '', 0)
|
22
|
-
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)
|
23
|
-
detector.backend.mock_command('wmic cpu get architecture /format:list',"\r\r\nArchitecture=9\r\r\n" , '', 0)
|
24
|
-
detector
|
25
|
-
}
|
26
|
-
|
27
|
-
it 'sets the correct family/release for windows' do
|
28
|
-
detector.detect_windows
|
29
|
-
detector.platform[:family].must_equal('windows')
|
30
|
-
detector.platform[:name].must_equal('Windows Server 2012 R2 Standard')
|
31
|
-
detector.platform[:arch].must_equal('x86_64')
|
32
|
-
detector.platform[:release].must_equal('6.3.9600')
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
describe 'windows 2008' do
|
37
|
-
let(:detector) {
|
38
|
-
detector = OsDetectWindowsTester.new
|
39
|
-
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 6.1.7601]\r\n", '', 0)
|
40
|
-
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)
|
41
|
-
detector.backend.mock_command('wmic cpu get architecture /format:list',"\r\r\nArchitecture=9\r\r\n" , '', 0)
|
42
|
-
detector
|
43
|
-
}
|
44
|
-
|
45
|
-
it 'sets the correct family/release for windows' do
|
46
|
-
detector.detect_windows
|
47
|
-
detector.platform[:family].must_equal('windows')
|
48
|
-
detector.platform[:name].must_equal('Windows Server 2008 R2 Standard')
|
49
|
-
detector.platform[:arch].must_equal('x86_64')
|
50
|
-
detector.platform[:release].must_equal('6.1.7601')
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
describe 'windows 7' do
|
55
|
-
let(:detector) {
|
56
|
-
detector = OsDetectWindowsTester.new
|
57
|
-
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 6.1.7601]\r\n", '', 0)
|
58
|
-
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)
|
59
|
-
detector.backend.mock_command('wmic cpu get architecture /format:list',"\r\r\nArchitecture=0\r\r\n" , '', 0)
|
60
|
-
detector
|
61
|
-
}
|
62
|
-
|
63
|
-
it 'sets the correct family/release for windows' do
|
64
|
-
detector.detect_windows
|
65
|
-
detector.platform[:family].must_equal('windows')
|
66
|
-
detector.platform[:name].must_equal('Windows 7 Enterprise')
|
67
|
-
detector.platform[:arch].must_equal('i386')
|
68
|
-
detector.platform[:release].must_equal('6.1.7601')
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
describe 'windows 10' do
|
73
|
-
let(:detector) {
|
74
|
-
detector = OsDetectWindowsTester.new
|
75
|
-
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 10.0.10240]\r\n", '', 0)
|
76
|
-
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)
|
77
|
-
detector.backend.mock_command('wmic cpu get architecture /format:list',"\r\r\nArchitecture=9\r\r\n" , '', 0)
|
78
|
-
detector
|
79
|
-
}
|
80
|
-
|
81
|
-
it 'sets the correct family/release for windows' do
|
82
|
-
detector.detect_windows
|
83
|
-
detector.platform[:family].must_equal('windows')
|
84
|
-
detector.platform[:name].must_equal('Windows 10 Pro')
|
85
|
-
detector.platform[:arch].must_equal('x86_64')
|
86
|
-
detector.platform[:release].must_equal('10.0.10240')
|
87
|
-
end
|
88
|
-
end
|
89
|
-
|
90
|
-
describe 'windows 98' do
|
91
|
-
let(:detector) {
|
92
|
-
detector = OsDetectWindowsTester.new
|
93
|
-
detector.backend.mock_command('cmd /c ver', "\r\nMicrosoft Windows [Version 4.10.1998]\r\n", '', 0)
|
94
|
-
detector.backend.mock_command('wmic os get * /format:list', nil, '', 1)
|
95
|
-
detector.backend.mock_command('wmic cpu get architecture /format:list', nil, '', 1)
|
96
|
-
detector
|
97
|
-
}
|
98
|
-
|
99
|
-
it 'fallback to version number if wmic is not available' do
|
100
|
-
detector.detect_windows
|
101
|
-
detector.platform[:family].must_equal('windows')
|
102
|
-
detector.platform[:name].must_equal('Windows 4.10.1998')
|
103
|
-
detector.platform[:arch].must_be_nil
|
104
|
-
detector.platform[:release].must_equal('4.10.1998')
|
105
|
-
end
|
106
|
-
end
|
107
|
-
end
|
@@ -1,61 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
|
3
|
-
require 'helper'
|
4
|
-
require 'train/platforms/detect/scanner'
|
5
|
-
require 'train/transports/mock'
|
6
|
-
|
7
|
-
describe 'scanner' do
|
8
|
-
let(:backend) { Train::Transports::Mock::Connection.new }
|
9
|
-
let(:scanner) { Train::Platforms::Detect::Scanner.new(backend) }
|
10
|
-
|
11
|
-
describe 'scan family children' do
|
12
|
-
it 'return child' do
|
13
|
-
family = Train::Platforms.family('linux')
|
14
|
-
scanner.scan_family_children(family).name.must_equal('linux')
|
15
|
-
scanner.instance_variable_get(:@family_hierarchy).must_equal(['linux'])
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'return nil' do
|
19
|
-
family = Train::Platforms.family('fake-fam')
|
20
|
-
scanner.scan_family_children(family).must_be_nil
|
21
|
-
scanner.instance_variable_get(:@family_hierarchy).must_be_empty
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
describe 'check condition' do
|
26
|
-
it 'return true equal' do
|
27
|
-
scanner.instance_variable_set(:@platform, { arch: 'x86_64' })
|
28
|
-
scanner.check_condition({ arch: '= x86_64' }).must_equal(true)
|
29
|
-
end
|
30
|
-
|
31
|
-
it 'return true greater then' do
|
32
|
-
scanner.instance_variable_set(:@platform, { release: '8.2' })
|
33
|
-
scanner.check_condition({ release: '>= 7' }).must_equal(true)
|
34
|
-
end
|
35
|
-
|
36
|
-
it 'return false greater then' do
|
37
|
-
scanner.instance_variable_set(:@platform, { release: '2.2' })
|
38
|
-
scanner.check_condition({ release: '> 7' }).must_equal(false)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
|
42
|
-
describe 'get platform' do
|
43
|
-
it 'return empty platform' do
|
44
|
-
plat = Train::Platforms.name('linux')
|
45
|
-
plat = scanner.get_platform(plat)
|
46
|
-
plat.platform.must_equal({})
|
47
|
-
plat.backend.must_equal(backend)
|
48
|
-
plat.family_hierarchy.must_equal([])
|
49
|
-
end
|
50
|
-
|
51
|
-
it 'return full platform' do
|
52
|
-
scanner.instance_variable_set(:@platform, { family: 'linux' })
|
53
|
-
scanner.instance_variable_set(:@family_hierarchy, [ 'linux', 'unix' ])
|
54
|
-
plat = Train::Platforms.name('linux')
|
55
|
-
plat = scanner.get_platform(plat)
|
56
|
-
plat.platform.must_equal({ family: 'linux' })
|
57
|
-
plat.backend.must_equal(backend)
|
58
|
-
plat.family_hierarchy.must_equal([ 'linux', 'unix' ])
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|