data-exporter 1.3.7

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,259 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataExporter::Configuration do
4
+ let(:instance) { DataExporter::Configuration.new }
5
+
6
+ describe '#load' do
7
+ let(:config_path) { Dir.mktmpdir('data_export') }
8
+ let(:export_dir) { Dir.mktmpdir('data_export') }
9
+ let(:download_dir) { Dir.mktmpdir('data_download') }
10
+ let(:unpack_dir) { Dir.mktmpdir('data_unpack') }
11
+ let(:backup_dir) { Dir.mktmpdir('data_export') }
12
+ let(:unpack_dir) { Dir.mktmpdir('data_export') }
13
+ let(:backup_key) { File.expand_path('../fixtures/backup_key', __FILE__) }
14
+ let(:backup_prefix) { 'data_export' }
15
+ let(:archive_base_directory) { 'data_exporter' }
16
+ let(:mysqldump_path) { '/opt/local/bin/mysqldump5' }
17
+ let(:mysqldump_options) { '' }
18
+
19
+ let(:mysql_config) do
20
+ {
21
+ adapter: 'mysql2',
22
+ host: 'localhost',
23
+ database: 'centurion_test',
24
+ username: 'root'
25
+ }
26
+ end
27
+
28
+ let(:s3_config) do
29
+ {
30
+ access_key_id: 'spec',
31
+ secret_access_key: 'spec',
32
+ bucket_name: 'spec',
33
+ prefix: backup_prefix
34
+ }
35
+ end
36
+
37
+ let(:redis_config) do
38
+ {
39
+ host: 'localhost',
40
+ port: 6379
41
+ }
42
+ end
43
+
44
+ let(:sftp_config) { {} }
45
+
46
+ let(:config_hash) do
47
+ {
48
+ export_dir: export_dir,
49
+ download_dir: download_dir,
50
+ unpack_dir: unpack_dir,
51
+ backup_dir: backup_dir,
52
+ backup_key: backup_key,
53
+ mysqldump_path: mysqldump_path,
54
+ mysqldump_options: mysqldump_options,
55
+ mysql: mysql_config,
56
+ s3: s3_config,
57
+ redis: redis_config,
58
+ sftp: sftp_config
59
+ }
60
+ end
61
+
62
+ let(:config_yaml) { config_hash.to_yaml }
63
+
64
+ let(:config_file) do
65
+ File.join(config_path, 'config_file').tap do |config_file|
66
+ File.open(config_file, 'w') do |file|
67
+ file.write config_yaml
68
+ file.close
69
+ end
70
+ end
71
+ end
72
+
73
+ let(:options) { {config_file: config_file} }
74
+
75
+ subject do
76
+ instance.load(options)
77
+ end
78
+
79
+ shared_context 'a configuration' do
80
+ describe '#export_dir' do
81
+ subject { super().export_dir }
82
+ it { is_expected.to eq(export_dir) }
83
+ end
84
+
85
+ describe '#download_dir' do
86
+ subject { super().download_dir }
87
+ it { is_expected.to eq(download_dir) }
88
+ end
89
+
90
+ describe '#unpack_dir' do
91
+ subject { super().unpack_dir }
92
+ it { is_expected.to eq(unpack_dir) }
93
+ end
94
+
95
+ describe '#backup_dir' do
96
+ subject { super().backup_dir }
97
+ it { is_expected.to eq(backup_dir) }
98
+ end
99
+
100
+ describe '#backup_key' do
101
+ subject { super().backup_key }
102
+ it { is_expected.to eq(backup_key) }
103
+ end
104
+
105
+ describe '#backup_prefix' do
106
+ subject { super().backup_prefix }
107
+ it { is_expected.to eq(backup_prefix) }
108
+ end
109
+
110
+ describe '#database' do
111
+ subject { super().database }
112
+ it { is_expected.to include(mysql_config) }
113
+ end
114
+
115
+ describe '#mysql' do
116
+ subject { super().mysql }
117
+ it { is_expected.to include(mysql_config) }
118
+ end
119
+
120
+ describe '#s3' do
121
+ subject { super().s3 }
122
+ it { is_expected.to include(bucket: 'spec', access_key_id: 'spec', secret_access_key: 'spec') }
123
+ end
124
+
125
+ describe '#mysqldump_path' do
126
+ subject { super().mysqldump_path }
127
+ it { is_expected.to eq(mysqldump_path) }
128
+ end
129
+
130
+ describe '#mysqldump_options' do
131
+ subject { super().mysqldump_options }
132
+ it { is_expected.to be_empty }
133
+ end
134
+
135
+ describe '#redis' do
136
+ subject { super().redis }
137
+ it { is_expected.to include redis_config }
138
+ end
139
+ end
140
+
141
+ it_behaves_like 'a configuration'
142
+
143
+ context 'with configuraiton provided by STDIN' do
144
+ let(:config_file) { '-' }
145
+ before do
146
+ expect(STDIN).to receive(:read).and_return(config_hash.to_yaml)
147
+ end
148
+ it_behaves_like 'a configuration'
149
+ end
150
+
151
+ context 'with relative backup_key' do
152
+ let(:backup_key) { 'backup_key' }
153
+
154
+ describe '#backup_key' do
155
+ subject { super().backup_key }
156
+ it { is_expected.to eq(File.join(config_path, backup_key)) }
157
+ end
158
+ end
159
+
160
+ context 'with alternative backup_prefix' do
161
+ before do
162
+ config_hash.merge(:backup_prefix => backup_prefix)
163
+ end
164
+
165
+ describe '#backup_prefix' do
166
+ subject { super().backup_prefix }
167
+ it { is_expected.to eq(backup_prefix) }
168
+ end
169
+ end
170
+
171
+ context 'when bucket has s3:// prefix' do
172
+ before do
173
+ config_hash[:s3].merge!(:bucket_name => 's3://fqbn')
174
+ end
175
+
176
+ describe '#s3' do
177
+ subject { super().s3 }
178
+ it { is_expected.to include(bucket: 'fqbn') }
179
+ end
180
+ end
181
+
182
+ context 'with default options and no s3 configuration' do
183
+ let(:options) { {config_file: config_file} }
184
+ let(:s3_config) { {} }
185
+
186
+ it { expect { subject }.to raise_error(/missing s3 section/) }
187
+ end
188
+
189
+ context 'with default options and no mysql configuration' do
190
+ let(:options) { {config_file: config_file} }
191
+ let(:mysql_config) { {} }
192
+
193
+ it { expect { subject }.to_not raise_error }
194
+ end
195
+
196
+ context 'with mysql_required=true option and no mysql configuration' do
197
+ let(:options) { {config_file: config_file, mysql_required: true} }
198
+ let(:mysql_config) { {} }
199
+
200
+ it { expect { subject }.to raise_error(/missing mysql section/) }
201
+ end
202
+
203
+ context 'with mysql_required=false option and no mysql configuration' do
204
+ let(:options) { {config_file: config_file, mysql_required: false} }
205
+ let(:mysql_config) { {} }
206
+
207
+ it { expect { subject }.to_not raise_error }
208
+ end
209
+
210
+ context 'with redis_key_prefix option and no redis configuration' do
211
+ let(:options) { {config_file: config_file, redis_key_prefix: 'data_exporter_prefix'} }
212
+ let(:redis_config) { {} }
213
+
214
+ it { expect { subject }.to raise_error }
215
+ end
216
+
217
+ context 'with sftp configuration' do
218
+ let(:sftp_config) do
219
+ {
220
+ host: 'localhost',
221
+ user: 'eventrobot'
222
+ }
223
+ end
224
+
225
+ let(:options) { {config_file: config_file} }
226
+
227
+ describe '#sftp_enabled?' do
228
+ subject { super().sftp_enabled? }
229
+ it { is_expected.to be_truthy }
230
+ end
231
+
232
+ describe '#sftp' do
233
+ subject { super().sftp }
234
+ it { is_expected.to include(host: 'localhost', user: 'eventrobot') }
235
+ end
236
+ end
237
+
238
+ context 'with mysqldump_options' do
239
+ let(:mysqldump_options) { '--single-transaction --master-data=2' }
240
+
241
+ describe '#mysqldump_options' do
242
+ subject { super().mysqldump_options }
243
+ it { is_expected.to eq(['--single-transaction', '--master-data=2']) }
244
+ end
245
+ end
246
+
247
+ context 'with configuration modes' do
248
+ let(:config_yaml) { { :default => config_hash }.to_yaml }
249
+ it_behaves_like 'a configuration'
250
+ end
251
+
252
+ context 'with configuration modes and --mode option' do
253
+ let(:config_yaml) { { :default => {}, :other => config_hash }.to_yaml }
254
+ let(:options) { {config_file: config_file, mode: 'other'} }
255
+ it_behaves_like 'a configuration'
256
+ end
257
+ end
258
+ end
259
+
@@ -0,0 +1,5 @@
1
+ require 'spec_helper'
2
+
3
+ describe DataExporter do
4
+ it { is_expected.to be_a(Module) }
5
+ end
@@ -0,0 +1 @@
1
+ spec
@@ -0,0 +1,13 @@
1
+ require 'bundler/setup'
2
+ Bundler.require(:default, :development, :test)
3
+ require 'data_exporter'
4
+ require 'tempfile'
5
+ require 'tmpdir'
6
+
7
+ Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
8
+
9
+ RSpec.configure do |config|
10
+ config.include SeedData
11
+ config.mock_with :rspec
12
+ end
13
+
@@ -0,0 +1,41 @@
1
+ class User < ActiveRecord::Base; end
2
+
3
+ module SeedData
4
+ def self.included(base)
5
+ base.before :all do
6
+ DataExporter.configure do |config|
7
+ config.database = {
8
+ adapter: 'mysql2',
9
+ host: 'localhost',
10
+ database: 'centurion_test',
11
+ username: 'root'
12
+ }
13
+ end
14
+
15
+ DataExporter.database_connection
16
+
17
+ ActiveRecord::Migration.suppress_messages do
18
+ ActiveRecord::Schema.define do
19
+ create_table :users, :force => true do |table|
20
+ table.column :username, :string
21
+ table.column :first_name, :string
22
+ table.column :last_name, :string
23
+ table.column :email, :string
24
+ table.column :created_at, :timestamp
25
+ table.column :updated_at, :timestamp
26
+ end
27
+ end
28
+
29
+ User.create(
30
+ first_name: 'Emily',
31
+ last_name: 'James',
32
+ email: 'emily@socialcast.com')
33
+
34
+ User.create(
35
+ first_name: 'Jennifer',
36
+ last_name: 'Lawson',
37
+ email: 'jennifer@socialcast.com')
38
+ end
39
+ end
40
+ end
41
+ end
metadata ADDED
@@ -0,0 +1,237 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: data-exporter
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.3.7
5
+ platform: ruby
6
+ authors:
7
+ - Michael Andrews
8
+ - Geoff Hichborn
9
+ - Sean Cashin
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2015-06-17 00:00:00.000000000 Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: thor
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - ">="
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - ">="
27
+ - !ruby/object:Gem::Version
28
+ version: '0'
29
+ - !ruby/object:Gem::Dependency
30
+ name: aws-sdk
31
+ requirement: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - "~>"
34
+ - !ruby/object:Gem::Version
35
+ version: '1.64'
36
+ type: :runtime
37
+ prerelease: false
38
+ version_requirements: !ruby/object:Gem::Requirement
39
+ requirements:
40
+ - - "~>"
41
+ - !ruby/object:Gem::Version
42
+ version: '1.64'
43
+ - !ruby/object:Gem::Dependency
44
+ name: archive-tar-minitar
45
+ requirement: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ type: :runtime
51
+ prerelease: false
52
+ version_requirements: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: '0'
57
+ - !ruby/object:Gem::Dependency
58
+ name: net-sftp
59
+ requirement: !ruby/object:Gem::Requirement
60
+ requirements:
61
+ - - ">="
62
+ - !ruby/object:Gem::Version
63
+ version: '0'
64
+ type: :runtime
65
+ prerelease: false
66
+ version_requirements: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ">="
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ - !ruby/object:Gem::Dependency
72
+ name: activesupport
73
+ requirement: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ type: :runtime
79
+ prerelease: false
80
+ version_requirements: !ruby/object:Gem::Requirement
81
+ requirements:
82
+ - - ">="
83
+ - !ruby/object:Gem::Version
84
+ version: '0'
85
+ - !ruby/object:Gem::Dependency
86
+ name: activerecord
87
+ requirement: !ruby/object:Gem::Requirement
88
+ requirements:
89
+ - - ">="
90
+ - !ruby/object:Gem::Version
91
+ version: '0'
92
+ type: :runtime
93
+ prerelease: false
94
+ version_requirements: !ruby/object:Gem::Requirement
95
+ requirements:
96
+ - - ">="
97
+ - !ruby/object:Gem::Version
98
+ version: '0'
99
+ - !ruby/object:Gem::Dependency
100
+ name: mysql2
101
+ requirement: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ type: :development
107
+ prerelease: false
108
+ version_requirements: !ruby/object:Gem::Requirement
109
+ requirements:
110
+ - - ">="
111
+ - !ruby/object:Gem::Version
112
+ version: '0'
113
+ - !ruby/object:Gem::Dependency
114
+ name: redis
115
+ requirement: !ruby/object:Gem::Requirement
116
+ requirements:
117
+ - - ">="
118
+ - !ruby/object:Gem::Version
119
+ version: '0'
120
+ type: :development
121
+ prerelease: false
122
+ version_requirements: !ruby/object:Gem::Requirement
123
+ requirements:
124
+ - - ">="
125
+ - !ruby/object:Gem::Version
126
+ version: '0'
127
+ - !ruby/object:Gem::Dependency
128
+ name: rake
129
+ requirement: !ruby/object:Gem::Requirement
130
+ requirements:
131
+ - - ">="
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ requirements:
138
+ - - ">="
139
+ - !ruby/object:Gem::Version
140
+ version: '0'
141
+ - !ruby/object:Gem::Dependency
142
+ name: rspec
143
+ requirement: !ruby/object:Gem::Requirement
144
+ requirements:
145
+ - - ">"
146
+ - !ruby/object:Gem::Version
147
+ version: '2.99'
148
+ type: :development
149
+ prerelease: false
150
+ version_requirements: !ruby/object:Gem::Requirement
151
+ requirements:
152
+ - - ">"
153
+ - !ruby/object:Gem::Version
154
+ version: '2.99'
155
+ - !ruby/object:Gem::Dependency
156
+ name: timecop
157
+ requirement: !ruby/object:Gem::Requirement
158
+ requirements:
159
+ - - ">="
160
+ - !ruby/object:Gem::Version
161
+ version: '0'
162
+ type: :development
163
+ prerelease: false
164
+ version_requirements: !ruby/object:Gem::Requirement
165
+ requirements:
166
+ - - ">="
167
+ - !ruby/object:Gem::Version
168
+ version: '0'
169
+ - !ruby/object:Gem::Dependency
170
+ name: byebug
171
+ requirement: !ruby/object:Gem::Requirement
172
+ requirements:
173
+ - - ">="
174
+ - !ruby/object:Gem::Version
175
+ version: '0'
176
+ type: :development
177
+ prerelease: false
178
+ version_requirements: !ruby/object:Gem::Requirement
179
+ requirements:
180
+ - - ">="
181
+ - !ruby/object:Gem::Version
182
+ version: '0'
183
+ description: Database Import / Export Tool
184
+ email:
185
+ - michael@socialcast.com
186
+ executables:
187
+ - data-exporter
188
+ extensions: []
189
+ extra_rdoc_files: []
190
+ files:
191
+ - README.md
192
+ - Rakefile
193
+ - bin/data-exporter
194
+ - lib/data_exporter.rb
195
+ - lib/data_exporter/actions.rb
196
+ - lib/data_exporter/archive.rb
197
+ - lib/data_exporter/cli.rb
198
+ - lib/data_exporter/configuration.rb
199
+ - lib/data_exporter/version.rb
200
+ - spec/actions_spec.rb
201
+ - spec/cli_spec.rb
202
+ - spec/configuration_spec.rb
203
+ - spec/data_exporter_spec.rb
204
+ - spec/fixtures/backup_key
205
+ - spec/spec_helper.rb
206
+ - spec/support/seed_data.rb
207
+ homepage: https://github.com/socialcast/data-exporter
208
+ licenses: []
209
+ metadata: {}
210
+ post_install_message:
211
+ rdoc_options: []
212
+ require_paths:
213
+ - lib
214
+ required_ruby_version: !ruby/object:Gem::Requirement
215
+ requirements:
216
+ - - ">="
217
+ - !ruby/object:Gem::Version
218
+ version: '0'
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - - ">="
222
+ - !ruby/object:Gem::Version
223
+ version: '0'
224
+ requirements: []
225
+ rubyforge_project:
226
+ rubygems_version: 2.4.6
227
+ signing_key:
228
+ specification_version: 4
229
+ summary: Database Import / Export Tool
230
+ test_files:
231
+ - spec/actions_spec.rb
232
+ - spec/cli_spec.rb
233
+ - spec/configuration_spec.rb
234
+ - spec/data_exporter_spec.rb
235
+ - spec/fixtures/backup_key
236
+ - spec/spec_helper.rb
237
+ - spec/support/seed_data.rb