interu-backup 3.0.16
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +2 -0
- data/Gemfile +31 -0
- data/Gemfile.lock +117 -0
- data/Guardfile +17 -0
- data/LICENSE.md +24 -0
- data/README.md +332 -0
- data/backup.gemspec +31 -0
- data/bin/backup +267 -0
- data/lib/backup.rb +181 -0
- data/lib/backup/archive.rb +73 -0
- data/lib/backup/cli.rb +82 -0
- data/lib/backup/compressor/base.rb +17 -0
- data/lib/backup/compressor/bzip2.rb +64 -0
- data/lib/backup/compressor/gzip.rb +61 -0
- data/lib/backup/configuration/base.rb +15 -0
- data/lib/backup/configuration/compressor/base.rb +10 -0
- data/lib/backup/configuration/compressor/bzip2.rb +23 -0
- data/lib/backup/configuration/compressor/gzip.rb +23 -0
- data/lib/backup/configuration/database/base.rb +18 -0
- data/lib/backup/configuration/database/mongodb.rb +41 -0
- data/lib/backup/configuration/database/mysql.rb +37 -0
- data/lib/backup/configuration/database/postgresql.rb +37 -0
- data/lib/backup/configuration/database/redis.rb +35 -0
- data/lib/backup/configuration/encryptor/base.rb +10 -0
- data/lib/backup/configuration/encryptor/gpg.rb +17 -0
- data/lib/backup/configuration/encryptor/open_ssl.rb +26 -0
- data/lib/backup/configuration/helpers.rb +54 -0
- data/lib/backup/configuration/notifier/base.rb +39 -0
- data/lib/backup/configuration/notifier/campfire.rb +25 -0
- data/lib/backup/configuration/notifier/mail.rb +52 -0
- data/lib/backup/configuration/notifier/presently.rb +25 -0
- data/lib/backup/configuration/notifier/twitter.rb +21 -0
- data/lib/backup/configuration/storage/base.rb +18 -0
- data/lib/backup/configuration/storage/cloudfiles.rb +21 -0
- data/lib/backup/configuration/storage/dropbox.rb +29 -0
- data/lib/backup/configuration/storage/ftp.rb +25 -0
- data/lib/backup/configuration/storage/rsync.rb +25 -0
- data/lib/backup/configuration/storage/s3.rb +25 -0
- data/lib/backup/configuration/storage/scp.rb +25 -0
- data/lib/backup/configuration/storage/sftp.rb +25 -0
- data/lib/backup/configuration/syncer/rsync.rb +45 -0
- data/lib/backup/configuration/syncer/s3.rb +33 -0
- data/lib/backup/database/base.rb +33 -0
- data/lib/backup/database/mongodb.rb +179 -0
- data/lib/backup/database/mysql.rb +104 -0
- data/lib/backup/database/postgresql.rb +111 -0
- data/lib/backup/database/redis.rb +105 -0
- data/lib/backup/dependency.rb +96 -0
- data/lib/backup/encryptor/base.rb +17 -0
- data/lib/backup/encryptor/gpg.rb +78 -0
- data/lib/backup/encryptor/open_ssl.rb +67 -0
- data/lib/backup/exception/command_not_found.rb +8 -0
- data/lib/backup/finder.rb +39 -0
- data/lib/backup/logger.rb +102 -0
- data/lib/backup/model.rb +272 -0
- data/lib/backup/notifier/base.rb +29 -0
- data/lib/backup/notifier/binder.rb +32 -0
- data/lib/backup/notifier/campfire.rb +194 -0
- data/lib/backup/notifier/mail.rb +141 -0
- data/lib/backup/notifier/presently.rb +105 -0
- data/lib/backup/notifier/templates/notify_failure.erb +33 -0
- data/lib/backup/notifier/templates/notify_success.erb +16 -0
- data/lib/backup/notifier/twitter.rb +87 -0
- data/lib/backup/storage/base.rb +67 -0
- data/lib/backup/storage/cloudfiles.rb +95 -0
- data/lib/backup/storage/dropbox.rb +91 -0
- data/lib/backup/storage/ftp.rb +114 -0
- data/lib/backup/storage/object.rb +45 -0
- data/lib/backup/storage/rsync.rb +129 -0
- data/lib/backup/storage/s3.rb +180 -0
- data/lib/backup/storage/scp.rb +106 -0
- data/lib/backup/storage/sftp.rb +106 -0
- data/lib/backup/syncer/base.rb +10 -0
- data/lib/backup/syncer/rsync.rb +152 -0
- data/lib/backup/syncer/s3.rb +118 -0
- data/lib/backup/version.rb +43 -0
- data/lib/templates/archive +7 -0
- data/lib/templates/compressor/bzip2 +7 -0
- data/lib/templates/compressor/gzip +7 -0
- data/lib/templates/database/mongodb +14 -0
- data/lib/templates/database/mysql +14 -0
- data/lib/templates/database/postgresql +14 -0
- data/lib/templates/database/redis +13 -0
- data/lib/templates/encryptor/gpg +12 -0
- data/lib/templates/encryptor/openssl +8 -0
- data/lib/templates/notifier/campfire +11 -0
- data/lib/templates/notifier/mail +17 -0
- data/lib/templates/notifier/presently +12 -0
- data/lib/templates/notifier/twitter +12 -0
- data/lib/templates/readme +15 -0
- data/lib/templates/storage/cloudfiles +10 -0
- data/lib/templates/storage/dropbox +12 -0
- data/lib/templates/storage/ftp +11 -0
- data/lib/templates/storage/rsync +10 -0
- data/lib/templates/storage/s3 +21 -0
- data/lib/templates/storage/scp +11 -0
- data/lib/templates/storage/sftp +11 -0
- data/lib/templates/syncer/rsync +17 -0
- data/lib/templates/syncer/s3 +15 -0
- data/spec/archive_spec.rb +90 -0
- data/spec/backup_spec.rb +11 -0
- data/spec/compressor/bzip2_spec.rb +59 -0
- data/spec/compressor/gzip_spec.rb +59 -0
- data/spec/configuration/base_spec.rb +35 -0
- data/spec/configuration/compressor/gzip_spec.rb +28 -0
- data/spec/configuration/database/base_spec.rb +16 -0
- data/spec/configuration/database/mongodb_spec.rb +30 -0
- data/spec/configuration/database/mysql_spec.rb +32 -0
- data/spec/configuration/database/postgresql_spec.rb +32 -0
- data/spec/configuration/database/redis_spec.rb +30 -0
- data/spec/configuration/encryptor/gpg_spec.rb +25 -0
- data/spec/configuration/encryptor/open_ssl_spec.rb +31 -0
- data/spec/configuration/notifier/campfire_spec.rb +20 -0
- data/spec/configuration/notifier/mail_spec.rb +32 -0
- data/spec/configuration/notifier/twitter_spec.rb +22 -0
- data/spec/configuration/storage/cloudfiles_spec.rb +34 -0
- data/spec/configuration/storage/dropbox_spec.rb +43 -0
- data/spec/configuration/storage/ftp_spec.rb +40 -0
- data/spec/configuration/storage/rsync_spec.rb +37 -0
- data/spec/configuration/storage/s3_spec.rb +37 -0
- data/spec/configuration/storage/scp_spec.rb +40 -0
- data/spec/configuration/storage/sftp_spec.rb +40 -0
- data/spec/configuration/syncer/rsync_spec.rb +46 -0
- data/spec/configuration/syncer/s3_spec.rb +43 -0
- data/spec/database/base_spec.rb +30 -0
- data/spec/database/mongodb_spec.rb +181 -0
- data/spec/database/mysql_spec.rb +150 -0
- data/spec/database/postgresql_spec.rb +164 -0
- data/spec/database/redis_spec.rb +122 -0
- data/spec/encryptor/gpg_spec.rb +57 -0
- data/spec/encryptor/open_ssl_spec.rb +102 -0
- data/spec/logger_spec.rb +58 -0
- data/spec/model_spec.rb +236 -0
- data/spec/notifier/campfire_spec.rb +96 -0
- data/spec/notifier/mail_spec.rb +97 -0
- data/spec/notifier/presently_spec.rb +99 -0
- data/spec/notifier/twitter_spec.rb +86 -0
- data/spec/spec_helper.rb +25 -0
- data/spec/storage/base_spec.rb +33 -0
- data/spec/storage/cloudfiles_spec.rb +102 -0
- data/spec/storage/dropbox_spec.rb +105 -0
- data/spec/storage/ftp_spec.rb +133 -0
- data/spec/storage/object_spec.rb +74 -0
- data/spec/storage/rsync_spec.rb +131 -0
- data/spec/storage/s3_spec.rb +110 -0
- data/spec/storage/scp_spec.rb +129 -0
- data/spec/storage/sftp_spec.rb +125 -0
- data/spec/syncer/rsync_spec.rb +195 -0
- data/spec/syncer/s3_spec.rb +139 -0
- data/spec/version_spec.rb +21 -0
- metadata +231 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Notifier::Mail do
|
6
|
+
let(:notifier) do
|
7
|
+
Backup::Notifier::Mail.new do |mail|
|
8
|
+
mail.from = 'my.sender.email@gmail.com'
|
9
|
+
mail.to = 'my.receiver.email@gmail.com'
|
10
|
+
mail.address = 'smtp.gmail.com'
|
11
|
+
mail.port = 587
|
12
|
+
mail.domain = 'your.host.name'
|
13
|
+
mail.user_name = 'user'
|
14
|
+
mail.password = 'secret'
|
15
|
+
mail.authentication = 'plain'
|
16
|
+
mail.enable_starttls_auto = true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
it do
|
21
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
22
|
+
notifier.to.should == 'my.receiver.email@gmail.com'
|
23
|
+
notifier.address.should == 'smtp.gmail.com'
|
24
|
+
notifier.port.should == 587
|
25
|
+
notifier.domain.should == 'your.host.name'
|
26
|
+
notifier.user_name.should == 'user'
|
27
|
+
notifier.password.should == 'secret'
|
28
|
+
notifier.authentication.should == 'plain'
|
29
|
+
notifier.enable_starttls_auto.should == true
|
30
|
+
|
31
|
+
notifier.on_success.should == true
|
32
|
+
notifier.on_failure.should == true
|
33
|
+
end
|
34
|
+
|
35
|
+
describe 'defaults' do
|
36
|
+
it do
|
37
|
+
Backup::Configuration::Notifier::Mail.defaults do |mail|
|
38
|
+
mail.to = 'some.receiver.email@gmail.com'
|
39
|
+
mail.on_success = false
|
40
|
+
mail.on_failure = true
|
41
|
+
end
|
42
|
+
notifier = Backup::Notifier::Mail.new do |mail|
|
43
|
+
mail.from = 'my.sender.email@gmail.com'
|
44
|
+
end
|
45
|
+
|
46
|
+
notifier.to.should == 'some.receiver.email@gmail.com'
|
47
|
+
notifier.from.should == 'my.sender.email@gmail.com'
|
48
|
+
notifier.on_success.should == false
|
49
|
+
notifier.on_failure.should == true
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
describe '#initialize' do
|
54
|
+
it do
|
55
|
+
Backup::Notifier::Mail.any_instance.expects(:set_defaults!)
|
56
|
+
Backup::Notifier::Mail.new
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
describe '#perform!' do
|
61
|
+
let(:model) { Backup::Model.new('blah', 'blah') {} }
|
62
|
+
before do
|
63
|
+
notifier.on_success = false
|
64
|
+
notifier.on_failure = false
|
65
|
+
end
|
66
|
+
|
67
|
+
context "when successful" do
|
68
|
+
it do
|
69
|
+
Backup::Logger.expects(:message).with("Backup::Notifier::Mail started notifying about the process.")
|
70
|
+
notifier.expects("notify_success!")
|
71
|
+
notifier.on_success = true
|
72
|
+
notifier.perform!(model)
|
73
|
+
end
|
74
|
+
|
75
|
+
it do
|
76
|
+
notifier.expects("notify_success!").never
|
77
|
+
notifier.on_success = false
|
78
|
+
notifier.perform!(model)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
context "when failed" do
|
83
|
+
it do
|
84
|
+
Backup::Logger.expects(:message).with("Backup::Notifier::Mail started notifying about the process.")
|
85
|
+
notifier.expects("notify_failure!")
|
86
|
+
notifier.on_failure = true
|
87
|
+
notifier.perform!(model, Exception.new)
|
88
|
+
end
|
89
|
+
|
90
|
+
it do
|
91
|
+
notifier.expects("notify_failure!").never
|
92
|
+
notifier.on_failure = false
|
93
|
+
notifier.perform!(model, Exception.new)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Notifier::Presently do
|
6
|
+
let(:notifier) do
|
7
|
+
Backup::Notifier::Presently.new do |presently|
|
8
|
+
presently.user_name = 'user_name'
|
9
|
+
presently.subdomain = 'subdomain'
|
10
|
+
presently.password = 'password'
|
11
|
+
presently.group_id = 'group_id'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it do
|
16
|
+
notifier.user_name.should == 'user_name'
|
17
|
+
notifier.subdomain.should == 'subdomain'
|
18
|
+
notifier.password.should == 'password'
|
19
|
+
notifier.group_id.should == 'group_id'
|
20
|
+
|
21
|
+
notifier.on_success.should == true
|
22
|
+
notifier.on_failure.should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'defaults' do
|
26
|
+
it do
|
27
|
+
Backup::Configuration::Notifier::Presently.defaults do |presently|
|
28
|
+
presently.user_name = 'old_user_name'
|
29
|
+
presently.on_success = false
|
30
|
+
presently.on_failure = true
|
31
|
+
end
|
32
|
+
notifier = Backup::Notifier::Presently.new do |presently|
|
33
|
+
presently.user_name = 'new_user_name'
|
34
|
+
end
|
35
|
+
|
36
|
+
notifier.user_name.should == 'new_user_name'
|
37
|
+
notifier.on_success.should == false
|
38
|
+
notifier.on_failure.should == true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#initialize' do
|
43
|
+
it do
|
44
|
+
Backup::Notifier::Presently.any_instance.expects(:set_defaults!)
|
45
|
+
Backup::Notifier::Presently.new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#perform!' do
|
50
|
+
let(:model) { Backup::Model.new('blah', 'blah') {} }
|
51
|
+
before do
|
52
|
+
notifier.on_success = false
|
53
|
+
notifier.on_failure = false
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when successful" do
|
57
|
+
it do
|
58
|
+
Backup::Logger.expects(:message).with("Backup::Notifier::Presently started notifying about the process.")
|
59
|
+
notifier.expects("notify_success!")
|
60
|
+
notifier.on_success = true
|
61
|
+
notifier.perform!(model)
|
62
|
+
end
|
63
|
+
|
64
|
+
it do
|
65
|
+
notifier.expects("notify_success!").never
|
66
|
+
notifier.on_success = false
|
67
|
+
notifier.perform!(model)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when failed" do
|
72
|
+
it do
|
73
|
+
Backup::Logger.expects(:message).with("Backup::Notifier::Presently started notifying about the process.")
|
74
|
+
notifier.expects("notify_failure!")
|
75
|
+
notifier.on_failure = true
|
76
|
+
notifier.perform!(model, Exception.new)
|
77
|
+
end
|
78
|
+
|
79
|
+
it do
|
80
|
+
notifier.expects("notify_failure!").never
|
81
|
+
notifier.on_failure = false
|
82
|
+
notifier.perform!(model, Exception.new)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
describe Backup::Notifier::Presently::Client do
|
88
|
+
let(:client) do
|
89
|
+
Backup::Notifier::Presently::Client.new('subdomain', 'user_name', 'password', 'group_id')
|
90
|
+
end
|
91
|
+
|
92
|
+
it do
|
93
|
+
client.user_name.should == 'user_name'
|
94
|
+
client.subdomain.should == 'subdomain'
|
95
|
+
client.password.should == 'password'
|
96
|
+
client.group_id.should == 'group_id'
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
@@ -0,0 +1,86 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Notifier::Twitter do
|
6
|
+
let(:notifier) do
|
7
|
+
Backup::Notifier::Twitter.new do |twitter|
|
8
|
+
twitter.consumer_key = 'consumer_key'
|
9
|
+
twitter.consumer_secret = 'consumer_secret'
|
10
|
+
twitter.oauth_token = 'oauth_token'
|
11
|
+
twitter.oauth_token_secret = 'oauth_token_secret'
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
it do
|
16
|
+
notifier.consumer_key.should == 'consumer_key'
|
17
|
+
notifier.consumer_secret.should == 'consumer_secret'
|
18
|
+
notifier.oauth_token.should == 'oauth_token'
|
19
|
+
notifier.oauth_token_secret.should == 'oauth_token_secret'
|
20
|
+
|
21
|
+
notifier.on_success.should == true
|
22
|
+
notifier.on_failure.should == true
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'defaults' do
|
26
|
+
it do
|
27
|
+
Backup::Configuration::Notifier::Twitter.defaults do |twitter|
|
28
|
+
twitter.consumer_key = 'new_consumer_key'
|
29
|
+
twitter.on_success = false
|
30
|
+
twitter.on_failure = true
|
31
|
+
end
|
32
|
+
notifier = Backup::Notifier::Twitter.new do |twitter|
|
33
|
+
twitter.consumer_key = 'my_own_consumer_key'
|
34
|
+
end
|
35
|
+
|
36
|
+
notifier.consumer_key.should == 'my_own_consumer_key'
|
37
|
+
notifier.on_success.should == false
|
38
|
+
notifier.on_failure.should == true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
describe '#initialize' do
|
43
|
+
it do
|
44
|
+
Backup::Notifier::Twitter.any_instance.expects(:set_defaults!)
|
45
|
+
Backup::Notifier::Twitter.new
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
describe '#perform!' do
|
50
|
+
let(:model) { Backup::Model.new('blah', 'blah') {} }
|
51
|
+
before do
|
52
|
+
notifier.on_success = false
|
53
|
+
notifier.on_failure = false
|
54
|
+
end
|
55
|
+
|
56
|
+
context "when successful" do
|
57
|
+
it do
|
58
|
+
Backup::Logger.expects(:message).with("Backup::Notifier::Twitter started notifying about the process.")
|
59
|
+
notifier.expects("notify_success!")
|
60
|
+
notifier.on_success = true
|
61
|
+
notifier.perform!(model)
|
62
|
+
end
|
63
|
+
|
64
|
+
it do
|
65
|
+
notifier.expects("notify_success!").never
|
66
|
+
notifier.on_success = false
|
67
|
+
notifier.perform!(model)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
context "when failed" do
|
72
|
+
it do
|
73
|
+
Backup::Logger.expects(:message).with("Backup::Notifier::Twitter started notifying about the process.")
|
74
|
+
notifier.expects("notify_failure!")
|
75
|
+
notifier.on_failure = true
|
76
|
+
notifier.perform!(model, Exception.new)
|
77
|
+
end
|
78
|
+
|
79
|
+
it do
|
80
|
+
notifier.expects("notify_failure!").never
|
81
|
+
notifier.on_failure = false
|
82
|
+
notifier.perform!(model, Exception.new)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
##
|
4
|
+
# Load Backup
|
5
|
+
require File.expand_path( '../../lib/backup', __FILE__ )
|
6
|
+
|
7
|
+
##
|
8
|
+
# Use Mocha to mock with RSpec
|
9
|
+
RSpec.configure do |config|
|
10
|
+
config.mock_with :mocha
|
11
|
+
end
|
12
|
+
|
13
|
+
# FIXTURES_PATH = File.join( File.dirname(__FILE__), 'fixtures' )
|
14
|
+
|
15
|
+
Backup.send(:remove_const, :TRIGGER) if defined? Backup::TRIGGER
|
16
|
+
Backup.send(:remove_const, :TIME) if defined? Backup::TIME
|
17
|
+
|
18
|
+
module Backup
|
19
|
+
TRIGGER = 'myapp'
|
20
|
+
TIME = Time.now.strftime("%Y.%m.%d.%H.%M.%S")
|
21
|
+
end
|
22
|
+
|
23
|
+
unless @put_ruby_version
|
24
|
+
puts @put_ruby_version = "\n\nRuby version: #{ENV['rvm_ruby_string']}\n\n"
|
25
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Storage::Base do
|
6
|
+
let(:base) { Backup::Storage::Base.new }
|
7
|
+
|
8
|
+
before do
|
9
|
+
Backup::Logger.stubs(:message)
|
10
|
+
end
|
11
|
+
|
12
|
+
it do
|
13
|
+
storage_object = mock
|
14
|
+
Backup::Storage::Object.expects(:new).with('Base').returns(storage_object)
|
15
|
+
storage_object.stubs(:load).returns([])
|
16
|
+
storage_object.expects(:write)
|
17
|
+
base.keep = 1
|
18
|
+
base.cycle!
|
19
|
+
end
|
20
|
+
|
21
|
+
it do
|
22
|
+
base.keep = 3
|
23
|
+
storage_object = mock
|
24
|
+
objects = %w[1 2 3 4].map { Backup::Storage::Base.new }
|
25
|
+
|
26
|
+
Backup::Storage::Object.expects(:new).with('Base').returns(storage_object)
|
27
|
+
storage_object.stubs(:load).returns(objects)
|
28
|
+
storage_object.expects(:write)
|
29
|
+
Backup::Storage::Base.any_instance.expects(:remove!).times(2)
|
30
|
+
|
31
|
+
base.cycle!
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,102 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require File.dirname(__FILE__) + '/../spec_helper'
|
4
|
+
|
5
|
+
describe Backup::Storage::CloudFiles do
|
6
|
+
|
7
|
+
let(:cf) do
|
8
|
+
Backup::Storage::CloudFiles.new do |cf|
|
9
|
+
cf.username = 'my_username'
|
10
|
+
cf.api_key = 'my_api_key'
|
11
|
+
cf.container = 'my_container'
|
12
|
+
cf.path = 'backups'
|
13
|
+
cf.keep = 20
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
before do
|
18
|
+
Backup::Configuration::Storage::CloudFiles.clear_defaults!
|
19
|
+
end
|
20
|
+
|
21
|
+
it 'should have defined the configuration properly' do
|
22
|
+
cf.username.should == 'my_username'
|
23
|
+
cf.api_key.should == 'my_api_key'
|
24
|
+
cf.container.should == 'my_container'
|
25
|
+
cf.path.should == 'backups'
|
26
|
+
cf.keep.should == 20
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should use the defaults if a particular attribute has not been defined' do
|
30
|
+
Backup::Configuration::Storage::CloudFiles.defaults do |cf|
|
31
|
+
cf.username = 'my_username'
|
32
|
+
cf.api_key = 'my_api_key'
|
33
|
+
end
|
34
|
+
|
35
|
+
cf = Backup::Storage::CloudFiles.new do |cf|
|
36
|
+
cf.container = 'my_container'
|
37
|
+
cf.path = 'my/backups'
|
38
|
+
end
|
39
|
+
|
40
|
+
cf.username.should == 'my_username'
|
41
|
+
cf.api_key.should == 'my_api_key'
|
42
|
+
cf.container.should == 'my_container'
|
43
|
+
cf.path.should == 'my/backups'
|
44
|
+
end
|
45
|
+
|
46
|
+
describe '#connection' do
|
47
|
+
it 'should establish a connection to Rackspace Cloud Files. using the provided credentials' do
|
48
|
+
Fog::Storage.expects(:new).with({
|
49
|
+
:provider => 'Rackspace',
|
50
|
+
:rackspace_username => 'my_username',
|
51
|
+
:rackspace_api_key => 'my_api_key'
|
52
|
+
})
|
53
|
+
|
54
|
+
cf.send(:connection)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
describe '#provider' do
|
59
|
+
it 'should be Rackspace' do
|
60
|
+
cf.provider == 'Rackspace'
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
describe '#transfer!' do
|
65
|
+
let(:connection) { mock('Fog::Storage') }
|
66
|
+
before do
|
67
|
+
Fog::Storage.stubs(:new).returns(connection)
|
68
|
+
Backup::Logger.stubs(:message)
|
69
|
+
end
|
70
|
+
|
71
|
+
it 'should transfer the provided file to the container' do
|
72
|
+
Backup::Model.new('blah', 'blah') {}
|
73
|
+
file = mock("Backup::Storage::CloudFiles::File")
|
74
|
+
File.expects(:open).with("#{File.join(Backup::TMP_PATH, "#{ Backup::TIME }.#{ Backup::TRIGGER}")}.tar").returns(file)
|
75
|
+
cf.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar").twice
|
76
|
+
connection.expects(:put_object).with('my_container', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar", file)
|
77
|
+
cf.send(:transfer!)
|
78
|
+
end
|
79
|
+
end
|
80
|
+
|
81
|
+
describe '#remove!' do
|
82
|
+
let(:connection) { mock('Fog::Storage') }
|
83
|
+
before do
|
84
|
+
Fog::Storage.stubs(:new).returns(connection)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should remove the file from the container' do
|
88
|
+
cf.expects(:remote_file).returns("#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
89
|
+
connection.expects(:delete_object).with('my_container', "backups/myapp/#{ Backup::TIME }.#{ Backup::TRIGGER }.tar")
|
90
|
+
cf.send(:remove!)
|
91
|
+
end
|
92
|
+
end
|
93
|
+
|
94
|
+
describe '#perform' do
|
95
|
+
it 'should invoke transfer! and cycle!' do
|
96
|
+
cf.expects(:transfer!)
|
97
|
+
cf.expects(:cycle!)
|
98
|
+
cf.perform!
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
end
|