Skip to content
This repository has been archived by the owner on Nov 11, 2020. It is now read-only.

Commit

Permalink
create the intermediate dir
Browse files Browse the repository at this point in the history
  • Loading branch information
simpsonjulian committed Dec 6, 2011
1 parent 8495499 commit 58f8ff9
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 2 deletions.
11 changes: 10 additions & 1 deletion lib/source.rb
Expand Up @@ -8,13 +8,22 @@ def excludes
'--exclude ' + ['.git'].join(' ')
end

def create_destination(node)
begin
node.ssh('mkdir -p infrastructure')
rescue
raise "Couldn't SSH to #{node.dns_name} with #{node.username}"
end
end

def rsync_command(node)
"rsync #{self.excludes} --delete -apze ssh #{@path}/. #{node.username}@#{node.dns_name}:infrastructure/."
"rsync #{self.excludes} --delete -arpze ssh #{@path}/. #{node.username}@#{node.dns_name}:infrastructure/."
end

def rsync(node)
puts rsync_command(node)
print "Copying code to #{node.dns_name} ..."
create_destination(node)

raise "Failed to rsync to #{node.dns_name} with #{node.username}" unless system self.rsync_command(node)
puts " Done."
Expand Down
13 changes: 12 additions & 1 deletion spec/source_spec.rb
Expand Up @@ -10,18 +10,29 @@
Source.new('/tmp').excludes.should include '.git'
end

it "should make a parent directory to shut rsync up" do
node = mock('node')
node.should_receive(:dns_name).at_least(3).times.and_return('this.should.not.resolve')
node.should_receive(:username).at_least(3).times.and_return('jimmy')
node.should_receive(:ssh)
source = Source.new('/tmp/')
lambda { source.rsync(node) }.should raise_exception RuntimeError
end

it "should rsync the source tree to the remote node" do
node = mock('node')
node.should_receive(:dns_name).and_return('foo.foo.com')
node.should_receive(:username).and_return('jimmy')
source = Source.new('/tmp/')
source.rsync_command(node).should == 'rsync --exclude .git --delete -apze ssh /tmp/. jimmy@foo.foo.com:infrastructure/.'
source.rsync_command(node).should == 'rsync --exclude .git --delete -arpze ssh /tmp/. jimmy@foo.foo.com:infrastructure/.'
end


it "should blow up if it can't connect to the remote node" do
node = stub('node')
node.stub!(:dns_name).and_return('com.foo.foo')
node.stub!(:username).and_return('jimmy')
node.should_receive(:ssh)

lambda { Source.new('/tmp').rsync(node) }.should raise_exception RuntimeError
end
Expand Down

0 comments on commit 58f8ff9

Please sign in to comment.