aptible-cli 0.6.9 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (35) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +1 -0
  3. data/README.md +1 -1
  4. data/aptible-cli.gemspec +6 -3
  5. data/bin/aptible +3 -1
  6. data/codecov.yml +12 -0
  7. data/lib/aptible/cli/agent.rb +3 -0
  8. data/lib/aptible/cli/helpers/app.rb +98 -33
  9. data/lib/aptible/cli/helpers/database.rb +3 -3
  10. data/lib/aptible/cli/subcommands/apps.rb +4 -3
  11. data/lib/aptible/cli/subcommands/backup.rb +55 -0
  12. data/lib/aptible/cli/subcommands/config.rb +2 -2
  13. data/lib/aptible/cli/subcommands/db.rb +11 -2
  14. data/lib/aptible/cli/subcommands/rebuild.rb +1 -1
  15. data/lib/aptible/cli/subcommands/restart.rb +1 -1
  16. data/lib/aptible/cli/version.rb +1 -1
  17. data/spec/aptible/cli/helpers/git_remote_handle_strategy_spec.rb +54 -0
  18. data/spec/aptible/cli/helpers/{handle_from_git_remote.rb → handle_from_git_remote_spec.rb} +0 -0
  19. data/spec/aptible/cli/helpers/options_handle_strategy_spec.rb +14 -0
  20. data/spec/aptible/cli/helpers/tunnel_spec.rb +0 -1
  21. data/spec/aptible/cli/subcommands/apps_spec.rb +141 -54
  22. data/spec/aptible/cli/subcommands/backup_spec.rb +115 -0
  23. data/spec/aptible/cli/subcommands/db_spec.rb +35 -61
  24. data/spec/aptible/cli/subcommands/domains_spec.rb +21 -38
  25. data/spec/aptible/cli/subcommands/logs_spec.rb +12 -17
  26. data/spec/aptible/cli/subcommands/ps_spec.rb +5 -12
  27. data/spec/fabricators/account_fabricator.rb +10 -0
  28. data/spec/fabricators/app_fabricator.rb +14 -0
  29. data/spec/fabricators/backup_fabricator.rb +10 -0
  30. data/spec/fabricators/database_fabricator.rb +15 -0
  31. data/spec/fabricators/operation_fabricator.rb +6 -0
  32. data/spec/fabricators/service_fabricator.rb +9 -0
  33. data/spec/fabricators/vhost_fabricator.rb +9 -0
  34. data/spec/spec_helper.rb +9 -1
  35. metadata +81 -17
@@ -1,49 +1,39 @@
1
- require 'ostruct'
2
1
  require 'spec_helper'
3
2
 
4
- class App < OpenStruct
5
- end
6
-
7
- class Service < OpenStruct
8
- end
9
-
10
- class Operation < OpenStruct
11
- end
12
-
13
- class Vhost < OpenStruct
14
- end
15
-
16
3
  describe Aptible::CLI::Agent do
17
4
  before { subject.stub(:ask) }
18
5
  before { subject.stub(:save_token) }
19
6
  before { subject.stub(:fetch_token) { double 'token' } }
20
7
 
21
- let(:service) { Service.new(process_type: 'web') }
22
- let(:op) { Operation.new(status: 'succeeded') }
23
- let(:app) { App.new(handle: 'hello', services: [service]) }
24
- let(:apps) { [app] }
25
- let(:account) do
26
- Account.new(bastion_host: 'localhost',
27
- dumptruck_port: 1234,
28
- handle: 'aptible')
8
+ let!(:account) { Fabricate(:account) }
9
+ let!(:app) { Fabricate(:app, handle: 'hello', account: account) }
10
+ let!(:service) { Fabricate(:service, app: app) }
11
+ let(:op) { Fabricate(:operation, status: 'succeeded', resource: app) }
12
+
13
+ before do
14
+ allow(Aptible::Api::App).to receive(:all) { [app] }
15
+ allow(Aptible::Api::Account).to receive(:all) { [account] }
29
16
  end
