backup 3.0.20 → 3.0.21

Sign up to get free protection for your applications and to get access to all the features.
Files changed (178) hide show
  1. data/Gemfile +1 -5
  2. data/Gemfile.lock +46 -50
  3. data/README.md +54 -27
  4. data/lib/backup.rb +16 -39
  5. data/lib/backup/archive.rb +42 -18
  6. data/lib/backup/cleaner.rb +110 -25
  7. data/lib/backup/cli/helpers.rb +17 -32
  8. data/lib/backup/cli/utility.rb +46 -107
  9. data/lib/backup/compressor/base.rb +14 -2
  10. data/lib/backup/compressor/bzip2.rb +10 -24
  11. data/lib/backup/compressor/gzip.rb +10 -24
  12. data/lib/backup/compressor/lzma.rb +10 -23
  13. data/lib/backup/compressor/pbzip2.rb +12 -32
  14. data/lib/backup/config.rb +171 -0
  15. data/lib/backup/configuration/compressor/base.rb +1 -2
  16. data/lib/backup/configuration/compressor/pbzip2.rb +4 -4
  17. data/lib/backup/configuration/database/base.rb +2 -1
  18. data/lib/backup/configuration/database/mongodb.rb +8 -0
  19. data/lib/backup/configuration/database/mysql.rb +4 -0
  20. data/lib/backup/configuration/database/postgresql.rb +4 -0
  21. data/lib/backup/configuration/database/redis.rb +4 -0
  22. data/lib/backup/configuration/database/riak.rb +5 -1
  23. data/lib/backup/configuration/encryptor/base.rb +1 -2
  24. data/lib/backup/configuration/encryptor/open_ssl.rb +1 -1
  25. data/lib/backup/configuration/helpers.rb +7 -2
  26. data/lib/backup/configuration/notifier/base.rb +4 -28
  27. data/lib/backup/configuration/storage/base.rb +1 -1
  28. data/lib/backup/configuration/storage/dropbox.rb +14 -4
  29. data/lib/backup/configuration/syncer/base.rb +10 -0
  30. data/lib/backup/configuration/syncer/rsync/base.rb +28 -0
  31. data/lib/backup/configuration/syncer/rsync/local.rb +11 -0
  32. data/lib/backup/configuration/syncer/rsync/pull.rb +11 -0
  33. data/lib/backup/configuration/syncer/rsync/push.rb +31 -0
  34. data/lib/backup/configuration/syncer/s3.rb +0 -4
  35. data/lib/backup/database/base.rb +25 -7
  36. data/lib/backup/database/mongodb.rb +112 -75
  37. data/lib/backup/database/mysql.rb +54 -29
  38. data/lib/backup/database/postgresql.rb +60 -42
  39. data/lib/backup/database/redis.rb +61 -39
  40. data/lib/backup/database/riak.rb +35 -11
  41. data/lib/backup/dependency.rb +4 -5
  42. data/lib/backup/encryptor/base.rb +13 -1
  43. data/lib/backup/encryptor/gpg.rb +39 -39
  44. data/lib/backup/encryptor/open_ssl.rb +28 -38
  45. data/lib/backup/logger.rb +20 -11
  46. data/lib/backup/model.rb +206 -163
  47. data/lib/backup/notifier/base.rb +27 -25
  48. data/lib/backup/notifier/campfire.rb +7 -13
  49. data/lib/backup/notifier/hipchat.rb +28 -28
  50. data/lib/backup/notifier/mail.rb +24 -26
  51. data/lib/backup/notifier/presently.rb +10 -18
  52. data/lib/backup/notifier/prowl.rb +9 -17
  53. data/lib/backup/notifier/twitter.rb +11 -18
  54. data/lib/backup/package.rb +47 -0
  55. data/lib/backup/packager.rb +81 -16
  56. data/lib/backup/splitter.rb +48 -35
  57. data/lib/backup/storage/base.rb +44 -172
  58. data/lib/backup/storage/cloudfiles.rb +31 -46
  59. data/lib/backup/storage/cycler.rb +117 -0
  60. data/lib/backup/storage/dropbox.rb +92 -76
  61. data/lib/backup/storage/ftp.rb +30 -40
  62. data/lib/backup/storage/local.rb +44 -45
  63. data/lib/backup/storage/ninefold.rb +55 -49
  64. data/lib/backup/storage/rsync.rb +49 -56
  65. data/lib/backup/storage/s3.rb +33 -44
  66. data/lib/backup/storage/scp.rb +21 -48
  67. data/lib/backup/storage/sftp.rb +26 -40
  68. data/lib/backup/syncer/base.rb +7 -0
  69. data/lib/backup/syncer/rsync/base.rb +78 -0
  70. data/lib/backup/syncer/rsync/local.rb +53 -0
  71. data/lib/backup/syncer/rsync/pull.rb +38 -0
  72. data/lib/backup/syncer/rsync/push.rb +113 -0
  73. data/lib/backup/syncer/s3.rb +42 -32
  74. data/lib/backup/version.rb +1 -1
  75. data/spec/archive_spec.rb +235 -69
  76. data/spec/cleaner_spec.rb +304 -0
  77. data/spec/cli/helpers_spec.rb +142 -1
  78. data/spec/cli/utility_spec.rb +338 -13
  79. data/spec/compressor/base_spec.rb +31 -0
  80. data/spec/compressor/bzip2_spec.rb +60 -35
  81. data/spec/compressor/gzip_spec.rb +60 -35
  82. data/spec/compressor/lzma_spec.rb +60 -35
  83. data/spec/compressor/pbzip2_spec.rb +98 -37
  84. data/spec/config_spec.rb +321 -0
  85. data/spec/configuration/base_spec.rb +4 -4
  86. data/spec/configuration/compressor/bzip2_spec.rb +1 -0
  87. data/spec/configuration/compressor/gzip_spec.rb +1 -0
  88. data/spec/configuration/compressor/lzma_spec.rb +1 -0
  89. data/spec/configuration/compressor/pbzip2_spec.rb +32 -0
  90. data/spec/configuration/database/base_spec.rb +2 -1
  91. data/spec/configuration/database/mongodb_spec.rb +26 -16
  92. data/spec/configuration/database/mysql_spec.rb +4 -0
  93. data/spec/configuration/database/postgresql_spec.rb +4 -0
  94. data/spec/configuration/database/redis_spec.rb +4 -0
  95. data/spec/configuration/database/riak_spec.rb +4 -0
  96. data/spec/configuration/encryptor/gpg_spec.rb +1 -0
  97. data/spec/configuration/encryptor/open_ssl_spec.rb +1 -0
  98. data/spec/configuration/notifier/base_spec.rb +32 -0
  99. data/spec/configuration/notifier/campfire_spec.rb +1 -0
  100. data/spec/configuration/notifier/hipchat_spec.rb +1 -0
  101. data/spec/configuration/notifier/mail_spec.rb +1 -0
  102. data/spec/configuration/notifier/presently_spec.rb +1 -0
  103. data/spec/configuration/notifier/prowl_spec.rb +1 -0
  104. data/spec/configuration/notifier/twitter_spec.rb +1 -0
  105. data/spec/configuration/storage/cloudfiles_spec.rb +1 -0
  106. data/spec/configuration/storage/dropbox_spec.rb +4 -3
  107. data/spec/configuration/storage/ftp_spec.rb +1 -0
  108. data/spec/configuration/storage/local_spec.rb +1 -0
  109. data/spec/configuration/storage/ninefold_spec.rb +1 -0
  110. data/spec/configuration/storage/rsync_spec.rb +3 -1
  111. data/spec/configuration/storage/s3_spec.rb +1 -0
  112. data/spec/configuration/storage/scp_spec.rb +1 -0
  113. data/spec/configuration/storage/sftp_spec.rb +1 -0
  114. data/spec/configuration/syncer/rsync/base_spec.rb +33 -0
  115. data/spec/configuration/syncer/rsync/local_spec.rb +10 -0
  116. data/spec/configuration/syncer/rsync/pull_spec.rb +10 -0
  117. data/spec/configuration/syncer/{rsync_spec.rb → rsync/push_spec.rb} +12 -15
  118. data/spec/configuration/syncer/s3_spec.rb +2 -3
  119. data/spec/database/base_spec.rb +35 -20
  120. data/spec/database/mongodb_spec.rb +298 -119
  121. data/spec/database/mysql_spec.rb +147 -72
  122. data/spec/database/postgresql_spec.rb +155 -100
  123. data/spec/database/redis_spec.rb +200 -97
  124. data/spec/database/riak_spec.rb +82 -24
  125. data/spec/dependency_spec.rb +49 -0
  126. data/spec/encryptor/base_spec.rb +30 -0
  127. data/spec/encryptor/gpg_spec.rb +105 -28
  128. data/spec/encryptor/open_ssl_spec.rb +85 -114
  129. data/spec/logger_spec.rb +74 -8
  130. data/spec/model_spec.rb +528 -220
  131. data/spec/notifier/base_spec.rb +89 -0
  132. data/spec/notifier/campfire_spec.rb +147 -119
  133. data/spec/notifier/hipchat_spec.rb +140 -145
  134. data/spec/notifier/mail_spec.rb +190 -248
  135. data/spec/notifier/presently_spec.rb +147 -282
  136. data/spec/notifier/prowl_spec.rb +79 -111
  137. data/spec/notifier/twitter_spec.rb +87 -106
  138. data/spec/package_spec.rb +61 -0
  139. data/spec/packager_spec.rb +154 -0
  140. data/spec/spec_helper.rb +36 -13
  141. data/spec/splitter_spec.rb +90 -41
  142. data/spec/storage/base_spec.rb +95 -239
  143. data/spec/storage/cloudfiles_spec.rb +185 -75
  144. data/spec/storage/cycler_spec.rb +239 -0
  145. data/spec/storage/dropbox_spec.rb +318 -87
  146. data/spec/storage/ftp_spec.rb +165 -152
  147. data/spec/storage/local_spec.rb +206 -54
  148. data/spec/storage/ninefold_spec.rb +264 -128
  149. data/spec/storage/rsync_spec.rb +244 -163
  150. data/spec/storage/s3_spec.rb +175 -64
  151. data/spec/storage/scp_spec.rb +156 -150
  152. data/spec/storage/sftp_spec.rb +153 -135
  153. data/spec/syncer/base_spec.rb +22 -0
  154. data/spec/syncer/rsync/base_spec.rb +118 -0
  155. data/spec/syncer/rsync/local_spec.rb +121 -0
  156. data/spec/syncer/rsync/pull_spec.rb +90 -0
  157. data/spec/syncer/rsync/push_spec.rb +327 -0
  158. data/spec/syncer/s3_spec.rb +180 -91
  159. data/templates/cli/utility/config +1 -1
  160. data/templates/cli/utility/database/mongodb +4 -0
  161. data/templates/cli/utility/database/mysql +3 -0
  162. data/templates/cli/utility/database/postgresql +3 -0
  163. data/templates/cli/utility/database/redis +3 -0
  164. data/templates/cli/utility/database/riak +3 -0
  165. data/templates/cli/utility/storage/dropbox +4 -1
  166. data/templates/cli/utility/syncer/rsync_local +12 -0
  167. data/templates/cli/utility/syncer/{rsync → rsync_pull} +2 -2
  168. data/templates/cli/utility/syncer/rsync_push +17 -0
  169. data/templates/storage/dropbox/authorization_url.erb +1 -1
  170. metadata +42 -17
  171. data/lib/backup/configuration/syncer/rsync.rb +0 -45
  172. data/lib/backup/finder.rb +0 -87
  173. data/lib/backup/storage/object.rb +0 -47
  174. data/lib/backup/syncer/rsync.rb +0 -152
  175. data/spec/backup_spec.rb +0 -11
  176. data/spec/finder_spec.rb +0 -91
  177. data/spec/storage/object_spec.rb +0 -74
  178. data/spec/syncer/rsync_spec.rb +0 -195
