Skip to content
This repository has been archived by the owner on Jul 10, 2022. It is now read-only.

Fix manifest generation with complex versions #32

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ GEM
nokogiri (>= 1.4.4, < 1.6.0)
uuidtools (~> 2.1)
json (1.8.1)
minitest (5.0.8)
nokogiri (1.5.10)
rake (10.1.1)
thor (0.18.1)
uuidtools (2.1.4)

Expand All @@ -22,3 +24,5 @@ PLATFORMS

DEPENDENCIES
deb-s3!
minitest
rake
7 changes: 7 additions & 0 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
require 'rake/testtask'

Rake::TestTask.new do |t|
t.pattern = "spec/**/*_spec.rb"
end

task :default => :test
2 changes: 2 additions & 0 deletions deb-s3.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,6 @@ Gem::Specification.new do |gem|

gem.add_dependency "thor", "~> 0.18.0"
gem.add_dependency "aws-sdk", "~> 1.18"
gem.add_development_dependency "minitest"
gem.add_development_dependency "rake"
end
14 changes: 7 additions & 7 deletions lib/deb/s3/manifest.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
require "tempfile"
require "zlib"
require 'deb/s3/utils'
require 'deb/s3/package'

class Deb::S3::Manifest
include Deb::S3::Utils
Expand All @@ -10,6 +12,8 @@ class Deb::S3::Manifest

attr_accessor :files

attr_reader :packages

def initialize
@packages = []
@component = nil
Expand Down Expand Up @@ -41,17 +45,13 @@ def parse_packages(str)
end
end

def packages
@packages
end

def add(pkg, preserve_versions)
if preserve_versions
@packages.delete_if { |p| p.name == pkg.name && p.version == pkg.version }
packages.delete_if { |p| p.name == pkg.name && p.full_version == pkg.full_version }
else
@packages.delete_if { |p| p.name == pkg.name }
packages.delete_if { |p| p.name == pkg.name }
end
@packages << pkg
packages << pkg
pkg
end

Expand Down
6 changes: 6 additions & 0 deletions lib/deb/s3/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
require "digest/md5"
require "socket"
require "tmpdir"
require 'deb/s3/utils'

class Deb::S3::Package
include Deb::S3::Utils
Expand Down Expand Up @@ -123,6 +124,11 @@ def initialize
@needs_uploading = false
end

def full_version
return nil if [epoch, version, iteration].all?(&:nil?)
[[epoch, version].compact.join(":"), iteration].compact.join("-")
end

def filename=(f)
@filename = f
@needs_uploading = true
Expand Down
45 changes: 45 additions & 0 deletions spec/deb/s3/manifest_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'deb/s3/manifest'

describe Deb::S3::Manifest do
before do
@manifest = Deb::S3::Manifest.new
end

describe "#add" do
it "removes packages which have the same full version" do
epoch = Time.now.to_i
existing_package_with_same_full_version = create_package name: "discourse", epoch: epoch, version: "0.9.8.3", iteration: "1"
new_package = create_package name: "discourse", epoch: epoch, version: "0.9.8.3", iteration: "1"

@manifest.stub :packages, [existing_package_with_same_full_version] do
@manifest.add(new_package, preserve_versions=true)
@manifest.packages.length.must_equal 1
end
end

it "does not remove packages based only on the version" do
existing_package_with_same_version = create_package name: "discourse", version: "0.9.8.3", iteration: "1"
new_package = create_package name: "discourse", version: "0.9.8.3", iteration: "2"

@manifest.stub :packages, [existing_package_with_same_version] do
@manifest.add(new_package, preserve_versions=true)
@manifest.packages.length.must_equal 2
end
end

it "removes any package with the same name, independently of the full version, if preserve_versions is false" do
existing_packages_with_same_name = [
create_package(name: "discourse", version: "0.9.8.3", iteration: "1"),
create_package(name: "discourse"),
create_package(name: "discourse", version: "0.9.8.4", iteration: "1", epoch: "2")
]
new_package = create_package name: "discourse", version: "0.9.8.5"

@manifest.stub :packages, existing_packages_with_same_name do
@manifest.add(new_package, preserve_versions=false)
@manifest.packages.must_equal [new_package]
end
end
end
end
43 changes: 43 additions & 0 deletions spec/deb/s3/package_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
require File.expand_path('../../../spec_helper', __FILE__)
require 'deb/s3/package'

describe Deb::S3::Package do
describe ".parse_string" do
it "creates a Package object with the right attributes" do
package = Deb::S3::Package.parse_string(File.read(fixture("Packages")))
package.version.must_equal("0.9.8.3")
package.epoch.must_equal(nil)
package.iteration.must_equal("1396474125.12e4179.wheezy")
package.full_version.must_equal("0.9.8.3-1396474125.12e4179.wheezy")
end
end

describe "#full_version" do
it "returns nil if no version, epoch, iteration" do
package = create_package
package.full_version.must_equal nil
end

it "returns only the version if no epoch and no iteration" do
package = create_package version: "0.9.8"
package.full_version.must_equal "0.9.8"
end

it "returns epoch:version if epoch and version" do
epoch = Time.now.to_i
package = create_package version: "0.9.8", epoch: epoch
package.full_version.must_equal "#{epoch}:0.9.8"
end

it "returns version-iteration if version and iteration" do
package = create_package version: "0.9.8", iteration: "2"
package.full_version.must_equal "0.9.8-2"
end

it "returns epoch:version-iteration if epoch and version and iteration" do
epoch = Time.now.to_i
package = create_package version: "0.9.8", iteration: "2", epoch: epoch
package.full_version.must_equal "#{epoch}:0.9.8-2"
end
end
end
18 changes: 18 additions & 0 deletions spec/fixtures/Packages
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
Package: discourse
Version: 0.9.8.3-1396474125.12e4179.wheezy
License: unknown
Vendor: @ba8d89490f8f
Architecture: amd64
Maintainer: <@ba8d89490f8f>
Installed-Size: 264979
Depends: mysql-common, libpq5, libsqlite3-0, openssl, libxml2, libxslt1.1, libreadline5, libreadline6, libssl1.0.0, libmysqlclient18, libevent-2.0-5, libevent-core-2.0-5, libevent-extra-2.0-5
Provides: discourse
Section: default
Priority: extra
Homepage: http://www.discourse.org
Filename: pool/d/di/discourse_0.9.8.3-1396474125.12e4179.wheezy_amd64.deb
Size: 85733514
SHA1: 919b7b7860ed0f5850d031072c00a64c6f41657a
SHA256: ab79c879c498086b62289da77d770725939acababcbcd8d8af5cf46e1971fd0e
MD5sum: 11aa00eeb849212667d81ce1904daa4d
Description: A platform for community discussion. Free, open, simple.
16 changes: 16 additions & 0 deletions spec/spec_helper.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
require "minitest/autorun"

$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
require 'deb/s3'

def fixture(name)
File.expand_path("../fixtures/#{name}", __FILE__)
end

def create_package(attributes = {})
package = Deb::S3::Package.new
attributes.each do |k,v|
package.send("#{k}=".to_sym, v)
end
package
end