Sha256: dd251d72c6548a012fa71a289690da7f0f9288bc8b65286d1054e468891c9c13

Contents?: true

Size: 1.59 KB

Versions: 12

Compression:

Stored size: 1.59 KB

Contents

require 'rubygems'
require 'net/ssh'
require 'net/sftp'
require 'log4r'
require 'tmpdir'
require 'fileutils'
require_relative '../lib/depengine/helper/validations'
require_relative '../lib/depengine/publisher/ssh'
require_relative '../lib/depengine/log/log'

$log            = Log::DeploymentLogger.new
$log.writer.level = Log4r::INFO
$exec_file_path = __FILE__

describe "the ssh publisher" do
  it "should execute a command on a remote host" do
    worker = Publisher::Ssh.new
    worker.remote_host  = 'localhost'
    worker.remote_user  = ENV['USER']
    worker.ssh_key_file = ENV['HOME']+"/.ssh/id_rsa"

    result = ''
    result = worker.remote_execute('ls -l /')
    result.should include("drwx")
  end

  it "removes old releases" do
    tmp_dir = Dir.mktmpdir
    begin
      elements = 10
      elements.times do |i|
        random_time_in_the_past_days = (Time.now-25*60*60*i-((rand*10000).to_i))
        FileUtils.mkdir_p(File.join(tmp_dir,random_time_in_the_past_days.strftime("%Y-%m-%d_%s")))
      end
      Dir.glob(tmp_dir+"/*").size.should be elements

      worker = Publisher::Ssh.new
      worker.remote_host  = 'localhost'
      worker.remote_user  = ENV['USER']
      worker.ssh_key_file = ENV['HOME']+"/.ssh/id_rsa"

      newest_release = Time.now.strftime("%Y-%m-%d_%s")
      FileUtils.mkdir_p(File.join(tmp_dir, newest_release))

      worker.remove_old_releases(tmp_dir, 1, /[0-9]{4}\-[0-9]{2}\-[0-9]{2}_[0-9]+.*/)
      Dir.glob(tmp_dir+"/*").size.should be 1
      Dir.glob(tmp_dir+"/*").first.should include(newest_release)

    ensure
      FileUtils.remove_entry tmp_dir
    end
  end

end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
depengine-3.0.11 spec/ssh_spec.rb
depengine-3.0.10 spec/ssh_spec.rb
depengine-3.0.9 spec/ssh_spec.rb
depengine-3.0.8 spec/ssh_spec.rb
depengine-3.0.7 spec/ssh_spec.rb
depengine-3.0.6 spec/ssh_spec.rb
depengine-3.0.5 spec/ssh_spec.rb
depengine-3.0.4 spec/ssh_spec.rb
depengine-3.0.3 spec/ssh_spec.rb
depengine-3.0.2 spec/ssh_spec.rb
depengine-3.0.1 spec/ssh_spec.rb
depengine-3.0.0 spec/ssh_spec.rb