@@ -3,197 +3,215 @@
3
3
  require File.expand_path('../../spec_helper.rb', __FILE__)
4
4
 
5
5
  describe Backup::Storage::SFTP do
6
-
7
- let(:sftp) do
8
- Backup::Storage::SFTP.new do |sftp|
6
+ let(:model) { Backup::Model.new(:test_trigger, 'test label') }
7
+ let(:storage) do
8
+ Backup::Storage::SFTP.new(model) do |sftp|
9
9
  sftp.username = 'my_username'
10
10
  sftp.password = 'my_password'
11
11
  sftp.ip = '123.45.678.90'
12
- sftp.port = 22
13
- sftp.path = '~/backups/'
14
- sftp.keep = 20
12
+ sftp.keep = 5
15
13
  end
16
14
  end
17
15
 
18
- before do
19
- Backup::Configuration::Storage::SFTP.clear_defaults!
20
- end
16
+ describe '#initialize' do
17
+ it 'should set the correct values' do
18
+ storage.username.should == 'my_username'
19
+ storage.password.should == 'my_password'
20
+ storage.ip.should == '123.45.678.90'
21
+ storage.port.should == 22
22
+ storage.path.should == 'backups'
21
23
 
22
- it 'should have defined the configuration properly' do
23
- sftp.username.should == 'my_username'
24
- sftp.password.should == 'my_password'
25
- sftp.ip.should == '123.45.678.90'
26
- sftp.port.should == 22
27
- sftp.path.should == 'backups/'
28
- sftp.keep.should == 20
29
- end
24
+ storage.storage_id.should be_nil
25
+ storage.keep.should == 5
26
+ end
30
27
 