30
17
 
31
- let(:vhost1) { Vhost.new(virtual_domain: 'domain1', external_host: 'host1') }
32
- let(:vhost2) { Vhost.new(virtual_domain: 'domain2', external_host: 'host2') }
18
+ let!(:vhost1) do
19
+ Fabricate(:vhost, virtual_domain: 'domain1', external_host: 'host1',
20
+ service: service)
21
+ end
22
+
23
+ let!(:vhost2) do
24
+ Fabricate(:vhost, virtual_domain: 'domain2', external_host: 'host2',
25
+ service: service)
26
+ end
33
27
 
34
28
  describe '#domains' do
35
29
  it 'should print out the hostnames' do
36
30
  expect(subject).to receive(:environment_from_handle)
37
31
  .with('foobar')
38
32
  .and_return(account)
39
- expect(subject).to receive(:apps_from_handle).and_return(apps)
40
- allow(service).to receive(:create_operation) { op }
33
+ expect(subject).to receive(:apps_from_handle).and_return([app])
41
34
  allow(subject).to receive(:options) do
42
35
  { environment: 'foobar', app: 'web' }
43
36
  end
44
- allow(Aptible::Api::App).to receive(:all) { apps }
45
-
46
- expect(app).to receive(:vhosts) { [vhost1, vhost2] }
47
37
  expect(subject).to receive(:say).with('domain1')
48
38
  expect(subject).to receive(:say).with('domain2')
49
39
 
@@ -51,19 +41,15 @@ describe Aptible::CLI::Agent do
51
41
  end
52
42
 
53
43
  it 'should fail if app is non-existent' do
54
- allow(service).to receive(:create_operation) { op }
55
- allow(Aptible::Api::Account).to receive(:all) { [account] }
56
- allow(account).to receive(:apps) { apps }
44
+ allow(subject).to receive(:options) { { app: 'not-an-app' } }
57
45
 
58
46
  expect do
59
47
  subject.send('domains')
60
- end.to raise_error(Thor::Error)
48
+ end.to raise_error(Thor::Error, /Could not find app/)
61
49
  end
62
50
 
63
51
  it 'should fail if environment is non-existent' do
64
- allow(service).to receive(:create_operation) { op }
65
52
  allow(Aptible::Api::Account).to receive(:all) { [] }
66
- allow(account).to receive(:apps) { apps }
67
53
 
68
54
  expect do
69
55
  subject.send('domains')
@@ -74,14 +60,11 @@ describe Aptible::CLI::Agent do
74
60
  expect(subject).to receive(:environment_from_handle)
75
61
  .with('foobar')
76
62
  .and_return(account)
77
- expect(subject).to receive(:apps_from_handle).and_return(apps)
78
- allow(service).to receive(:create_operation) { op }
63
+ expect(subject).to receive(:apps_from_handle).and_return([app])
79
64
  allow(subject).to receive(:options) do
80
65
  { verbose: true, app: 'hello', environment: 'foobar' }
81
66
  end
82
- allow(Aptible::Api::App).to receive(:all) { apps }
83
67
 
84
- expect(app).to receive(:vhosts) { [vhost1, vhost2] }
85
68
  expect(subject).to receive(:say).with('domain1 -> host1')
86
69
  expect(subject).to receive(:say).with('domain2 -> host2')
87
70
 
@@ -1,33 +1,28 @@
1
- require 'ostruct'
2
1
  require 'spec_helper'
3
2
 
4
- class App < OpenStruct
5
- end
6
-
7
- class Service < OpenStruct
8
- end
9
-
10
3
  describe Aptible::CLI::Agent do
11
4
  before { subject.stub(:ask) }
12
5
  before { subject.stub(:save_token) }
13
6
  before { subject.stub(:fetch_token) { double 'token' } }
14
7
 
15
- let(:service) { Service.new(process_type: 'web') }
16
- let(:app) do
17
- App.new(handle: 'foobar', status: 'provisioned', services: [service])
18
- end
8
+ let!(:app) { Fabricate(:app, handle: 'foobar') }
9
+ let!(:service) { Fabricate(:service, app: app) }
19
10
 
