Skip to content

Commit

Permalink
fixed bug with S3 files rotation
Browse files Browse the repository at this point in the history
added more tests
  • Loading branch information
vitaly committed May 22, 2009
1 parent 95bf5d2 commit 8a2e9b1
Show file tree
Hide file tree
Showing 3 changed files with 67 additions and 13 deletions.
16 changes: 8 additions & 8 deletions examples/unit/gpg_example.rb
Expand Up @@ -12,8 +12,8 @@ def def_backup

def gpg(config = {}, backup = def_backup)
Astrails::Safe::Gpg.new(
@config = Astrails::Safe::Config::Node.new(nil, config),
@backup = Astrails::Safe::Backup.new(backup)
Astrails::Safe::Config::Node.new(nil, config),
Astrails::Safe::Backup.new(backup)
)
end

Expand All @@ -33,17 +33,17 @@ def gpg(config = {}, backup = def_backup)
end

it "should add .gpg extension" do
mock(@backup.extension) << '.gpg'
mock(@gpg.backup.extension) << '.gpg'
@gpg.process
end

it "should add command pipe" do
mock(@backup.command) << (/\|gpg -BLAH/)
mock(@gpg.backup.command) << (/\|gpg -BLAH/)
@gpg.process
end

it "should set compressed" do
mock(@backup).compressed = true
mock(@gpg.backup).compressed = true
@gpg.process
end
end
Expand All @@ -54,17 +54,17 @@ def gpg(config = {}, backup = def_backup)
end

it "should not touch extension" do
dont_allow(@backup.extension) << anything
dont_allow(@gpg.backup.extension) << anything
@gpg.process
end

it "should not touch command" do
dont_allow(@backup.command) << anything
dont_allow(@gpg.backup.command) << anything
@gpg.process
end

it "should not touch compressed" do
dont_allow(@backup).compressed = anything
dont_allow(@gpg.backup).compressed = anything
@gpg.process
end
end
Expand Down
62 changes: 58 additions & 4 deletions examples/unit/s3_example.rb
Expand Up @@ -2,6 +2,64 @@

describe Astrails::Safe::S3 do

def def_config
{
:s3 => {
:bucket => "_bucket",
:key => "_key",
:secret => "_secret",
:path => "s3_path"
},
:keep => {
:s3 => 2
}
}
end

def def_backup
{
:kind => "_kind",
:filename => "/backup/somewhere/_kind-_id.NOW.bar",
:extension => ".bar",
:id => "_id",
:timestamp => "NOW"
}
end

def s3(config = def_config, backup = def_backup)
Astrails::Safe::S3.new(
Astrails::Safe::Config::Node.new(nil, config),
Astrails::Safe::Backup.new(backup)
)
end

describe :cleanup do

before(:each) do
@s3 = s3

@files = [4,1,3,2].to_a.map { |i| stub(o = {}).key {"aaaaa#{i}"}; o }

stub(AWS::S3::Bucket).objects("_bucket", :prefix => "s3_path/_kind-_id", :max_keys => 4) {@files}
stub(AWS::S3::Bucket).find("_bucket").stub![anything].stub!.delete
end

it "should check [:keep, :s3]" do
mock(@s3.config).[](:keep, :s3) {nil}
dont_allow(@s3.backup).filename
@s3.send :cleanup
end

it "should delete extra files" do
mock(AWS::S3::Bucket).find("_bucket").mock!["aaaaa1"].mock!.delete
mock(AWS::S3::Bucket).find("_bucket").mock!["aaaaa2"].mock!.delete
@s3.send :cleanup
end

it "should have more tests"

end

describe :active do
it "should be true when all params are set"
it "should be false if bucket is missing"
Expand All @@ -21,8 +79,4 @@
it "should open local file"
it "should upload file"
end

describe :cleanup do
it "should have some tests"
end
end
2 changes: 1 addition & 1 deletion lib/astrails/safe/s3.rb
Expand Up @@ -33,7 +33,7 @@ def cleanup

return unless keep = @config[:keep, :s3]

base = File.basename(filename).split(".").first
base = File.basename(@backup.filename).split(".").first

puts "listing files in #{bucket}:#{prefix}/#{base}"
files = AWS::S3::Bucket.objects(bucket, :prefix => "#{prefix}/#{base}", :max_keys => keep * 2)
Expand Down

0 comments on commit 8a2e9b1

Please sign in to comment.