31
- it 'should use the defaults if a particular attribute has not been defined' do
32
- Backup::Configuration::Storage::SFTP.defaults do |sftp|
33
- sftp.username = 'my_default_username'
34
- sftp.password = 'my_default_password'
35
- sftp.path = '~/backups'
28
+ it 'should set a storage_id if given' do
29
+ sftp = Backup::Storage::SFTP.new(model, 'my storage_id')
30
+ sftp.storage_id.should == 'my storage_id'
36
31
  end
37
32
 
38
- sftp = Backup::Storage::SFTP.new do |sftp|
39
- sftp.password = 'my_password'
40
- sftp.ip = '123.45.678.90'
33
+ it 'should remove any preceeding tilde and slash from the path' do
34
+ storage = Backup::Storage::SFTP.new(model) do |sftp|
35
+ sftp.path = '~/my_backups/path'
36
+ end
37
+ storage.path.should == 'my_backups/path'
41
38
  end
42
39
 
43
- sftp.username.should == 'my_default_username'
44
- sftp.password.should == 'my_password'
45
- sftp.ip.should == '123.45.678.90'
46
- sftp.port.should == 22
47
- end
40
+ context 'when setting configuration defaults' do
41
+ after { Backup::Configuration::Storage::SFTP.clear_defaults! }
42
+
43
+ it 'should use the configured defaults' do
44
+ Backup::Configuration::Storage::SFTP.defaults do |sftp|
45
+ sftp.username = 'some_username'
46
+ sftp.password = 'some_password'
47
+ sftp.ip = 'some_ip'
48
+ sftp.port = 'some_port'
49
+ sftp.path = 'some_path'
50
+ sftp.keep = 'some_keep'
51
+ end
52
+ storage = Backup::Storage::SFTP.new(model)
53
+ storage.username.should == 'some_username'
54
+ storage.password.should == 'some_password'
55
+ storage.ip.should == 'some_ip'
56
+ storage.port.should == 'some_port'
57
+ storage.path.should == 'some_path'
58
+
59
+ storage.storage_id.should be_nil
60
+ storage.keep.should == 'some_keep'
61
+ end
48
62
 