20
11
  describe '#logs' do
12
+ before { allow(Aptible::Api::Account).to receive(:all) { [app.account] } }
13
+ before { allow(Aptible::Api::App).to receive(:all) { [app] } }
14
+ before { subject.options = { app: app.handle } }
15
+
21
16
  it 'should fail if the app is unprovisioned' do
22
- allow(app).to receive(:status) { 'pending' }
23
- allow(subject).to receive(:ensure_app) { app }
24
- expect { subject.send('logs') }.to raise_error(Thor::Error)
17
+ app.status = 'pending'
18
+ expect { subject.send('logs') }
19
+ .to raise_error(Thor::Error, /Have you deployed foobar yet/)
25
20
  end
26
21
 
27
22
  it 'should fail if the app has no services' do
28
- allow(app).to receive(:services) { [] }
29
- allow(subject).to receive(:ensure_app) { app }
30
- expect { subject.send('logs') }.to raise_error(Thor::Error)
23
+ app.services = []
24
+ expect { subject.send('logs') }
25
+ .to raise_error(Thor::Error, /Have you deployed foobar yet/)
31
26
  end
32
27
  end
33
28
  end
@@ -1,13 +1,11 @@
1
- require 'ostruct'
2
1
  require 'spec_helper'
3
2
 
4
- class App < OpenStruct
5
- end
6
-
7
- class Account < OpenStruct
8
- end
9
-
10
3
  describe Aptible::CLI::Agent do
4
+ let(:account) do
5
+ Fabricate(:account, bastion_host: 'bastion.com', dumptruck_port: 45022)
6
+ end
7
+ let(:app) { Fabricate(:app, account: account) }
8
+
11
9
  before { subject.stub(:ask) }
12
10
  before { subject.stub(:save_token) }
13
11
  before { subject.stub(:fetch_token) { double 'token' } }
@@ -15,11 +13,6 @@ describe Aptible::CLI::Agent do
15
13
  before { subject.stub(:set_env) }
16
14
  before { Kernel.stub(:exec) }
17
15
 
18
- let(:account) do
19
- Account.new(bastion_host: 'bastion.com', dumptruck_port: 45022)
20
- end
21
- let(:app) { App.new(handle: 'hello', account: account) }
22
-
23
16
  describe '#ps' do
24
17
  it 'should set ENV["APTIBLE_CLI_COMMAND"]' do
25
18
  expect(subject).to receive(:set_env).with('APTIBLE_CLI_COMMAND', 'ps')
