Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add broken tests.

  • Loading branch information...
commit 4c5f757a004d2c7d995758b3eb8c70f299f31bf0 1 parent c5969e4
H. Wade Minter minter authored vitaly committed
159 examples/unit/cloudfiles_example.rb
View
@@ -0,0 +1,159 @@
+require File.expand_path(File.dirname(__FILE__) + '/../example_helper')
+
+describe Astrails::Safe::Cloudfiles do
+
+ def def_config
+ {
+ :cloudfiles => {
+ :container => "_container",
+ :user => "_user",
+ :api_key => "_api_key",
+ },
+ :keep => {
+ :cloudfiles => 2
+ }
+ }
+ end
+
+ def def_backup(extra = {})
+ {
+ :kind => "_kind",
+ :filename => "/backup/somewhere/_kind-_id.NOW.bar",
+ :extension => ".bar",
+ :id => "_id",
+ :timestamp => "NOW"
+ }.merge(extra)
+ end
+
+ def cloudfiles(config = def_config, backup = def_backup)
+ Astrails::Safe::Cloudfiles.new(
+ Astrails::Safe::Config::Node.new(nil, config),
+ Astrails::Safe::Backup.new(backup)
+ )
+ end
+
+ describe :cleanup do
+
+ before(:each) do
+ @cloudfiles = cloudfiles
+ @files = [4,1,3,2].to_a.map { |i| stub(o = {}).name {"aaaaa#{i}"}; o }
+ mock.instance_of(CloudFiles::Container).objects(:prefix => "_kind/_id/_kind-_id.") { @files }
+ stub(CloudFiles::Authentication).new { true }
+
+ end
+
+ it "should check [:keep, :cloudfiles]" do
+ @cloudfiles.config[:keep].data["cloudfiles"] = nil
+ dont_allow(@cloudfiles.backup).filename
+ @cloudfiles.send :cleanup
+ end
+
+ it "should delete extra files" do
+ mock(CloudFiles::Connection).container("_container").mock!["aaaaa1"].mock!.delete
+ mock(CloudFiles::Connection).container("_container").mock!["aaaaa2"].mock!.delete
+ @cloudfiles.send :cleanup
+ end
+
+ end
+
+ # describe :active do
+ # before(:each) do
+ # @s3 = s3
+ # end
+ #
+ # it "should be true when all params are set" do
+ # @s3.should be_active
+ # end
+ #
+ # it "should be false if bucket is missing" do
+ # @s3.config[:s3].data["bucket"] = nil
+ # @s3.should_not be_active
+ # end
+ #
+ # it "should be false if key is missing" do
+ # @s3.config[:s3].data["key"] = nil
+ # @s3.should_not be_active
+ # end
+ #
+ # it "should be false if secret is missing" do
+ # @s3.config[:s3].data["secret"] = nil
+ # @s3.should_not be_active
+ # end
+ # end
+ #
+ # describe :path do
+ # before(:each) do
+ # @s3 = s3
+ # end
+ # it "should use s3/path 1st" do
+ # @s3.config[:s3].data["path"] = "s3_path"
+ # @s3.config[:local] = {:path => "local_path"}
+ # @s3.send(:path).should == "s3_path"
+ # end
+ #
+ # it "should use local/path 2nd" do
+ # @s3.config[:local] = {:path => "local_path"}
+ # @s3.send(:path).should == "local_path"
+ # end
+ #
+ # it "should use constant 3rd" do
+ # @s3.send(:path).should == "_kind/_id"
+ # end
+ #
+ # end
+ #
+ # describe :save do
+ # def add_stubs(*stubs)
+ # stubs.each do |s|
+ # case s
+ # when :connection
+ # stub(AWS::S3::Base).establish_connection!(:access_key_id => "_key", :secret_access_key => "_secret", :use_ssl => true)
+ # when :stat
+ # stub(File).stat("foo").stub!.size {123}
+ # when :create_bucket
+ # stub(AWS::S3::Bucket).create
+ # when :file_open
+ # stub(File).open("foo") {|f, block| block.call(:opened_file)}
+ # when :s3_store
+ # stub(AWS::S3::S3Object).store(@full_path, :opened_file, "_bucket")
+ # end
+ # end
+ # end
+ #
+ # before(:each) do
+ # @s3 = s3(def_config, def_backup(:path => "foo"))
+ # @full_path = "_kind/_id/backup/somewhere/_kind-_id.NOW.bar.bar"
+ # end
+ #
+ # it "should fail if no backup.file is set" do
+ # @s3.backup.path = nil
+ # proc {@s3.send(:save)}.should raise_error(RuntimeError)
+ # end
+ #
+ # it "should establish s3 connection" do
+ # mock(AWS::S3::Base).establish_connection!(:access_key_id => "_key", :secret_access_key => "_secret", :use_ssl => true)
+ # add_stubs(:stat, :create_bucket, :file_open, :s3_store)
+ # @s3.send(:save)
+ # end
+ #
+ # it "should open local file" do
+ # add_stubs(:connection, :stat, :create_bucket)
+ # mock(File).open("foo")
+ # @s3.send(:save)
+ # end
+ #
+ # it "should upload file" do
+ # add_stubs(:connection, :stat, :create_bucket, :file_open)
+ # mock(AWS::S3::S3Object).store(@full_path, :opened_file, "_bucket")
+ # @s3.send(:save)
+ # end
+ #
+ # it "should fail on files bigger then 5G" do
+ # add_stubs(:connection)
+ # mock(File).stat("foo").stub!.size {5*1024*1024*1024+1}
+ # mock(STDERR).puts(anything)
+ # dont_allow(Benchmark).realtime
+ # @s3.send(:save)
+ # end
+ # end
+end
6 lib/astrails/safe/cloudfiles.rb
View
@@ -41,11 +41,13 @@ def cleanup
puts "listing files: #{container}:#{base}*" if $_VERBOSE
cf = CloudFiles::Connection.new(user, api_key, true, service_net) unless $LOCAL
- files = cf.container(container).objects(:prefix => base)
+ cf_container = cf.container(container)
+ files = cf_container.objects(:prefix => base)
+ print "DEBUG: Files is #{files.to_s}\n"
cleanup_with_limit(files, keep) do |f|
puts "removing Cloud File #{container}:#{f}" if $DRY_RUN || $_VERBOSE
- cf.container(container).delete_object(f) unless $DRY_RUN || $LOCAL
+ cf_container.delete_object(f) unless $DRY_RUN || $LOCAL
end
end
Please sign in to comment.
Something went wrong with that request. Please try again.