49
- it 'should have its own defaults' do
50
- sftp = Backup::Storage::SFTP.new
51
- sftp.port.should == 22
52
- sftp.path.should == 'backups'
53
- end
63
+ it 'should override the configured defaults' do
64
+ Backup::Configuration::Storage::SFTP.defaults do |sftp|
65
+ sftp.username = 'old_username'
66
+ sftp.password = 'old_password'
67
+ sftp.ip = 'old_ip'
68
+ sftp.port = 'old_port'
69
+ sftp.path = 'old_path'
70
+ sftp.keep = 'old_keep'
71
+ end
72
+ storage = Backup::Storage::SFTP.new(model) do |sftp|
73
+ sftp.username = 'new_username'
74
+ sftp.password = 'new_password'
75
+ sftp.ip = 'new_ip'
76
+ sftp.port = 'new_port'
77
+ sftp.path = 'new_path'
78
+ sftp.keep = 'new_keep'
79
+ end
80
+
81
+ storage.username.should == 'new_username'
82
+ storage.password.should == 'new_password'
83
+ storage.ip.should == 'new_ip'
84
+ storage.port.should == 'new_port'
85
+ storage.path.should == 'new_path'
86
+
87
+ storage.storage_id.should be_nil
88
+ storage.keep.should == 'new_keep'
89
+ end
90
+ end # context 'when setting configuration defaults'
54
91
 