@@ -0,0 +1,10 @@
1
+ class StubAccount < OpenStruct; end
2
+
3
+ Fabricator(:account, from: :stub_account) do
4
+ bastion_host 'localhost'
5
+ dumptruck_port 1234
6
+ handle 'aptible'
7
+
8
+ apps { [] }
9
+ databases { [] }
10
+ end
@@ -0,0 +1,14 @@
1
+ class StubApp < OpenStruct
2
+ def vhosts
3
+ services.map(&:vhosts).flatten
4
+ end
5
+ end
6
+
7
+ Fabricator(:app, from: :stub_app) do
8
+ handle 'hello'
9
+ status 'provisioned'
10
+ account
11
+ services { [] }
12
+
13
+ after_create { |app| app.account.apps << app }
14
+ end
@@ -0,0 +1,10 @@
1
+ class StubBackup < OpenStruct; end
2
+
3
+ Fabricator(:backup, from: :stub_backup) do
4
+ id { sequence(:backup_id) }
5
+ aws_region { %w(us-east-1 us-west-1).sample }
6
+ created_at { Time.now }
7
+ database
8
+
9
+ after_create { |backup| backup.database.backups << backup }
10
+ end
@@ -0,0 +1,15 @@
1
+ class StubDatabase < OpenStruct; end
2
+
3
+ Fabricator(:database, from: :stub_database) do
4
+ type 'postgresql'
5
+ handle do |attrs|
6
+ Fabricate.sequence(:database) { |i| "#{attrs[:type]}-#{i}" }
7
+ end
8
+ passphrase 'password'
9
+ connection_url 'postgresql://aptible:password@10.252.1.125:49158/db'
10
+ account
11
+
12
+ backups { [] }
13
+
14
+ after_create { |database| database.account.databases << database }
15
+ end
@@ -0,0 +1,6 @@
1
+ class StubOperation < OpenStruct; end
2
+
3
+ Fabricator(:operation, from: :stub_operation) do
4
+ status 'queued'
5
+ resource { Fabricate(:app) }
6
+ end
@@ -0,0 +1,9 @@
1
+ class StubService < OpenStruct; end
2
+
3
+ Fabricator(:service, from: :stub_service) do
4
+ process_type 'web'
5
+ app
6
+ vhosts { [] }
7
+
8
+ after_create { |service| service.app.services << service }
9
+ end
@@ -0,0 +1,9 @@
1
+ class StubVhost < OpenStruct; end
2
+
3
+ Fabricator(:vhost, from: :stub_vhost) do
4
+ virtual_domain 'domain1'
5
+ external_host 'host1'
6
+ service
7
+
8
+ after_create { |vhost| vhost.service.vhosts << vhost }
9
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,7 +1,15 @@
1
1
  $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  $LOAD_PATH.unshift(File.dirname(__FILE__))
3
3
 
4
- require 'webmock/rspec'
4
+ Bundler.require :development
5
+
6
+ require 'simplecov'
7
+ SimpleCov.start
8
+
9
+ if ENV['CI']
10
+ require 'codecov'
11
+ SimpleCov.formatter = SimpleCov::Formatter::Codecov
12
+ end
5
13
 
6
14
  # Load shared spec files
7
15
  Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
metadata CHANGED
@@ -1,57 +1,71 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.9
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-26 00:00:00.000000000 Z
11
+ date: 2016-06-20 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: 0.9.5
19
+ version: 0.9.7
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: 0.9.5
26
+ version: 0.9.7
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: aptible-auth
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: 0.11.3
33
+ version: 0.11.7
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: 0.11.3
40
+ version: 0.11.7
41
+ - !ruby/object:Gem::Dependency
42
+ name: aptible-resource
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: 0.3.6
48
+ type: :runtime
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: 0.3.6
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: thor
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 0.19.0
61
+ version: 0.19.1
48
62
  type: :runtime
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 0.19.0
68
+ version: 0.19.1
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: git
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +94,20 @@ dependencies:
80
94
  - - ">="
81
95
  - !ruby/object:Gem::Version
82
96
  version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: chronic_duration
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - "~>"
102
+ - !ruby/object:Gem::Version
103
+ version: 0.10.6
104
+ type: :runtime
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - "~>"
109
+ - !ruby/object:Gem::Version
110
+ version: 0.10.6
83
111
  - !ruby/object:Gem::Dependency
84
112
  name: bundler
85
113
  requirement: !ruby/object:Gem::Requirement
@@ -164,6 +192,20 @@ dependencies:
164
192
  - - ">="
165
193
  - !ruby/object:Gem::Version
166
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: fabrication
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - "~>"
200
+ - !ruby/object:Gem::Version
201
+ version: 2.15.2
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - "~>"
207
+ - !ruby/object:Gem::Version
208
+ version: 2.15.2
167
209
  description: Aptible CLI
168
210
  email:
169
211
  - frank@macreery.com
@@ -182,6 +224,7 @@ files:
182
224
  - Rakefile
183
225
  - aptible-cli.gemspec
184
226
  - bin/aptible
227
+ - codecov.yml
185
228
  - lib/aptible/cli.rb
186
229
  - lib/aptible/cli/agent.rb
187
230
  - lib/aptible/cli/helpers/app.rb
@@ -192,6 +235,7 @@ files:
192
235
  - lib/aptible/cli/helpers/token.rb
