Skip to content

Commit

Permalink
Add a Rakefile and fix the unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
surybala committed Jul 21, 2015
1 parent 748de99 commit 1e10c2d
Show file tree
Hide file tree
Showing 684 changed files with 70,633 additions and 69,289 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Gemfile.lock
deployment/
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ gem 'rubyzip'
gem 'rake'
gem 'archive-tar-minitar'
gem 'logging'
gem 'process_manager'

group :development do
# this doesn't need to be a global or even a standard dependency
Expand Down
29 changes: 29 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rake'
require 'rake/testtask'
require 'rspec/core/rake_task'
require 'rubygems'

# Check Ruby syntax in bin/ and lib/

# Run all units tests in test/
desc "Run unit tests in test/"
Rake::TestTask.new(:test) do |t|
t.libs << ['test', 'lib', 'test/helpers']

test_files = FileList.new("test/**/*_test.rb")
t.test_files = test_files
t.verbose = true
end
task :default => :test

# Run units tests in test/instance_agent/
Rake::TestTask.new(:test_instance_agent) do |t|
t.libs << ['test', 'lib', 'test/helpers']
t.pattern = "test/instance_agent/**/*_test.rb"
t.verbose = true
end

# Clean up
task :clean do
rm_rf 'deployment'
end
2 changes: 1 addition & 1 deletion codedeploy_agent-1.1.0.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,4 @@ Gem::Specification.new do |spec|
spec.add_dependency('rake', '~> 0.9')
spec.add_dependency('logging', '~>1.8')
spec.add_dependency('aws-sdk-core', '~>2.0')
end
end
1 change: 0 additions & 1 deletion lib/instance_agent.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
# encoding: UTF-8

Gem.use_paths(nil, Gem.path << "/opt/codedeploy-agent/vendor")

require 'core_ext'

require 'rubygems'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,19 @@ module InstanceAgent
module Plugins
module CodeDeployPlugin
module ApplicationSpecification

class ApplicationSpecificationTest < InstanceAgentTestCase
def make_app_spec
ApplicationSpecification.new(YAML.load(@app_spec_string), {:revision_id => @test_revision_id})
end

context 'The Application Specification' do
setup do
@test_revision_id = 'bar'
end

private

def make_app_spec
ApplicationSpecification.new(YAML.load(@app_spec_string), {:revision_id => @test_revision_id})
end

context "With missing version" do
setup do
@app_spec_string = <<-END
Expand Down Expand Up @@ -1710,4 +1711,4 @@ def make_app_spec
end
end
end
end
end
18 changes: 9 additions & 9 deletions test/instance_agent/plugins/codedeploy/command_executor_test.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
require 'test_helper'
require 'certificate_helper'
require 'stringio'
require 'com/amazon/codedeploy/command/v20141006/host_command_instance'
require 'aws-sdk-core/s3'

class CodeDeployPluginCommandExecutorTest < InstanceAgentTestCase

include InstanceAgent::Plugins::CodeDeployPlugin
def generate_signed_message_for(map)
message = @cert_helper.sign_message(map.to_json)
spec = OpenStruct.new({ :payload => message })
spec.format = "PKCS7/JSON"

return spec
end

context 'The CodeDeploy Plugin Command Executor' do
setup do
Expand Down Expand Up @@ -33,13 +40,6 @@ class CodeDeployPluginCommandExecutorTest < InstanceAgentTestCase
end

context "when executing a command" do
def generate_signed_message_for(map)
message = @cert_helper.sign_message(map.to_json)
spec = OpenStruct.new({ :payload => message })
spec.format = "PKCS7/JSON"

return spec
end