55
- describe '#perform' do
56
- it 'should invoke transfer! and cycle!' do
57
- sftp.expects(:transfer!)
58
- sftp.expects(:cycle!)
59
- sftp.perform!
60
- end
61
- end
92
+ end # describe '#initialize'
62
93
 
63
94
  describe '#connection' do
64
- it 'should establish a connection to the remote server' do
65
- connection = mock
95
+ let(:connection) { mock }
96
+
97
+ it 'should yield a connection to the remote server' do
66
98
  Net::SFTP.expects(:start).with(
67
- '123.45.678.90',
68
- 'my_username',
69
- :password => 'my_password',
70
- :port => 22
99
+ '123.45.678.90', 'my_username', :password => 'my_password', :port => 22
71
100
  ).yields(connection)
72
101
 
73
- sftp.send(:connection) do |conn|
74
- conn.should be connection
102
+ storage.send(:connection) do |sftp|
103
+ sftp.should be(connection)
75
104
  end
76
105
  end
77
- end # describe '#connection'
106
+ end
78
107
 
79
108
  describe '#transfer!' do
80
109
  let(:connection) { mock }
110
+ let(:package) { mock }
111
+ let(:s) { sequence '' }
81
112
 
82
113
  before do
83
- sftp.stubs(:storage_name).returns('Storage::SFTP')
114
+ storage.instance_variable_set(:@package, package)
115
+ storage.stubs(:storage_name).returns('Storage::SFTP')
116
+ storage.stubs(:local_path).returns('/local/path')
117
+ storage.stubs(:connection).yields(connection)
84
118
  end
85
119
 
86
- context 'when file chunking is not used' do
87
- it 'should create remote paths and transfer using a single connection' do
88
- local_file = "#{ Backup::TIME }.#{ Backup::TRIGGER }.tar"
89
- remote_file = "#{ Backup::TRIGGER }.tar"
90
-
91
- sftp.expects(:connection).yields(connection)
92
- sftp.expects(:create_remote_directories).with(connection)
93
-
94
- Backup::Logger.expects(:message).with(
95
- "Storage::SFTP started transferring '#{local_file}' to '#{sftp.ip}'."
96
- )
97
-
98
- connection.expects(:upload!).with(
99
- File.join(Backup::TMP_PATH, local_file),
100
- File.join('backups/myapp', Backup::TIME, remote_file)
101
- )
120
+ it 'should transfer the package files' do
121
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
122
+ returns('remote/path')
123
+ storage.expects(:create_remote_path).in_sequence(s).with(
124
+ 'remote/path', connection
125
+ )
102
126
 
