Created
August 22, 2018 10:42
-
-
Save marzdgzmn/518836865851d148abbdfc00e136bf01 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'marz/rsync/logs' | |
require 'marz/rsync/result' | |
module Marz | |
module Rsync | |
#The rsync command to be run | |
class Command | |
# Runs an rsync job, returns the exit code, and does logging | |
# | |
# @param opts {Array} | |
# @return {ExitCode} | |
def self.run(*opts) | |
cmd = ['rsync', '--itemize-changes', 'stats -h', opts].flatten.shelljoin | |
output = `#{cmd} 2>&1` | |
Result.new(output, $?.exitstatus) | |
end | |
def self.command | |
@command ||= "rsync" | |
end | |
def self.command=(cmd) | |
@command = cmd | |
end | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require 'marz/rsync/version' | |
require 'marz/rsync/configure' | |
require 'marz/rsync/command' | |
module Marz | |
# Main interface to rsyunc | |
module Rsync | |
extend Configure | |
# Runs an rsync {Command} and return the {Result} | |
# @param source {String} | |
# @param destination {String} | |
# @param opts {Array} | |
# @return {Result} | |
# @yield {Result} | |
def self.run(source, destination, opts = [], &block) | |
destination = "#{self.host}:#{destination}" if self.host | |
result = Command.run(source, destination, opts) | |
yield(result) if block_given? | |
result | |
end | |
end | |
end |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "test_helper" | |
class Marz::RsyncTest < Minitest::Test | |
def test_that_it_has_a_version_number | |
refute_nil ::Marz::Rsync::VERSION | |
end | |
def configure_rsync_host | |
Marz::Rsync.configure do |config| | |
config.host = 'root@127.0.0.1' | |
end | |
end | |
#def test_it_does_something_useful | |
# assert false | |
#end | |
def test_rsync_run_should_prepend_host_to_destination | |
mock = MiniTest::Mock.new | |
mocked_result = Minitest::Mock.new | |
mock.expect(Marz::Rsync::Command::run, mocked_result, ['/foo1', 'root@127.0.0.1:/foo2', ['-a']]) | |
Marz::Rsync::Command.stub :run, mocked_result do | |
Marz::Rsync.run('/foo1', '/foo2', ['-a']) | |
end | |
mock.verify | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment