Skip to content

Commit

Permalink
Add beginnings of MiniTest::Spec support, and some basic template tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
ohookins committed Jan 2, 2012
1 parent b94620b commit 9f5cf62
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1 deletion.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,9 @@ Targets:

## Something broken?

FPM lacks automated testing (though I have that planned).
FPM lacks much automated testing. It does have:
* BASH-based acceptance tests for finished packages
* MiniTest-based unit tests (in their infancy)

To compensate for lack of automated testing, should you find any bugs that
would prevent you from using fpm yourself, please let me know (file a ticket,
Expand Down
10 changes: 10 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,17 @@
require 'rake/testtask'

task :default => [:package]

task :test do
system("make -C test")
Rake::Task[:minitest].invoke # Run these tests as well.
# Eventually all the tests should be minitest-run or initiated.
end

# MiniTest tests
Rake::TestTask.new do |t|
t.pattern = 'test/fpm/*.rb'
t.name = 'minitest'
end

task :package => [:test, :package_real] do
Expand Down
29 changes: 29 additions & 0 deletions test/fpm/fpm_target_deb.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
require 'rubygems'
require 'minitest/autorun'
require 'fpm/target/deb'
require 'fpm/source/dir'
require 'erb'

describe FPM::Target::Deb do
it 'renders the control file template correctly' do
# Use the 'dir' source as it is the simplest to test in isolation
root = File.join(File.dirname(__FILE__), 'test_data')
# paths = root = File.join(File.dirname(__FILE__), 'test_data')
# FIXME: Should be a fully-specifed path, but needs
# some fixes in the path handling to remove the root components.
paths = './test_data/dir/'
source = FPM::Source::Dir.new(paths, root)
deb = FPM::Target::Deb.new(source)

# Fix some properties of the package to get consistent output
deb.scripts = {}
deb.architecture = 'all'
deb.maintainer = '<testdude@example.com>'

# Render the template and compare it to our canned output
control_output = deb.render_spec
test_file = File.join(File.dirname(__FILE__), 'test_data', 'test_deb.control')
file_output = File.read(test_file)
control_output.must_equal file_output
end
end
28 changes: 28 additions & 0 deletions test/fpm/fpm_target_rpm.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
require 'rubygems'
require 'minitest/autorun'
require 'fpm/target/rpm'
require 'fpm/source/dir'
require 'erb'

describe FPM::Target::Rpm do
it 'renders the spec file template correctly' do
# Use the 'dir' source as it is the simplest to test in isolation
root = File.join(File.dirname(__FILE__), 'test_data')
# paths = root = File.join(File.dirname(__FILE__), 'test_data')
# FIXME: Should be a fully-specifed path, but needs
# some fixes in the path handling to remove the root components.
paths = './test_data/dir/'
source = FPM::Source::Dir.new(paths, root)
rpm = FPM::Target::Rpm.new(source)

# Fix some properties of the package to get consistent output
rpm.scripts = {}
rpm.architecture = 'all'

# Render the template and compare it to our canned output
spec_output = rpm.render_spec
test_file = File.join(File.dirname(__FILE__), 'test_data', 'test_rpm.spec')
file_output = File.read(test_file)
spec_output.must_equal file_output
end
end
Empty file added test/fpm/test_data/dir/foo
Empty file.
9 changes: 9 additions & 0 deletions test/fpm/test_data/test_deb.control
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
Package: test-data
Version: 1.0
Architecture: all
Maintainer: <testdude@example.com>
Standards-Version: 3.9.1
Section: default
Priority: extra
Homepage: http://nourlgiven.example.com/no/url/given
Description: no description given
39 changes: 39 additions & 0 deletions test/fpm/test_data/test_rpm.spec
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
%define __jar_repack 0

Name: test_data
Version: 1.0
Release: 1
Summary: no description given
BuildArch: noarch
AutoReqProv: no

Group: default
License: unknown
URL: http://nourlgiven.example.com/no/url/given
Source0: %{_sourcedir}/data.tar.gz
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)

%description
no description given

%prep
# noop

%build
# noop

%install
# some rpm implementations delete the build dir and then recreate it by
# default, for some reason. Whatever, let's work around it.
cd $RPM_BUILD_ROOT
tar -zxf %SOURCE0

%clean
rm -rf $RPM_BUILD_ROOT

%files
%defattr(-,root,root,-)

/test_data/dir/

%changelog

0 comments on commit 9f5cf62

Please sign in to comment.