103
- sftp.send(:transfer!)
104
- end
105
- end
127
+ storage.expects(:files_to_transfer_for).in_sequence(s).with(package).
128
+ multiple_yields(
129
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
130
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
131
+ )
132
+ # first yield
133
+ Backup::Logger.expects(:message).in_sequence(s).with(
134
+ "Storage::SFTP started transferring " +
135
+ "'2011.12.31.11.00.02.backup.tar.enc-aa' to '123.45.678.90'."
136
+ )
137
+ connection.expects(:upload!).in_sequence(s).with(
138
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-aa'),
139
+ File.join('remote/path', 'backup.tar.enc-aa')
140
+ )
141
+ # second yield
142
+ Backup::Logger.expects(:message).in_sequence(s).with(
143
+ "Storage::SFTP started transferring " +
144
+ "'2011.12.31.11.00.02.backup.tar.enc-ab' to '123.45.678.90'."
145
+ )
146
+ connection.expects(:upload!).in_sequence(s).with(
147
+ File.join('/local/path', '2011.12.31.11.00.02.backup.tar.enc-ab'),
148
+ File.join('remote/path', 'backup.tar.enc-ab')
149
+ )
106
150
 
107
- context 'when file chunking is used' do
108
- it 'should transfer all the provided files using a single connection' do
109
- s = sequence ''
110
-
111
- sftp.expects(:connection).in_sequence(s).yields(connection)
112
- sftp.expects(:create_remote_directories).in_sequence(s).with(connection)
113
-
114
- sftp.expects(:files_to_transfer).in_sequence(s).multiple_yields(
115
- ['local_file1', 'remote_file1'], ['local_file2', 'remote_file2']
116
- )
117
-
118
- Backup::Logger.expects(:message).in_sequence(s).with(
119
- "Storage::SFTP started transferring 'local_file1' to '#{sftp.ip}'."
120
- )
121
- connection.expects(:upload!).in_sequence(s).with(
122
- File.join(Backup::TMP_PATH, 'local_file1'),
123
- File.join('backups/myapp', Backup::TIME, 'remote_file1')
124
- )
125
-
126
- Backup::Logger.expects(:message).in_sequence(s).with(
127
- "Storage::SFTP started transferring 'local_file2' to '#{sftp.ip}'."
128
- )
129
- connection.expects(:upload!).in_sequence(s).with(
130
- File.join(Backup::TMP_PATH, 'local_file2'),
131
- File.join('backups/myapp', Backup::TIME, 'remote_file2')
132
- )
133
-
134
- sftp.send(:transfer!)
135
- end
151
+ storage.send(:transfer!)
136
152
  end
137
- end # describe '#transfer'
153
+ end # describe '#transfer!'
138
154
 
139
155
  describe '#remove!' do
140
- it 'should remove all remote files with a single FTP connection' do
141
- s = sequence ''
142
- connection = mock
143
- remote_path = "backups/myapp/#{ Backup::TIME }"
144
- sftp.stubs(:storage_name).returns('Storage::SFTP')
156
+ let(:package) { mock }
157
+ let(:connection) { mock }
158
+ let(:s) { sequence '' }
145
159
 
146
- sftp.expects(:connection).in_sequence(s).yields(connection)
160
+ before do
161
+ storage.stubs(:storage_name).returns('Storage::SFTP')
162
+ storage.stubs(:connection).yields(connection)
163
+ end
147
164
 
148
- sftp.expects(:transferred_files).in_sequence(s).multiple_yields(
149
- ['local_file1', 'remote_file1'], ['local_file2', 'remote_file2']
150
- )
165
+ it 'should remove the package files' do
166
+ storage.expects(:remote_path_for).in_sequence(s).with(package).
167
+ returns('remote/path')
151
168
 
169
+ storage.expects(:transferred_files_for).in_sequence(s).with(package).
170
+ multiple_yields(
171
+ ['2011.12.31.11.00.02.backup.tar.enc-aa', 'backup.tar.enc-aa'],
172
+ ['2011.12.31.11.00.02.backup.tar.enc-ab', 'backup.tar.enc-ab']
173
+ )
174
+ # first yield
152
175
  Backup::Logger.expects(:message).in_sequence(s).with(
153
- "Storage::SFTP started removing 'local_file1' from '#{sftp.ip}'."
176
+ "Storage::SFTP started removing " +
177
+ "'2011.12.31.11.00.02.backup.tar.enc-aa' from '123.45.678.90'."
154
178
  )
