train 0.28.0 → 0.29.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +17 -2
- data/lib/train/extras.rb +0 -5
- data/lib/train/extras/os_common.rb +1 -1
- data/lib/train/extras/os_detect_unix.rb +6 -0
- data/lib/train/{extras/file_common.rb → file.rb} +65 -92
- data/lib/train/file/local.rb +70 -0
- data/lib/train/file/local/unix.rb +77 -0
- data/lib/train/file/local/windows.rb +63 -0
- data/lib/train/file/remote.rb +28 -0
- data/lib/train/file/remote/aix.rb +21 -0
- data/lib/train/file/remote/linux.rb +19 -0
- data/lib/train/file/remote/qnx.rb +41 -0
- data/lib/train/file/remote/unix.rb +110 -0
- data/lib/train/file/remote/windows.rb +94 -0
- data/lib/train/plugins/base_connection.rb +2 -1
- data/lib/train/transports/docker.rb +8 -1
- data/lib/train/transports/local.rb +6 -2
- data/lib/train/transports/mock.rb +7 -6
- data/lib/train/transports/ssh.rb +1 -2
- data/lib/train/transports/ssh_connection.rb +24 -4
- data/lib/train/transports/winrm_connection.rb +11 -5
- data/lib/train/version.rb +1 -1
- data/test/integration/tests/path_block_device_test.rb +2 -2
- data/test/integration/tests/path_character_device_test.rb +2 -2
- data/test/integration/tests/path_file_test.rb +2 -2
- data/test/integration/tests/path_folder_test.rb +5 -5
- data/test/integration/tests/path_missing_test.rb +0 -1
- data/test/integration/tests/path_pipe_test.rb +2 -3
- data/test/integration/tests/path_symlink_test.rb +2 -2
- data/test/unit/extras/os_detect_linux_test.rb +3 -3
- data/test/unit/extras/os_detect_windows_test.rb +1 -1
- data/test/unit/file/local/unix_test.rb +112 -0
- data/test/unit/file/local/windows_test.rb +41 -0
- data/test/unit/file/local_test.rb +110 -0
- data/test/unit/{extras/linux_file_test.rb → file/remote/linux_test.rb} +7 -7
- data/test/unit/file/remote/unix_test.rb +44 -0
- data/test/unit/file/remote_test.rb +62 -0
- data/test/unit/file_test.rb +156 -0
- data/test/unit/plugins/transport_test.rb +1 -1
- data/test/unit/transports/mock_test.rb +3 -3
- data/test/windows/local_test.rb +106 -0
- data/test/windows/winrm_test.rb +125 -0
- metadata +26 -16
- data/lib/train/extras/file_aix.rb +0 -20
- data/lib/train/extras/file_linux.rb +0 -16
- data/lib/train/extras/file_unix.rb +0 -79
- data/lib/train/extras/file_windows.rb +0 -100
- data/lib/train/transports/local_file.rb +0 -98
- data/test/unit/extras/file_common_test.rb +0 -180
- data/test/unit/extras/windows_file_test.rb +0 -44
- data/test/unit/transports/local_file_test.rb +0 -202
@@ -1,44 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
require 'helper'
|
3
|
-
require 'train/transports/mock'
|
4
|
-
require 'train/extras'
|
5
|
-
|
6
|
-
describe 'file common' do
|
7
|
-
let(:cls) { Train::Extras::WindowsFile }
|
8
|
-
let(:backend) {
|
9
|
-
backend = Train::Transports::Mock.new.connection
|
10
|
-
backend.mock_os({ family: 'windows' })
|
11
|
-
backend
|
12
|
-
}
|
13
|
-
|
14
|
-
it 'provides the full path' do
|
15
|
-
cls.new(backend, 'C:\dir\file').path.must_equal 'C:\dir\file'
|
16
|
-
end
|
17
|
-
|
18
|
-
it 'provides the basename to a unix path' do
|
19
|
-
cls.new(backend, 'C:\dir\file').basename.must_equal 'file'
|
20
|
-
end
|
21
|
-
|
22
|
-
it 'provides the full path with whitespace' do
|
23
|
-
wf = cls.new(backend, 'C:\Program Files\file name')
|
24
|
-
wf.path.must_equal 'C:\Program Files\file name'
|
25
|
-
wf.basename.must_equal 'file name'
|
26
|
-
end
|
27
|
-
|
28
|
-
it 'reads file contents' do
|
29
|
-
out = rand.to_s
|
30
|
-
backend.mock_command('Get-Content("path") | Out-String', out)
|
31
|
-
cls.new(backend, 'path').content.must_equal out
|
32
|
-
end
|
33
|
-
|
34
|
-
it 'check escaping of invalid chars in path' do
|
35
|
-
wf = cls.new(nil, nil)
|
36
|
-
wf.sanitize_filename('c:/test') .must_equal 'c:/test'
|
37
|
-
wf.sanitize_filename('c:/test directory') .must_equal 'c:/test directory'
|
38
|
-
%w{ < > " * ?}.each do |char|
|
39
|
-
wf.sanitize_filename("c:/test#{char}directory") .must_equal 'c:/testdirectory'
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
# TODO: add all missing file tests!!
|
44
|
-
end
|
@@ -1,202 +0,0 @@
|
|
1
|
-
# encoding: utf-8
|
2
|
-
#
|
3
|
-
# author: Dominik Richter
|
4
|
-
# author: Christoph Hartmann
|
5
|
-
|
6
|
-
require 'helper'
|
7
|
-
require 'train/transports/local'
|
8
|
-
|
9
|
-
describe 'local file transport' do
|
10
|
-
let(:transport) { Train::Transports::Local.new }
|
11
|
-
let(:connection) { transport.connection }
|
12
|
-
|
13
|
-
it 'gets file contents' do
|
14
|
-
res = rand.to_s
|
15
|
-
File.stub :read, res do
|
16
|
-
connection.file(rand.to_s).content.must_equal(res)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'checks for file existance' do
|
21
|
-
File.stub :exist?, true do
|
22
|
-
connection.file(rand.to_s).exist?.must_equal(true)
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
{
|
27
|
-
exist?: :exist?,
|
28
|
-
file?: :file?,
|
29
|
-
socket?: :socket?,
|
30
|
-
directory?: :directory?,
|
31
|
-
symlink?: :symlink?,
|
32
|
-
pipe?: :pipe?,
|
33
|
-
character_device?: :chardev?,
|
34
|
-
block_device?: :blockdev?,
|
35
|
-
}.each do |method, file_method|
|
36
|
-
it "checks if file is a #{method}" do
|
37
|
-
File.stub file_method.to_sym, true do
|
38
|
-
connection.file(rand.to_s).method(method.to_sym).call.must_equal(true)
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
it 'checks a file\'s link path' do
|
44
|
-
out = rand.to_s
|
45
|
-
File.stub :realpath, out do
|
46
|
-
File.stub :symlink?, true do
|
47
|
-
connection.file(rand.to_s).link_path.must_equal out
|
48
|
-
end
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
describe '#path' do
|
53
|
-
it 'returns the path if it is not a symlink' do
|
54
|
-
File.stub :symlink?, false do
|
55
|
-
filename = rand.to_s
|
56
|
-
connection.file(filename).path.must_equal filename
|
57
|
-
end
|
58
|
-
end
|
59
|
-
|
60
|
-
it 'returns the link_path if it is a symlink' do
|
61
|
-
File.stub :symlink?, true do
|
62
|
-
file_obj = connection.file(rand.to_s)
|
63
|
-
file_obj.stub :link_path, '/path/to/resolved_link' do
|
64
|
-
file_obj.path.must_equal '/path/to/resolved_link'
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
end
|
69
|
-
|
70
|
-
describe 'file metadata' do
|
71
|
-
let(:stat) { Struct.new(:mode, :size, :mtime, :uid, :gid) }
|
72
|
-
let(:uid) { rand }
|
73
|
-
let(:gid) { rand }
|
74
|
-
let(:statres) { stat.new(00140755, rand, (rand*100).to_i, uid, gid) }
|
75
|
-
|
76
|
-
def meta_stub(method, param, &block)
|
77
|
-
pwres = Struct.new(:name)
|
78
|
-
Etc.stub :getpwuid, pwres.new('owner') do
|
79
|
-
Etc.stub :getgrgid, pwres.new('group') do
|
80
|
-
File.stub method, param do; yield; end
|
81
|
-
end
|
82
|
-
end
|
83
|
-
end
|
84
|
-
|
85
|
-
it 'recognizes type' do
|
86
|
-
meta_stub :stat, statres do
|
87
|
-
connection.file(rand.to_s).type.must_equal :socket
|
88
|
-
end
|
89
|
-
end
|
90
|
-
|
91
|
-
it 'recognizes mode' do
|
92
|
-
meta_stub :stat, statres do
|
93
|
-
connection.file(rand.to_s).mode.must_equal 00755
|
94
|
-
end
|
95
|
-
end
|
96
|
-
|
97
|
-
it 'recognizes mtime' do
|
98
|
-
meta_stub :stat, statres do
|
99
|
-
connection.file(rand.to_s).mtime.must_equal statres.mtime
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
it 'recognizes size' do
|
104
|
-
meta_stub :stat, statres do
|
105
|
-
connection.file(rand.to_s).size.must_equal statres.size
|
106
|
-
end
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'recognizes owner' do
|
110
|
-
meta_stub :stat, statres do
|
111
|
-
connection.file(rand.to_s).owner.must_equal 'owner'
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'recognizes uid' do
|
116
|
-
meta_stub :stat, statres do
|
117
|
-
connection.file(rand.to_s).uid.must_equal uid
|
118
|
-
end
|
119
|
-
end
|
120
|
-
|
121
|
-
it 'recognizes group' do
|
122
|
-
meta_stub :stat, statres do
|
123
|
-
connection.file(rand.to_s).group.must_equal 'group'
|
124
|
-
end
|
125
|
-
end
|
126
|
-
|
127
|
-
it 'recognizes gid' do
|
128
|
-
meta_stub :stat, statres do
|
129
|
-
connection.file(rand.to_s).gid.must_equal gid
|
130
|
-
end
|
131
|
-
end
|
132
|
-
|
133
|
-
it 'recognizes selinux label' do
|
134
|
-
meta_stub :stat, statres do
|
135
|
-
label = rand.to_s
|
136
|
-
res = Train::Extras::CommandResult.new(label, nil, 0)
|
137
|
-
connection.stub :run_command, res do
|
138
|
-
connection.file(rand.to_s).selinux_label.must_equal label
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'recognizes source type' do
|
144
|
-
meta_stub :lstat, statres do
|
145
|
-
connection.file(rand.to_s).source.type.must_equal :socket
|
146
|
-
end
|
147
|
-
end
|
148
|
-
|
149
|
-
it 'recognizes source mode' do
|
150
|
-
meta_stub :lstat, statres do
|
151
|
-
connection.file(rand.to_s).source.mode.must_equal 00755
|
152
|
-
end
|
153
|
-
end
|
154
|
-
|
155
|
-
it 'recognizes source mtime' do
|
156
|
-
meta_stub :lstat, statres do
|
157
|
-
connection.file(rand.to_s).source.mtime.must_equal statres.mtime
|
158
|
-
end
|
159
|
-
end
|
160
|
-
|
161
|
-
it 'recognizes source size' do
|
162
|
-
meta_stub :lstat, statres do
|
163
|
-
connection.file(rand.to_s).source.size.must_equal statres.size
|
164
|
-
end
|
165
|
-
end
|
166
|
-
|
167
|
-
it 'recognizes source owner' do
|
168
|
-
meta_stub :lstat, statres do
|
169
|
-
connection.file(rand.to_s).source.owner.must_equal 'owner'
|
170
|
-
end
|
171
|
-
end
|
172
|
-
|
173
|
-
it 'recognizes source uid' do
|
174
|
-
meta_stub :lstat, statres do
|
175
|
-
connection.file(rand.to_s).source.uid.must_equal uid
|
176
|
-
end
|
177
|
-
end
|
178
|
-
|
179
|
-
it 'recognizes source owner' do
|
180
|
-
meta_stub :lstat, statres do
|
181
|
-
connection.file(rand.to_s).source.owner.must_equal 'owner'
|
182
|
-
end
|
183
|
-
end
|
184
|
-
|
185
|
-
it 'recognizes source gid' do
|
186
|
-
meta_stub :lstat, statres do
|
187
|
-
connection.file(rand.to_s).source.gid.must_equal gid
|
188
|
-
end
|
189
|
-
end
|
190
|
-
|
191
|
-
it 'recognizes source selinux label' do
|
192
|
-
meta_stub :lstat, statres do
|
193
|
-
label = rand.to_s
|
194
|
-
res = Train::Extras::CommandResult.new(label, nil, 0)
|
195
|
-
connection.stub :run_command, res do
|
196
|
-
connection.file(rand.to_s).source.selinux_label.must_equal label
|
197
|
-
end
|
198
|
-
end
|
199
|
-
end
|
200
|
-
end
|
201
|
-
|
202
|
-
end
|