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

move train/plugins/common to train/extras #2

Merged
merged 6 commits into from
Oct 13, 2015
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
2 changes: 1 addition & 1 deletion .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,4 @@ Style/AndOr:
Style/TrailingComma:
EnforcedStyleForMultiline: comma
Style/SpaceAroundOperators:
MultiSpaceAllowedForOperators: ["=", "=>", "||="]
MultiSpaceAllowedForOperators: [ "=", "=>", "||=" ]
4 changes: 0 additions & 4 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
---
sudo: required
language: ruby
cache: bundler

Expand All @@ -11,6 +10,3 @@ matrix:
gemfile: Gemfile
- rvm: 2.2
gemfile: Gemfile
script: bundle exec rake lint test
before_script:
- source <(curl -sL https://raw.githubusercontent.com/zuazo/kitchen-in-travis/0.3.0/scripts/start_docker.sh)
3 changes: 2 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ desc 'Run robocop linter'
task lint: [:rubocop]

# run tests
task default: :test
task default: [:test, :lint]

Rake::TestTask.new do |t|
t.libs << 'test/unit'
t.pattern = 'test/unit/**/*_test.rb'
Expand Down
13 changes: 13 additions & 0 deletions lib/train/extras.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# encoding: utf-8
#
# Author:: Dominik Richter (<[email protected]>)

module Train::Extras
autoload :FileCommon, 'train/extras/file_common'
autoload :LinuxFile, 'train/extras/linux_file'
autoload :OSCommon, 'train/extras/os_common'
autoload :Stat, 'train/extras/stat'

CommandResult = Struct.new(:stdout, :stderr, :exit_status)
LoginCommand = Struct.new(:command, :arguments)
end
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@
require 'digest/sha2'
require 'digest/md5'

module Train::Plugins::Common
module Train::Extras
class FileCommon
autoload :Stat, 'train/plugins/stat'

# interface methods: these fields should be implemented by every
# backend File
%w{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@
# author: Christoph Hartmann

require 'shellwords'
require 'train/extras/stat'

module Train::Plugins::Common
module Train::Extras
class LinuxFile < FileCommon
attr_reader :path
def initialize(backend, path)
Expand Down Expand Up @@ -67,7 +68,7 @@ def file_version

def stat
return @stat if defined?(@stat)
@stat = Stat.stat(@spath, @backend)
@stat = Train::Extras::Stat.stat(@spath, @backend)
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# by Adam Jacob, Chef Software Inc
#

module Train::Plugins::Common
module Train::Extras
module LinuxLSB
def lsb_config(content)
{
Expand Down
18 changes: 9 additions & 9 deletions lib/train/plugins/os_common.rb → lib/train/extras/os_common.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,17 @@
# by Adam Jacob, Chef Software Inc
#

require 'train/plugins/os_detect_darwin'
require 'train/plugins/os_detect_linux'
require 'train/plugins/os_detect_unix'
require 'train/plugins/os_detect_windows'
require 'train/extras/os_detect_darwin'
require 'train/extras/os_detect_linux'
require 'train/extras/os_detect_unix'
require 'train/extras/os_detect_windows'

module Train::Plugins::Common
module Train::Extras
class OSCommon
include DetectDarwin
include DetectLinux
include DetectUnix
include DetectWindows
include Train::Extras::DetectDarwin
include Train::Extras::DetectLinux
include Train::Extras::DetectUnix
include Train::Extras::DetectWindows

def initialize(backend, platform = nil)
@backend = backend
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# by Adam Jacob, Chef Software Inc
#

module Train::Plugins::Common
module Train::Extras
module DetectDarwin
def detect_darwin
cmd = @backend.run_command('/usr/bin/sw_vers')
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
# by Adam Jacob, Chef Software Inc
#

require 'train/plugins/linux_lsb'
require 'train/extras/linux_lsb'

module Train::Plugins::Common
module Train::Extras
module DetectLinux
include LinuxLSB
include Train::Extras::LinuxLSB

def detect_linux_via_config # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/PerceivedComplexity
if !(raw = get_config('oracle-release')).nil?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
# by Adam Jacob, Chef Software Inc
#

module Train::Plugins::Common
module Train::Extras
module DetectUnix
def detect_via_uname # rubocop:disable Metrics/AbcSize, Metrics/CyclomaticComplexity, Metrics/MethodLength
case uname_s.downcase
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

require 'json'

module Train::Plugins::Common
module Train::Extras
module DetectWindows
# See: https://msdn.microsoft.com/en-us/library/windows/desktop/ms724832%28v=vs.85%29.aspx
# Product Type:
Expand Down
2 changes: 1 addition & 1 deletion lib/train/plugins/stat.rb → lib/train/extras/stat.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
# author: Dominik Richter
# author: Christoph Hartmann

class Train::Plugins::Common::FileCommon
module Train::Extras
class Stat
TYPES = {
socket: 00140000,
Expand Down
4 changes: 2 additions & 2 deletions lib/train/plugins/base_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Author:: Dominik Richter (<[email protected]>)

require 'train/errors'
require 'train/plugins/common'
require 'train/extras'
require 'logger'

class Train::Plugins::Transport
Expand All @@ -16,7 +16,7 @@ class Train::Plugins::Transport
#
# @author Fletcher Nichol <[email protected]>
class BaseConnection
include Train::Plugins::Common
include Train::Extras

# Create a new Connection instance.
#
Expand Down
13 changes: 0 additions & 13 deletions lib/train/plugins/common.rb

This file was deleted.

4 changes: 2 additions & 2 deletions lib/train/plugins/transport.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@

require 'logger'
require 'train/errors'
require 'train/plugins/common'
require 'train/extras'

class Train::Plugins
class Transport
include Train::Plugins::Common
include Train::Extras

autoload :BaseConnection, 'train/plugins/base_connection'

Expand Down
4 changes: 3 additions & 1 deletion lib/train/transports/local_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
# author: Dominik Richter
# author: Christoph Hartmann

require 'train/extras'

class Train::Transports::Local::Connection
class File < LinuxFile
def content
Expand Down Expand Up @@ -56,7 +58,7 @@ def stat
end

@stat = {
type: Stat.find_type(file_stat.mode),
type: Train::Extras::Stat.find_type(file_stat.mode),
mode: file_stat.mode & 00777,
mtime: file_stat.mtime.to_i,
size: file_stat.size,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
# encoding: utf-8
require 'helper'
require 'securerandom'
require 'train/plugins/file_common'
require 'train/extras/file_common'

describe 'file common' do
let(:cls) { Train::Plugins::Common::FileCommon }
let(:cls) { Train::Extras::FileCommon }

def mockup(stubs)
Class.new(cls) do
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
# encoding: utf-8
require 'helper'
require 'train/transports/mock'
require 'train/plugins/common'
require 'train/plugins/linux_file'
require 'train/extras'

describe 'file common' do
let(:cls) { Train::Plugins::Common::LinuxFile }
let(:cls) { Train::Extras::LinuxFile }
let(:backend) {
backend = Train::Transports::Mock.new
backend.mock_os({ family: 'linux' })
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
# author: Christoph Hartmann

require 'helper'
require 'train/plugins/os_common'
require 'train/extras'

describe 'os common plugin' do
let(:cls) {
Class.new(Train::Plugins::Common::OSCommon) do
Class.new(Train::Extras::OSCommon) do
def detect_family; end
end
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
# encoding: utf-8
require 'helper'
require 'train/plugins/common'
require 'train/plugins/stat'
require 'train/extras'

describe 'stat' do
let(:cls) { Train::Plugins::Common::FileCommon::Stat }
let(:cls) { Train::Extras::Stat }

describe 'find_type' do
let (:random_mode) { (rand * 1000).to_i }
Expand Down
26 changes: 13 additions & 13 deletions test/unit/transports/local_file_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,15 @@
let(:connection) { transport.connection }

it 'gets file contents' do
res = rand
res = rand.to_s
File.stub :read, res do
connection.file(rand).content.must_equal(res)
connection.file(rand.to_s).content.must_equal(res)
end
end

it 'checks for file existance' do
File.stub :exist?, true do
connection.file(rand).exist?.must_equal(true)
connection.file(rand.to_s).exist?.must_equal(true)
end
end

Expand All @@ -35,7 +35,7 @@
}.each do |method, file_method|
it "checks if file is a #{method}" do
File.stub file_method.to_sym, true do
connection.file(rand).method(method.to_sym).call.must_equal(true)
connection.file(rand.to_s).method(method.to_sym).call.must_equal(true)
end
end
end
Expand All @@ -44,7 +44,7 @@
out = rand.to_s
File.stub :readlink, out do
File.stub :symlink?, true do
connection.file(rand).link_path.must_equal out
connection.file(rand.to_s).link_path.must_equal out
end
end
end
Expand All @@ -64,46 +64,46 @@ def meta_stub(method, param, &block)

it 'recognizes type' do
meta_stub :lstat, statres do
connection.file(rand).type.must_equal :socket
connection.file(rand.to_s).type.must_equal :socket
end
end

it 'recognizes mode' do
meta_stub :lstat, statres do
connection.file(rand).mode.must_equal 00755
connection.file(rand.to_s).mode.must_equal 00755
end
end

it 'recognizes mtime' do
meta_stub :lstat, statres do
connection.file(rand).mtime.must_equal statres.mtime
connection.file(rand.to_s).mtime.must_equal statres.mtime
end
end

it 'recognizes size' do
meta_stub :lstat, statres do
connection.file(rand).size.must_equal statres.size
connection.file(rand.to_s).size.must_equal statres.size
end
end

it 'recognizes owner' do
meta_stub :lstat, statres do
connection.file(rand).owner.must_equal 'owner'
connection.file(rand.to_s).owner.must_equal 'owner'
end
end

it 'recognizes group' do
meta_stub :lstat, statres do
connection.file(rand).group.must_equal 'group'
connection.file(rand.to_s).group.must_equal 'group'
end
end

it 'recognizes selinux label' do
meta_stub :lstat, statres do
label = rand.to_s
res = Train::Plugins::Common::CommandResult.new(label, nil, 0)
res = Train::Extras::CommandResult.new(label, nil, 0)
connection.stub :run_command, res do
connection.file(rand).selinux_label.must_equal label
connection.file(rand.to_s).selinux_label.must_equal label
end
end
end
Expand Down
1 change: 1 addition & 0 deletions train.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Gem::Specification.new do |spec|
spec.add_dependency 'winrm', '~> 1.3'
spec.add_dependency 'winrm-transport', '~> 1.0'

spec.add_development_dependency 'rake', '~> 10.4'
spec.add_development_dependency 'minitest', '~> 5.8'
spec.add_development_dependency 'rubocop', '~> 0.34'
end