193
236
  - lib/aptible/cli/helpers/tunnel.rb
194
237
  - lib/aptible/cli/subcommands/apps.rb
238
+ - lib/aptible/cli/subcommands/backup.rb
195
239
  - lib/aptible/cli/subcommands/config.rb
196
240
  - lib/aptible/cli/subcommands/db.rb
197
241
  - lib/aptible/cli/subcommands/domains.rb
@@ -202,13 +246,23 @@ files:
202
246
  - lib/aptible/cli/subcommands/ssh.rb
203
247
  - lib/aptible/cli/version.rb
204
248
  - spec/aptible/cli/agent_spec.rb
205
- - spec/aptible/cli/helpers/handle_from_git_remote.rb
249
+ - spec/aptible/cli/helpers/git_remote_handle_strategy_spec.rb
250
+ - spec/aptible/cli/helpers/handle_from_git_remote_spec.rb
251
+ - spec/aptible/cli/helpers/options_handle_strategy_spec.rb
206
252
  - spec/aptible/cli/helpers/tunnel_spec.rb
207
253
  - spec/aptible/cli/subcommands/apps_spec.rb
254
+ - spec/aptible/cli/subcommands/backup_spec.rb
208
255
  - spec/aptible/cli/subcommands/db_spec.rb
209
256
  - spec/aptible/cli/subcommands/domains_spec.rb
210
257
  - spec/aptible/cli/subcommands/logs_spec.rb
211
258
  - spec/aptible/cli/subcommands/ps_spec.rb
259
+ - spec/fabricators/account_fabricator.rb
260
+ - spec/fabricators/app_fabricator.rb
261
+ - spec/fabricators/backup_fabricator.rb
262
+ - spec/fabricators/database_fabricator.rb
263
+ - spec/fabricators/operation_fabricator.rb
264
+ - spec/fabricators/service_fabricator.rb
265
+ - spec/fabricators/vhost_fabricator.rb
212
266
  - spec/mock/ssh_mock.rb
213
267
  - spec/spec_helper.rb
214
268
  homepage: https://github.com/aptible/aptible-cli
@@ -231,18 +285,28 @@ required_rubygems_version: !ruby/object:Gem::Requirement
231
285
  version: '0'
232
286
  requirements: []
233
287
  rubyforge_project:
234
- rubygems_version: 2.4.5.1
288
+ rubygems_version: 2.6.4
235
289
  signing_key:
236
290
  specification_version: 4
237
291
  summary: Command-line interface for Aptible services
238
292
  test_files:
239
293
  - spec/aptible/cli/agent_spec.rb
240
- - spec/aptible/cli/helpers/handle_from_git_remote.rb
294
+ - spec/aptible/cli/helpers/git_remote_handle_strategy_spec.rb
295
+ - spec/aptible/cli/helpers/handle_from_git_remote_spec.rb
296
+ - spec/aptible/cli/helpers/options_handle_strategy_spec.rb
241
297
  - spec/aptible/cli/helpers/tunnel_spec.rb
242
298
  - spec/aptible/cli/subcommands/apps_spec.rb
299
+ - spec/aptible/cli/subcommands/backup_spec.rb
243
300
  - spec/aptible/cli/subcommands/db_spec.rb
244
301
  - spec/aptible/cli/subcommands/domains_spec.rb
245
302
  - spec/aptible/cli/subcommands/logs_spec.rb
246
303
  - spec/aptible/cli/subcommands/ps_spec.rb
304
+ - spec/fabricators/account_fabricator.rb
305
+ - spec/fabricators/app_fabricator.rb
306
+ - spec/fabricators/backup_fabricator.rb
307
+ - spec/fabricators/database_fabricator.rb
308
+ - spec/fabricators/operation_fabricator.rb
309
+ - spec/fabricators/service_fabricator.rb
310
+ - spec/fabricators/vhost_fabricator.rb
247
311
  - spec/mock/ssh_mock.rb
248
312
  - spec/spec_helper.rb