setup do
@cert_helper = CertificateHelper.new
Expand All @@ -62,7 +62,7 @@ def generate_signed_message_for(map)
"S3Revision" => @s3Revision
}
})
@command = Com::Amazon::Codedeploy::Command::V20141006::HostCommandInstance.new(
@command = Aws::CodeDeployCommand::Types::HostCommandInstance.new(
:host_command_identifier => "command-1",
:deployment_execution_id => "test-execution")
@root_dir = '/tmp/codedeploy/'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
require 'certificate_helper'

class DeploymentSpecificationTest < InstanceAgentTestCase
context 'The Deployment Specification' do
def generate_signed_message_for(map)
message = @cert_helper.sign_message(map.to_json)
spec = OpenStruct.new({ :payload => message })
spec.format = "PKCS7/JSON"

return spec
end
def generate_signed_message_for(map)
message = @cert_helper.sign_message(map.to_json)
spec = OpenStruct.new({ :payload => message })
spec.format = "PKCS7/JSON"
return spec
end

context 'The Deployment Specification' do
setup do
@cert_helper = CertificateHelper.new
@deployment_id = SecureRandom.uuid.to_s
Expand All @@ -37,8 +37,8 @@ def generate_signed_message_for(map)

@packed_message = generate_signed_message_for(@deployment_spec)
InstanceAgent::Config.init
end

end
context "with JSON format" do
should "populate the deployment id" do
parsed_deployment_spec = InstanceAgent::Plugins::CodeDeployPlugin::DeploymentSpecification.parse(@packed_message)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
require 'test_helper'
require 'stringio'
require 'fileutils'
require 'com/amazon/codedeploy/command/v20141006/host_command_instance'

class HookExecutorTest < InstanceAgentTestCase

Expand Down
4 changes: 4 additions & 0 deletions test/test_helper.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
# encoding: UTF-8
$:.unshift "lib"
Gem.use_paths(nil, Gem.path << "vendor")

require 'thread'
require 'rubygems'
require "bundler"
Expand All @@ -14,3 +17,4 @@
# require local test helpers. If you need a helper write,
# keep this pattern or you'll be punished hard
require 'instance_agent_helper'

14 changes: 14 additions & 0 deletions vendor/gems/archive-tar-minitar-0.5.2/ChangeLog
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
Revision history for Ruby library Archive::Tar::Minitar. Unless explicitly
noted otherwise, all changes are produced by Austin Ziegler
<[email protected]>.

== 0.5.2
* Fixed a Ruby 1.9 compatibility error.

== 0.5.1
* Fixed a variable name error.

== Archive::Tar::Minitar 0.5.0
* Initial release. Does files and directories. Command does create, extract,
* and list.

6 changes: 6 additions & 0 deletions vendor/gems/archive-tar-minitar-0.5.2/Install
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
Installing this package is as simple as:

% ruby install.rb

Alternatively, you can use the RubyGem version of Archive::Tar::Minitar
available as archive-tar-minitar-0.5.2.gem from the usual sources.
66 changes: 66 additions & 0 deletions vendor/gems/archive-tar-minitar-0.5.2/README
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
Archive::Tar::Minitar README
============================
Archive::Tar::Minitar is a pure-Ruby library and command-line utility that
provides the ability to deal with POSIX tar(1) archive files. The
implementation is based heavily on Mauricio Ferna'ndez's implementation in
rpa-base, but has been reorganised to promote reuse in other projects.

This release is version 0.5.2, offering a Ruby 1.9 compatibility bugfix over
version 0.5.1. The library can only handle files and directories at this
point. A future version will be expanded to handle symbolic links and hard
links in a portable manner. The command line utility, minitar, can only create
archives, extract from archives, and list archive contents.

Using this library is easy. The simplest case is:

require 'zlib'
require 'archive/tar/minitar'
include Archive::Tar

# Packs everything that matches Find.find('tests')
File.open('test.tar', 'wb') { |tar| Minitar.pack('tests', tar) }
# Unpacks 'test.tar' to 'x', creating 'x' if necessary.
Minitar.unpack('test.tar', 'x')

A gzipped tar can be written with:

tgz = Zlib::GzipWriter.new(File.open('test.tgz', 'wb'))
# Warning: tgz will be closed!
Minitar.pack('tests', tgz)

tgz = Zlib::GzipReader.new(File.open('test.tgz', 'rb'))
# Warning: tgz will be closed!
Minitar.unpack(tgz, 'x')

As the case above shows, one need not write to a file. However, it will
sometimes require that one dive a little deeper into the API, as in the case
of StringIO objects. Note that I'm not providing a block with Minitar::Output,
as Minitar::Output#close automatically closes both the Output object and the
wrapped data stream object.

begin
sgz = Zlib::GzipWriter.new(StringIO.new(""))
tar = Output.new(sgz)
Find.find('tests') do |entry|
Minitar.pack_file(entry, tar)
end
ensure
# Closes both tar and sgz.
tar.close
end

Copyright
=========
# Copyright 2004 Mauricio Julio Ferna'ndez Pradier and Austin Ziegler
#
# This program is based on and incorporates parts of RPA::Package from
# rpa-base (lib/rpa/package.rb and lib/rpa/util.rb) by Mauricio and has been
# adapted to be more generic by Austin.
#
# 'minitar' contains an adaptation of Ruby/ProgressBar by Satoru
# Takabayashi <[email protected]>, copyright 2001 - 2004.
#
# This program is free software. It may be redistributed and/or modified
# under the terms of the GPL version 2 (or later) or Ruby's licence.
#
# $Id: README 213 2008-02-26 22:32:11Z austin $
113 changes: 113 additions & 0 deletions vendor/gems/archive-tar-minitar-0.5.2/Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#! /usr/bin/env rake
$LOAD_PATH.unshift('lib')

require 'rubygems'
require 'rake/gempackagetask'
require 'rake/contrib/rubyforgepublisher'
require 'archive/tar/minitar'
require 'zlib'

DISTDIR = "archive-tar-minitar-#{Archive::Tar::Minitar::VERSION}"
TARDIST = "../#{DISTDIR}.tar.gz"

DATE_RE = %r<(\d{4})[./-]?(\d{2})[./-]?(\d{2})(?:[\sT]?(\d{2})[:.]?(\d{2})[:.]?(\d{2})?)?>

if ENV['RELEASE_DATE']
year, month, day, hour, minute, second = DATE_RE.match(ENV['RELEASE_DATE']).captures
year ||= 0
month ||= 0
day ||= 0
hour ||= 0
minute ||= 0
second ||= 0
ReleaseDate = Time.mktime(year, month, day, hour, minute, second)
else
ReleaseDate = nil
end

task :test do |t|
require 'test/unit/testsuite'
require 'test/unit/ui/console/testrunner'

runner = Test::Unit::UI::Console::TestRunner

$LOAD_PATH.unshift('tests')
Dir['tests/tc_*.rb'].each do |testcase|
load testcase
end

suite = Test::Unit::TestSuite.new

ObjectSpace.each_object(Class) do |testcase|
suite << testcase.suite if testcase < Test::Unit::TestCase
end

runner.run(suite)
end

spec = eval(File.read("archive-tar-minitar.gemspec"))
desc "Build the RubyGem for Archive::Tar::Minitar."
task :gem => [ :test ]
Rake::GemPackageTask.new(spec) do |g|
g.need_tar = false
g.need_zip = false
g.package_dir = ".."
end

desc "Build an Archive::Tar::Minitar .tar.gz distribution."
task :tar => [ TARDIST ]
file TARDIST do |t|
current = File.basename(Dir.pwd)
Dir.chdir("..") do
begin
files = Dir["#{current}/**/*"].select { |dd| dd !~ %r{(?:/CVS/?|~$)} }
files.map! do |dd|
ddnew = dd.gsub(/^#{current}/, DISTDIR)
mtime = ReleaseDate || File.stat(dd).mtime
if File.directory?(dd)
{ :name => ddnew, :mode => 0755, :dir => true, :mtime => mtime }
else
if dd =~ %r{bin/}
mode = 0755
else
mode = 0644
end
data = File.read(dd)
{ :name => ddnew, :mode => mode, :data => data, :size => data.size,
:mtime => mtime }
end
end

ff = File.open(t.name.gsub(%r{^\.\./}o, ''), "wb")
gz = Zlib::GzipWriter.new(ff)
tw = Archive::Tar::Minitar::Writer.new(gz)

files.each do |entry|
if entry[:dir]
tw.mkdir(entry[:name], entry)
else
tw.add_file_simple(entry[:name], entry) { |os| os.write(entry[:data]) }
end
end
ensure
tw.close if tw
gz.close if gz
end
end
end
task TARDIST => [ :test ]

def sign(file)
sh %(gpg -ba #{file})
end

task :signtar => [ :tar ] do
sign TARDIST
end
task :signgem => [ :gem ] do
sign "../#{DISTDIR}.gem"
end

desc "Build everything."
task :default => [ :signtar, :signgem ] do
end
Loading

0 comments on commit 1e10c2d

Please sign in to comment.