155
179
  connection.expects(:remove!).in_sequence(s).with(
156
- File.join(remote_path, 'remote_file1')
180
+ File.join('remote/path', 'backup.tar.enc-aa')
157
181
  )
158
-
182
+ # second yield
159
183
  Backup::Logger.expects(:message).in_sequence(s).with(
160
- "Storage::SFTP started removing 'local_file2' from '#{sftp.ip}'."
184
+ "Storage::SFTP started removing " +
185
+ "'2011.12.31.11.00.02.backup.tar.enc-ab' from '123.45.678.90'."
161
186
  )
162
187
  connection.expects(:remove!).in_sequence(s).with(
163
- File.join(remote_path, 'remote_file2')
188
+ File.join('remote/path', 'backup.tar.enc-ab')
164
189
  )
165
190
 
166
- connection.expects(:rmdir!).in_sequence(s).with(remote_path)
191
+ connection.expects(:rmdir!).with('remote/path').in_sequence(s)
167
192
 
168
- sftp.send(:remove!)
193
+ storage.send(:remove!, package)
169
194
  end
170
195
  end # describe '#remove!'
171
196
 
172
- describe '#create_remote_directories' do
173
- let(:connection) { mock }
197
+ describe '#create_remote_path' do
198
+ let(:connection) { mock }
199
+ let(:remote_path) { 'backups/folder/another_folder' }
200
+ let(:s) { sequence '' }
201
+ let(:sftp_response) { stub(:code => 11, :message => nil) }
202
+ let(:sftp_status_exception) { Net::SFTP::StatusException.new(sftp_response) }
174
203
 
175
204
  context 'while properly creating remote directories one by one' do
176
- it 'should rescue any SFTP::StatusExceptions' do
177
- s = sequence ''
178
- sftp.path = '~/backups/some_other_folder/another_folder'
179
- sftp_response = stub(:code => 11, :message => nil)
180
- sftp_status_exception = Net::SFTP::StatusException.new(sftp_response)
181
-
182
- connection.expects(:mkdir!).in_sequence(s).
183
- with("~").raises(sftp_status_exception)
184
- connection.expects(:mkdir!).in_sequence(s).
185
- with("~/backups").raises(sftp_status_exception)
186
- connection.expects(:mkdir!).in_sequence(s).
187
- with("~/backups/some_other_folder")
205
+ it 'should rescue any SFTP::StatusException and continue' do
188
206
  connection.expects(:mkdir!).in_sequence(s).
189
- with("~/backups/some_other_folder/another_folder")
207
+ with("backups").raises(sftp_status_exception)
190
208
  connection.expects(:mkdir!).in_sequence(s).
191
- with("~/backups/some_other_folder/another_folder/myapp")
209
+ with("backups/folder")
192
210
  connection.expects(:mkdir!).in_sequence(s).
193
- with("~/backups/some_other_folder/another_folder/myapp/#{ Backup::TIME }")
211
+ with("backups/folder/another_folder")
194
212
 
195
213
  expect do
196
- sftp.send(:create_remote_directories, connection)
214
+ storage.send(:create_remote_path, remote_path, connection)
197
215
  end.not_to raise_error
198
216
  end
199
217
  end
