Permalink
Browse files

fixed bug with S3 files rotation

added more tests
  • Loading branch information...
1 parent 95bf5d2 commit 8a2e9b197acd7e32c49eb6d982654c1fe1181097 @vitaly vitaly committed May 22, 2009
Showing with 67 additions and 13 deletions.
  1. +8 −8 examples/unit/gpg_example.rb
  2. +58 −4 examples/unit/s3_example.rb
  3. +1 −1 lib/astrails/safe/s3.rb
@@ -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
@@ -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
@@ -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
@@ -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"
@@ -21,8 +79,4 @@
it "should open local file"
it "should upload file"
end
-
- describe :cleanup do
- it "should have some tests"
- end
end
View
@@ -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)

0 comments on commit 8a2e9b1

Please sign in to comment.