r-train 0.9.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +45 -0
- data/.travis.yml +12 -0
- data/Gemfile +22 -0
- data/LICENSE +201 -0
- data/README.md +137 -0
- data/Rakefile +39 -0
- data/lib/train.rb +100 -0
- data/lib/train/errors.rb +23 -0
- data/lib/train/extras.rb +15 -0
- data/lib/train/extras/command_wrapper.rb +105 -0
- data/lib/train/extras/file_common.rb +131 -0
- data/lib/train/extras/linux_file.rb +74 -0
- data/lib/train/extras/linux_lsb.rb +60 -0
- data/lib/train/extras/os_common.rb +131 -0
- data/lib/train/extras/os_detect_darwin.rb +32 -0
- data/lib/train/extras/os_detect_linux.rb +126 -0
- data/lib/train/extras/os_detect_unix.rb +77 -0
- data/lib/train/extras/os_detect_windows.rb +73 -0
- data/lib/train/extras/stat.rb +92 -0
- data/lib/train/extras/windows_file.rb +85 -0
- data/lib/train/options.rb +80 -0
- data/lib/train/plugins.rb +40 -0
- data/lib/train/plugins/base_connection.rb +86 -0
- data/lib/train/plugins/transport.rb +49 -0
- data/lib/train/transports/docker.rb +102 -0
- data/lib/train/transports/local.rb +52 -0
- data/lib/train/transports/local_file.rb +77 -0
- data/lib/train/transports/local_os.rb +51 -0
- data/lib/train/transports/mock.rb +125 -0
- data/lib/train/transports/ssh.rb +163 -0
- data/lib/train/transports/ssh_connection.rb +216 -0
- data/lib/train/transports/winrm.rb +187 -0
- data/lib/train/transports/winrm_connection.rb +258 -0
- data/lib/train/version.rb +7 -0
- data/test/integration/.kitchen.yml +43 -0
- data/test/integration/Berksfile +3 -0
- data/test/integration/bootstrap.sh +17 -0
- data/test/integration/chefignore +1 -0
- data/test/integration/cookbooks/test/metadata.rb +1 -0
- data/test/integration/cookbooks/test/recipes/default.rb +101 -0
- data/test/integration/docker_run.rb +153 -0
- data/test/integration/docker_test.rb +24 -0
- data/test/integration/docker_test_container.rb +24 -0
- data/test/integration/helper.rb +58 -0
- data/test/integration/sudo/nopasswd.rb +16 -0
- data/test/integration/sudo/passwd.rb +21 -0
- data/test/integration/sudo/run_as.rb +12 -0
- data/test/integration/test-runner.yaml +24 -0
- data/test/integration/test_local.rb +19 -0
- data/test/integration/test_ssh.rb +24 -0
- data/test/integration/tests/path_block_device_test.rb +74 -0
- data/test/integration/tests/path_character_device_test.rb +74 -0
- data/test/integration/tests/path_file_test.rb +79 -0
- data/test/integration/tests/path_folder_test.rb +88 -0
- data/test/integration/tests/path_missing_test.rb +77 -0
- data/test/integration/tests/path_pipe_test.rb +78 -0
- data/test/integration/tests/path_symlink_test.rb +83 -0
- data/test/integration/tests/run_command_test.rb +28 -0
- data/test/unit/extras/command_wrapper_test.rb +41 -0
- data/test/unit/extras/file_common_test.rb +133 -0
- data/test/unit/extras/linux_file_test.rb +98 -0
- data/test/unit/extras/os_common_test.rb +258 -0
- data/test/unit/extras/stat_test.rb +105 -0
- data/test/unit/helper.rb +6 -0
- data/test/unit/plugins/connection_test.rb +44 -0
- data/test/unit/plugins/transport_test.rb +111 -0
- data/test/unit/plugins_test.rb +22 -0
- data/test/unit/train_test.rb +132 -0
- data/test/unit/transports/local_file_test.rb +112 -0
- data/test/unit/transports/local_test.rb +73 -0
- data/test/unit/transports/mock_test.rb +76 -0
- data/test/unit/transports/ssh_test.rb +95 -0
- data/test/unit/version_test.rb +8 -0
- data/train.gemspec +32 -0
- metadata +299 -0
@@ -0,0 +1,98 @@
|
|
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::LinuxFile }
|
8
|
+
let(:backend) {
|
9
|
+
backend = Train::Transports::Mock.new.connection
|
10
|
+
backend.mock_os({ family: 'linux' })
|
11
|
+
backend
|
12
|
+
}
|
13
|
+
|
14
|
+
def mock_stat(path, out, err = '', code = 0)
|
15
|
+
backend.mock_command(
|
16
|
+
"stat path 2>/dev/null --printf '%s\n%f\n%U\n%u\n%G\n%g\n%X\n%Y\n%C'",
|
17
|
+
out, err, code,
|
18
|
+
)
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'reads file contents' do
|
22
|
+
out = rand.to_s
|
23
|
+
backend.mock_command('cat path || echo -n', out)
|
24
|
+
cls.new(backend, 'path').content.must_equal out
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'reads file contents' do
|
28
|
+
backend.mock_command('cat path || echo -n', '')
|
29
|
+
mock_stat('path', '', 'some error...', 1)
|
30
|
+
cls.new(backend, 'path').content.must_equal nil
|
31
|
+
end
|
32
|
+
|
33
|
+
it 'checks for file existance' do
|
34
|
+
backend.mock_command('test -e path', true)
|
35
|
+
cls.new(backend, 'path').exist?.must_equal true
|
36
|
+
end
|
37
|
+
|
38
|
+
it 'checks for file existance' do
|
39
|
+
backend.mock_command('test -e path', nil, nil, 1)
|
40
|
+
cls.new(backend, 'path').exist?.must_equal false
|
41
|
+
end
|
42
|
+
|
43
|
+
it 'retrieves the link path' do
|
44
|
+
out = rand.to_s
|
45
|
+
mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\n?")
|
46
|
+
backend.mock_command('readlink path', out)
|
47
|
+
cls.new(backend, 'path').link_path.must_equal out
|
48
|
+
end
|
49
|
+
|
50
|
+
it 'retrieves the linked file' do
|
51
|
+
out = rand.to_s
|
52
|
+
mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\n?")
|
53
|
+
backend.mock_command('readlink path', out)
|
54
|
+
f = backend.file(out)
|
55
|
+
cls.new(backend, 'path').link_target.must_equal f
|
56
|
+
end
|
57
|
+
|
58
|
+
it 'checks a mounted path' do
|
59
|
+
backend.mock_command("mount | grep -- ' on path'", rand.to_s)
|
60
|
+
cls.new(backend, 'path').mounted?.must_equal true
|
61
|
+
end
|
62
|
+
|
63
|
+
it 'has nil product version' do
|
64
|
+
cls.new(backend, 'path').product_version.must_be_nil
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'has nil file version' do
|
68
|
+
cls.new(backend, 'path').file_version.must_be_nil
|
69
|
+
end
|
70
|
+
|
71
|
+
describe 'stat on a file' do
|
72
|
+
before { mock_stat('path', "13\na1ff\nz\n1001\nz\n1001\n1444573475\n1444573475\nlabels") }
|
73
|
+
|
74
|
+
it 'retrieves the file type' do
|
75
|
+
cls.new(backend, 'path').type.must_equal :symlink
|
76
|
+
end
|
77
|
+
|
78
|
+
it 'retrieves the file mode' do
|
79
|
+
cls.new(backend, 'path').mode.must_equal 00777
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'retrieves the file owner' do
|
83
|
+
cls.new(backend, 'path').owner.must_equal 'z'
|
84
|
+
end
|
85
|
+
|
86
|
+
it 'retrieves the file mtime' do
|
87
|
+
cls.new(backend, 'path').mtime.must_equal 1444573475
|
88
|
+
end
|
89
|
+
|
90
|
+
it 'retrieves the file size' do
|
91
|
+
cls.new(backend, 'path').size.must_equal 13
|
92
|
+
end
|
93
|
+
|
94
|
+
it 'retrieves the file selinux_label' do
|
95
|
+
cls.new(backend, 'path').selinux_label.must_equal 'labels'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,258 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
# author: Dominik Richter
|
3
|
+
# author: Christoph Hartmann
|
4
|
+
|
5
|
+
require 'helper'
|
6
|
+
require 'train/extras'
|
7
|
+
|
8
|
+
describe 'os common plugin' do
|
9
|
+
let(:cls) {
|
10
|
+
Class.new(Train::Extras::OSCommon) do
|
11
|
+
def detect_family; end
|
12
|
+
end
|
13
|
+
}
|
14
|
+
|
15
|
+
def mock_platform(x)
|
16
|
+
cls.new(nil, { family: x })
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'provides a method to access platform data' do
|
20
|
+
family = rand
|
21
|
+
os = mock_platform(family)
|
22
|
+
os[:family].must_equal family
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'provides an accessor for the full hash' do
|
26
|
+
x = rand.to_s
|
27
|
+
os = mock_platform(x)
|
28
|
+
os.to_hash.must_equal({ family: x })
|
29
|
+
end
|
30
|
+
|
31
|
+
describe 'with platform set to redhat' do
|
32
|
+
let(:os) { mock_platform('redhat') }
|
33
|
+
it { os.redhat?.must_equal(true) }
|
34
|
+
it { os.debian?.must_equal(false) }
|
35
|
+
it { os.suse?.must_equal(false) }
|
36
|
+
it { os.linux?.must_equal(true) }
|
37
|
+
it { os.unix?.must_equal(true) }
|
38
|
+
end
|
39
|
+
|
40
|
+
describe 'with platform set to oracle' do
|
41
|
+
let(:os) { mock_platform('oracle') }
|
42
|
+
it { os.redhat?.must_equal(true) }
|
43
|
+
it { os.debian?.must_equal(false) }
|
44
|
+
it { os.suse?.must_equal(false) }
|
45
|
+
it { os.linux?.must_equal(true) }
|
46
|
+
it { os.unix?.must_equal(true) }
|
47
|
+
end
|
48
|
+
|
49
|
+
describe 'with platform set to centos' do
|
50
|
+
let(:os) { mock_platform('centos') }
|
51
|
+
it { os.redhat?.must_equal(true) }
|
52
|
+
it { os.debian?.must_equal(false) }
|
53
|
+
it { os.suse?.must_equal(false) }
|
54
|
+
it { os.linux?.must_equal(true) }
|
55
|
+
it { os.unix?.must_equal(true) }
|
56
|
+
end
|
57
|
+
|
58
|
+
describe 'with platform set to fedora' do
|
59
|
+
let(:os) { mock_platform('fedora') }
|
60
|
+
it { os.redhat?.must_equal(true) }
|
61
|
+
it { os.debian?.must_equal(false) }
|
62
|
+
it { os.suse?.must_equal(false) }
|
63
|
+
it { os.linux?.must_equal(true) }
|
64
|
+
it { os.unix?.must_equal(true) }
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'with platform set to debian' do
|
68
|
+
let(:os) { mock_platform('debian') }
|
69
|
+
it { os.redhat?.must_equal(false) }
|
70
|
+
it { os.debian?.must_equal(true) }
|
71
|
+
it { os.suse?.must_equal(false) }
|
72
|
+
it { os.linux?.must_equal(true) }
|
73
|
+
it { os.unix?.must_equal(true) }
|
74
|
+
end
|
75
|
+
|
76
|
+
describe 'with platform set to ubuntu' do
|
77
|
+
let(:os) { mock_platform('ubuntu') }
|
78
|
+
it { os.redhat?.must_equal(false) }
|
79
|
+
it { os.debian?.must_equal(true) }
|
80
|
+
it { os.suse?.must_equal(false) }
|
81
|
+
it { os.linux?.must_equal(true) }
|
82
|
+
it { os.unix?.must_equal(true) }
|
83
|
+
end
|
84
|
+
|
85
|
+
describe 'with platform set to linuxmint' do
|
86
|
+
let(:os) { mock_platform('linuxmint') }
|
87
|
+
it { os.redhat?.must_equal(false) }
|
88
|
+
it { os.debian?.must_equal(true) }
|
89
|
+
it { os.suse?.must_equal(false) }
|
90
|
+
it { os.linux?.must_equal(true) }
|
91
|
+
it { os.unix?.must_equal(true) }
|
92
|
+
end
|
93
|
+
|
94
|
+
describe 'with platform set to raspbian' do
|
95
|
+
let(:os) { mock_platform('raspbian') }
|
96
|
+
it { os.redhat?.must_equal(false) }
|
97
|
+
it { os.debian?.must_equal(true) }
|
98
|
+
it { os.suse?.must_equal(false) }
|
99
|
+
it { os.linux?.must_equal(true) }
|
100
|
+
it { os.unix?.must_equal(true) }
|
101
|
+
end
|
102
|
+
|
103
|
+
describe 'with platform set to suse' do
|
104
|
+
let(:os) { mock_platform('suse') }
|
105
|
+
it { os.redhat?.must_equal(false) }
|
106
|
+
it { os.debian?.must_equal(false) }
|
107
|
+
it { os.suse?.must_equal(true) }
|
108
|
+
it { os.linux?.must_equal(true) }
|
109
|
+
it { os.unix?.must_equal(true) }
|
110
|
+
end
|
111
|
+
|
112
|
+
describe 'with platform set to opensuse' do
|
113
|
+
let(:os) { mock_platform('opensuse') }
|
114
|
+
it { os.redhat?.must_equal(false) }
|
115
|
+
it { os.debian?.must_equal(false) }
|
116
|
+
it { os.suse?.must_equal(true) }
|
117
|
+
it { os.linux?.must_equal(true) }
|
118
|
+
it { os.unix?.must_equal(true) }
|
119
|
+
end
|
120
|
+
|
121
|
+
describe 'with platform set to alpine' do
|
122
|
+
let(:os) { mock_platform('alpine') }
|
123
|
+
it { os.redhat?.must_equal(false) }
|
124
|
+
it { os.debian?.must_equal(false) }
|
125
|
+
it { os.suse?.must_equal(false) }
|
126
|
+
it { os.linux?.must_equal(true) }
|
127
|
+
it { os.unix?.must_equal(true) }
|
128
|
+
end
|
129
|
+
|
130
|
+
describe 'with platform set to arch' do
|
131
|
+
let(:os) { mock_platform('arch') }
|
132
|
+
it { os.redhat?.must_equal(false) }
|
133
|
+
it { os.debian?.must_equal(false) }
|
134
|
+
it { os.suse?.must_equal(false) }
|
135
|
+
it { os.linux?.must_equal(true) }
|
136
|
+
it { os.unix?.must_equal(true) }
|
137
|
+
end
|
138
|
+
|
139
|
+
describe 'with platform set to coreos' do
|
140
|
+
let(:os) { mock_platform('coreos') }
|
141
|
+
it { os.redhat?.must_equal(false) }
|
142
|
+
it { os.debian?.must_equal(false) }
|
143
|
+
it { os.suse?.must_equal(false) }
|
144
|
+
it { os.linux?.must_equal(true) }
|
145
|
+
it { os.unix?.must_equal(true) }
|
146
|
+
end
|
147
|
+
|
148
|
+
describe 'with platform set to exherbo' do
|
149
|
+
let(:os) { mock_platform('exherbo') }
|
150
|
+
it { os.redhat?.must_equal(false) }
|
151
|
+
it { os.debian?.must_equal(false) }
|
152
|
+
it { os.suse?.must_equal(false) }
|
153
|
+
it { os.linux?.must_equal(true) }
|
154
|
+
it { os.unix?.must_equal(true) }
|
155
|
+
end
|
156
|
+
|
157
|
+
describe 'with platform set to gentoo' do
|
158
|
+
let(:os) { mock_platform('gentoo') }
|
159
|
+
it { os.redhat?.must_equal(false) }
|
160
|
+
it { os.debian?.must_equal(false) }
|
161
|
+
it { os.suse?.must_equal(false) }
|
162
|
+
it { os.linux?.must_equal(true) }
|
163
|
+
it { os.unix?.must_equal(true) }
|
164
|
+
end
|
165
|
+
|
166
|
+
describe 'with platform set to slackware' do
|
167
|
+
let(:os) { mock_platform('slackware') }
|
168
|
+
it { os.redhat?.must_equal(false) }
|
169
|
+
it { os.debian?.must_equal(false) }
|
170
|
+
it { os.suse?.must_equal(false) }
|
171
|
+
it { os.linux?.must_equal(true) }
|
172
|
+
it { os.unix?.must_equal(true) }
|
173
|
+
end
|
174
|
+
|
175
|
+
describe 'with platform set to linux' do
|
176
|
+
let(:os) { mock_platform('linux') }
|
177
|
+
it { os.linux?.must_equal(true) }
|
178
|
+
it { os.unix?.must_equal(true) }
|
179
|
+
end
|
180
|
+
|
181
|
+
describe 'with platform set to freebsd' do
|
182
|
+
let(:os) { mock_platform('freebsd') }
|
183
|
+
it { os.bsd?.must_equal(true) }
|
184
|
+
it { os.linux?.must_equal(false) }
|
185
|
+
it { os.unix?.must_equal(true) }
|
186
|
+
end
|
187
|
+
|
188
|
+
describe 'with platform set to netbsd' do
|
189
|
+
let(:os) { mock_platform('netbsd') }
|
190
|
+
it { os.bsd?.must_equal(true) }
|
191
|
+
it { os.linux?.must_equal(false) }
|
192
|
+
it { os.unix?.must_equal(true) }
|
193
|
+
end
|
194
|
+
|
195
|
+
describe 'with platform set to openbsd' do
|
196
|
+
let(:os) { mock_platform('openbsd') }
|
197
|
+
it { os.bsd?.must_equal(true) }
|
198
|
+
it { os.linux?.must_equal(false) }
|
199
|
+
it { os.unix?.must_equal(true) }
|
200
|
+
end
|
201
|
+
|
202
|
+
describe 'with platform set to darwin' do
|
203
|
+
let(:os) { mock_platform('darwin') }
|
204
|
+
it { os.bsd?.must_equal(true) }
|
205
|
+
it { os.linux?.must_equal(false) }
|
206
|
+
it { os.unix?.must_equal(true) }
|
207
|
+
end
|
208
|
+
|
209
|
+
describe 'with platform set to solaris' do
|
210
|
+
let(:os) { mock_platform('solaris') }
|
211
|
+
it { os.solaris?.must_equal(true) }
|
212
|
+
it { os.linux?.must_equal(false) }
|
213
|
+
it { os.unix?.must_equal(true) }
|
214
|
+
end
|
215
|
+
|
216
|
+
describe 'with platform set to smartos' do
|
217
|
+
let(:os) { mock_platform('smartos') }
|
218
|
+
it { os.solaris?.must_equal(true) }
|
219
|
+
it { os.linux?.must_equal(false) }
|
220
|
+
it { os.unix?.must_equal(true) }
|
221
|
+
end
|
222
|
+
|
223
|
+
describe 'with platform set to openindiana' do
|
224
|
+
let(:os) { mock_platform('openindiana') }
|
225
|
+
it { os.solaris?.must_equal(true) }
|
226
|
+
it { os.linux?.must_equal(false) }
|
227
|
+
it { os.unix?.must_equal(true) }
|
228
|
+
end
|
229
|
+
|
230
|
+
describe 'with platform set to opensolaris' do
|
231
|
+
let(:os) { mock_platform('opensolaris') }
|
232
|
+
it { os.solaris?.must_equal(true) }
|
233
|
+
it { os.linux?.must_equal(false) }
|
234
|
+
it { os.unix?.must_equal(true) }
|
235
|
+
end
|
236
|
+
|
237
|
+
describe 'with platform set to solaris2' do
|
238
|
+
let(:os) { mock_platform('solaris2') }
|
239
|
+
it { os.solaris?.must_equal(true) }
|
240
|
+
it { os.linux?.must_equal(false) }
|
241
|
+
it { os.unix?.must_equal(true) }
|
242
|
+
end
|
243
|
+
|
244
|
+
describe 'with platform set to nexentacore' do
|
245
|
+
let(:os) { mock_platform('nexentacore') }
|
246
|
+
it { os.solaris?.must_equal(true) }
|
247
|
+
it { os.linux?.must_equal(false) }
|
248
|
+
it { os.unix?.must_equal(true) }
|
249
|
+
end
|
250
|
+
|
251
|
+
describe 'with platform set to windows' do
|
252
|
+
let(:os) { mock_platform('windows') }
|
253
|
+
it { os.solaris?.must_equal(false) }
|
254
|
+
it { os.bsd?.must_equal(false) }
|
255
|
+
it { os.linux?.must_equal(false) }
|
256
|
+
it { os.unix?.must_equal(false) }
|
257
|
+
end
|
258
|
+
end
|
@@ -0,0 +1,105 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
require 'helper'
|
3
|
+
require 'train/extras'
|
4
|
+
|
5
|
+
describe 'stat' do
|
6
|
+
let(:cls) { Train::Extras::Stat }
|
7
|
+
|
8
|
+
describe 'find_type' do
|
9
|
+
let (:random_mode) { (rand * 1000).to_i }
|
10
|
+
|
11
|
+
it 'detects :unknown types' do
|
12
|
+
cls.find_type(random_mode).must_equal :unknown
|
13
|
+
end
|
14
|
+
|
15
|
+
it 'detects sockets' do
|
16
|
+
cls.find_type(00140755).must_equal :socket
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'detects sockets' do
|
20
|
+
cls.find_type(00120755).must_equal :symlink
|
21
|
+
end
|
22
|
+
|
23
|
+
it 'detects sockets' do
|
24
|
+
cls.find_type(00100755).must_equal :file
|
25
|
+
end
|
26
|
+
|
27
|
+
it 'detects sockets' do
|
28
|
+
cls.find_type(00060755).must_equal :block_device
|
29
|
+
end
|
30
|
+
|
31
|
+
it 'detects sockets' do
|
32
|
+
cls.find_type(00040755).must_equal :directory
|
33
|
+
end
|
34
|
+
|
35
|
+
it 'detects sockets' do
|
36
|
+
cls.find_type(00020755).must_equal :character_device
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'detects sockets' do
|
40
|
+
cls.find_type(00010755).must_equal :pipe
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'linux stat' do
|
45
|
+
let(:backend) { Minitest::Mock.new }
|
46
|
+
|
47
|
+
it 'ignores wrong stat results' do
|
48
|
+
res = Minitest::Mock.new
|
49
|
+
res.expect :stdout, ''
|
50
|
+
backend.expect :run_command, res, [String]
|
51
|
+
cls.linux_stat('/path', backend).must_equal({})
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'reads correct stat results' do
|
55
|
+
res = Minitest::Mock.new
|
56
|
+
res.expect :stdout, "360\n43ff\nroot\n0\nroot\n0\n1444520846\n1444522445\n?"
|
57
|
+
backend.expect :run_command, res, [String]
|
58
|
+
cls.linux_stat('/path', backend).must_equal({
|
59
|
+
type: :directory,
|
60
|
+
mode: 00777,
|
61
|
+
owner: 'root',
|
62
|
+
group: 'root',
|
63
|
+
mtime: 1444522445,
|
64
|
+
size: 360,
|
65
|
+
selinux_label: nil,
|
66
|
+
})
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe 'bsd stat' do
|
71
|
+
let(:backend) { Minitest::Mock.new }
|
72
|
+
|
73
|
+
it 'ignores failed stat results' do
|
74
|
+
res = Minitest::Mock.new
|
75
|
+
res.expect :stdout, '.....'
|
76
|
+
res.expect :exit_status, 1
|
77
|
+
backend.expect :run_command, res, [String]
|
78
|
+
cls.bsd_stat('/path', backend).must_equal({})
|
79
|
+
end
|
80
|
+
|
81
|
+
it 'ignores wrong stat results' do
|
82
|
+
res = Minitest::Mock.new
|
83
|
+
res.expect :stdout, ''
|
84
|
+
res.expect :exit_status, 0
|
85
|
+
backend.expect :run_command, res, [String]
|
86
|
+
cls.bsd_stat('/path', backend).must_equal({})
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'reads correct stat results' do
|
90
|
+
res = Minitest::Mock.new
|
91
|
+
res.expect :stdout, "360\n41777\nroot\n0\nroot\n0\n1444520846\n1444522445"
|
92
|
+
res.expect :exit_status, 0
|
93
|
+
backend.expect :run_command, res, [String]
|
94
|
+
cls.bsd_stat('/path', backend).must_equal({
|
95
|
+
type: :directory,
|
96
|
+
mode: 00777,
|
97
|
+
owner: 'root',
|
98
|
+
group: 'root',
|
99
|
+
mtime: 1444522445,
|
100
|
+
size: 360,
|
101
|
+
selinux_label: nil,
|
102
|
+
})
|
103
|
+
end
|
104
|
+
end
|
105
|
+
end
|