@@ -0,0 +1,22 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Syncer::Base do
6
+ let(:base) { Backup::Syncer::Base }
7
+ let(:syncer) { base.new }
8
+
9
+ it 'should include CLI::Helpers' do
10
+ base.included_modules.should include(Backup::CLI::Helpers)
11
+ end
12
+
13
+ it 'should include Configuration::Helpers' do
14
+ base.included_modules.should include(Backup::Configuration::Helpers)
15
+ end
16
+
17
+ describe '#syncer_name' do
18
+ it 'should return the class name with the Backup:: namespace removed' do
19
+ syncer.send(:syncer_name).should == 'Syncer::Base'
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,118 @@
1
+ # encoding: utf-8
2
+
3
+ require File.expand_path('../../../spec_helper.rb', __FILE__)
4
+
5
+ describe Backup::Syncer::RSync::Base do
6
+ let(:syncer) { Backup::Syncer::RSync::Base.new }
7
+
8
+ describe '#initialize' do
9
+
10
+ it 'should use default values' do
11
+ syncer.path.should == 'backups'
12
+ syncer.directories.should == []
13
+ syncer.mirror.should == false
14
+ syncer.additional_options.should == []
15
+ end
16
+
17
+ context 'when setting configuration defaults' do
18
+ after { Backup::Configuration::Syncer::RSync::Base.clear_defaults! }
19
+
20
+ it 'should use the configured defaults' do
21
+ Backup::Configuration::Syncer::RSync::Base.defaults do |rsync|
22
+ rsync.path = 'some_path'
23
+ #rsync.directories = 'cannot_have_a_default_value'
24
+ rsync.mirror = 'some_mirror'
25
+ rsync.additional_options = 'some_additional_options'
26
+ end
27
+ syncer = Backup::Syncer::RSync::Base.new
28
+ syncer.path.should == 'some_path'
29
+ syncer.directories.should == []
30
+ syncer.mirror.should == 'some_mirror'
31
+ syncer.additional_options.should == 'some_additional_options'
32
+ end
33
+ end
34
+
35
+ end # describe '#initialize'
36
+
37
+ describe '#directories' do
38
+ before do
39
+ syncer.directories = ['/some/directory', '/another/directory']
40
+ end
41
+
42
+ context 'when no block is given' do
43
+ it 'should return @directories' do
44
+ syncer.directories.should ==
45
+ ['/some/directory', '/another/directory']
46
+ end
47
+ end
48
+
49
+ context 'when a block is given' do
50
+ it 'should evalute the block, allowing #add to add directories' do
51
+ syncer.directories do
52
+ add '/new/path'
53
+ add '/another/new/path'
54
+ end
55
+ syncer.directories.should == [
56
+ '/some/directory',
57
+ '/another/directory',
58
+ '/new/path',
59
+ '/another/new/path'
60
+ ]
61
+ end
62
+ end
63
+ end # describe '#directories'
64
+
65
+ describe '#add' do
66
+ before do
67
+ syncer.directories = ['/some/directory', '/another/directory']
68
+ end
69
+
70
+ it 'should add the given path to @directories' do
71
+ syncer.add '/my/path'
72
+ syncer.directories.should ==
73
+ ['/some/directory', '/another/directory', '/my/path']
74
+ end
75
+ end
76
+
77
+ describe '#directory_options' do
78
+ before do
79
+ syncer.directories = ['/some/directory', '/another/directory']
80
+ end
81
+
82
+ it 'should return the directories for use in the command line' do
83
+ syncer.send(:directories_option).should ==
84
+ "'/some/directory' '/another/directory'"
85
+ end
86
+
87
+ it 'should expand relative paths' do
88
+ syncer.directories += ['relative/path', '~/home/path']
89
+ syncer.send(:directories_option).should ==
90
+ "'/some/directory' '/another/directory' " +
91
+ "'#{ File.expand_path('relative/path') }' " +
92
+ "'#{ File.expand_path('~/home/path') }'"
93
+ end
94
+ end
95
+
96
+ describe '#mirror_option' do
97
+ context 'when @mirror is true' do
98
+ before { syncer.mirror = true }
99
+ it 'should return the command line flag for mirroring' do
100
+ syncer.send(:mirror_option).should == '--delete'
101
+ end
102
+ end
103
+
104
+ context 'when @mirror is false' do
105
+ before { syncer.mirror = false }
106
+ it 'should return nil' do
107
+ syncer.send(:mirror_option).should be_nil
108
+ end
109
+ end
110
+ end
111
+
112
+ describe '#archive_option' do
113
+ it 'should return the command line flag for archiving' do
114
+ syncer.send(:archive_option).should == '--archive'
115
+ end
116
+ end
117
+
118
+ end