Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix AIX and QNX file support #249

Merged
merged 1 commit into from
Feb 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions lib/train/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,7 @@
# author: Dominik Richter

require 'train/file/local'
require 'train/file/local/unix'
require 'train/file/local/windows'
require 'train/file/remote'
require 'train/file/remote/unix'
require 'train/file/remote/linux'
require 'train/file/remote/windows'
require 'train/file/remote/qnx'
require 'digest/sha2'
require 'digest/md5'
require 'train/extras/stat'
Expand Down
5 changes: 5 additions & 0 deletions lib/train/file/local.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,3 +68,8 @@ def linked_to?(dst)
end
end
end

# subclass requires are loaded after Train::File::Local is defined
# to avoid superclass mismatch errors
require 'train/file/local/unix'
require 'train/file/local/windows'
8 changes: 8 additions & 0 deletions lib/train/file/remote.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ def detect_filename(path, sep)
end
end
end

# subclass requires are loaded after Train::File::Remote is defined
# to avoid superclass mismatch errors
require 'train/file/remote/aix'
require 'train/file/remote/linux'
require 'train/file/remote/qnx'
require 'train/file/remote/unix'
require 'train/file/remote/windows'
4 changes: 2 additions & 2 deletions lib/train/file/remote/qnx.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
module Train
class File
class Remote
class Aix < Train::File::Remote::Unix
class Qnx < Train::File::Remote::Unix
def content
cat = 'cat'
cat = '/proc/boot/cat' if @backend.os[:release].to_i >= 7
Expand All @@ -32,7 +32,7 @@ def type
mode owner group uid gid mtime size selinux_label link_path mounted stat
}.each do |field|
define_method field.to_sym do
fail NotImplementedError, "QNX does not implement the #{m}() method yet."
fail NotImplementedError, "QNX does not implement the #{field}() method yet."
end
end
end
Expand Down
26 changes: 26 additions & 0 deletions test/unit/file/remote/aix_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
require 'helper'
require 'train/transports/local'
require 'train/file/remote/aix'
require 'train/transports/mock'

describe Train::File::Remote::Aix do
let(:cls) { Train::File::Remote::Aix }
let(:backend) {
backend = Train::Transports::Mock.new.connection
backend.mock_os({ name: 'aix', family: 'unix' })
backend
}

it 'returns a nil link_path if the object is not a symlink' do
file = cls.new(backend, 'path')
file.stubs(:symlink?).returns(false)
file.link_path.must_be_nil
end

it 'returns a correct link_path' do
file = cls.new(backend, 'path')
file.stubs(:symlink?).returns(true)
backend.mock_command("perl -e 'print readlink shift' path", 'our_link_path')
file.link_path.must_equal 'our_link_path'
end
end
44 changes: 44 additions & 0 deletions test/unit/file/remote/qnx_test.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
require 'helper'
require 'train/transports/local'
require 'train/file/remote/qnx'
require 'train/transports/mock'

describe Train::File::Remote::Qnx do
let(:cls) { Train::File::Remote::Qnx }
let(:backend) {
backend = Train::Transports::Mock.new.connection
backend.mock_os({ name: 'qnx', family: 'unix' })
backend
}

it 'returns file contents when the file exists' do
out = rand.to_s
backend.mock_command('cat path', out)
file = cls.new(backend, 'path')
file.stubs(:exist?).returns(true)
file.content.must_equal out
end

it 'returns nil contents when the file does not exist' do
file = cls.new(backend, 'path')
file.stubs(:exist?).returns(false)
file.content.must_be_nil
end

it 'returns a file type' do
backend.mock_command('file path', 'blah directory blah')
cls.new(backend, 'path').type.must_equal :directory
end

it 'returns a directory type' do
backend.mock_command('file path', 'blah regular file blah')
cls.new(backend, 'path').type.must_equal :file
end

it 'raises exception for unimplemented methods' do
file = cls.new(backend, 'path')
%w{mode owner group uid gid mtime size selinux_label link_path mounted stat}.each do |m|
proc { file.send(m) }.must_raise NotImplementedError
end
end
end