aptible-cli 0.6.4 → 0.6.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9a00f24436f3849b23c677260e75b31f661eb6e8
4
- data.tar.gz: 857e002bd160ca13dbb846d41527d30138be7ee3
3
+ metadata.gz: 5476287949f6306971e1400683283f93a8a07d5f
4
+ data.tar.gz: 8e1f9600ebc7787553c8c11e02b35dd80ae5af47
5
5
  SHA512:
6
- metadata.gz: 6c2da48570c2db9dc2edb39f1455f6ea10131e35c6719d5d0a69b18a4619e30b8585cea0d8d12f0f99258c9ed550b7dd8eb3642a2c712b764aac4a36a4a22a51
7
- data.tar.gz: 33fc2f342c37a66c2d0e2684384f7bf65304e9a403fe7de9dbbd540f36cf99ed9b15fdb29bd56c8938ae8e7af6e020be9007c97d414eb83298ece9c6f478d1f5
6
+ metadata.gz: f63a2b3abaa73cfe3b61fcad53ad1701279e33ae7d2991646dbc1d997c6b5d8049f2e6515d2b79290e369ef5ce02195f6a30293e6439aae3a16e95685d862500
7
+ data.tar.gz: 1dcfcaad6fd98538bea9a3772c505ee4331d3016ead7ccf4fa42c41e957841617a91c13a1e8a57e3f2f483b79821c06ac37fc9a219e968d5b8cc0230315ecac0
data/Gemfile CHANGED
@@ -2,5 +2,9 @@ source 'https://rubygems.org'
2
2
 
3
3
  gem 'pry', github: 'fancyremarker/pry', branch: 'aptible'
4
4
 
5
+ group :test do
6
+ gem 'webmock'
7
+ end
8
+
5
9
  # Specify your gem's dependencies in aptible-cli.gemspec
6
10
  gemspec
@@ -4,10 +4,14 @@ module Aptible
4
4
  module CLI
5
5
  module Helpers
6
6
  module Token
7
+ TOKEN_ENV_VAR = 'APTIBLE_ACCESS_TOKEN'
8
+
7
9
  def fetch_token
8
- @token ||= current_token_hash[Aptible::Auth.configuration.root_url]
10
+ @token ||= ENV[TOKEN_ENV_VAR] ||
11
+ current_token_hash[Aptible::Auth.configuration.root_url]
9
12
  return @token if @token
10
- fail Thor::Error, 'Could not read token: please run aptible login'
13
+ fail Thor::Error, 'Could not read token: please run aptible login ' \
14
+ "or set #{TOKEN_ENV_VAR}"
11
15
  end
12
16
 
13
17
  def save_token(token)
@@ -35,11 +35,31 @@ module Aptible
35
35
 
36
36
  desc 'apps:scale TYPE NUMBER', 'Scale app to NUMBER of instances'
37
37
  app_options
38
+ option :size, type: :numeric, enum: [512,
39
+ 1024,
40
+ 2048,
41
+ 4096,
42
+ 8192,
43
+ 16384,
44
+ 32768,
45
+ 65536]
38
46
  define_method 'apps:scale' do |type, n|
39
47
  num = Integer(n)
40
48
  app = ensure_app(options)
41
49
  service = app.services.find { |s| s.process_type == type }
42
- op = service.create_operation(type: 'scale', container_count: num)
50
+ if service.nil?
51
+ valid_types = if app.services.empty?
52
+ 'NONE (deploy the app first)'
53
+ else
54
+ app.services.map(&:process_type).join(', ')
55
+ end
56
+ fail Thor::Error, "Service with type #{type} does not " \
57
+ "exist for app #{app.handle}. Valid " \
58
+ "types: #{valid_types}."
59
+ end
60
+ op = service.create_operation(type: 'scale',
61
+ container_count: num,
62
+ container_size: options[:size])
43
63
  attach_to_operation_logs(op)
44
64
  end
45
65
 
@@ -1,5 +1,5 @@
1
1
  module Aptible
2
2
  module CLI
3
- VERSION = '0.6.4'
3
+ VERSION = '0.6.6'
4
4
  end
5
5
  end
@@ -26,22 +26,49 @@ describe Aptible::CLI::Agent do
26
26
  dumptruck_port: 1234,
27
27
  handle: 'aptible')
28
28
  end
29
+ let(:services) { [service] }
29
30
  let(:apps) do
30
- [App.new(handle: 'hello', services: [service], account: account)]
31
+ [App.new(handle: 'hello', services: services, account: account)]
31
32
  end
32
33
 
33
34
  describe '#apps:scale' do
34
35
  it 'should pass given correct parameters' do
35
36
  allow(service).to receive(:create_operation) { op }
36
- allow(subject).to receive(:options) { { app: 'hello' } }
37
+ allow(subject).to receive(:options) do
38
+ { app: 'hello', environment: 'foobar' }
39
+ end
37
40
  allow(op).to receive(:resource) { apps.first }
38
41
  allow(Aptible::Api::App).to receive(:all) { apps }
39
42
 
43
+ expect(subject).to receive(:environment_from_handle)
44
+ .with('foobar')
45
+ .and_return(account)
46
+ expect(subject).to receive(:apps_from_handle).and_return(apps)
47
+ subject.send('apps:scale', 'web', 3)
48
+ end
49
+
50
+ it 'should pass container size param to operation if given' do
51
+ expect(service).to receive(:create_operation)
52
+ .with(type: 'scale', container_count: 3, container_size: 90210)
53
+ .and_return(op)
54
+ allow(subject).to receive(:options) do
55
+ { app: 'hello', size: 90210, environment: 'foobar' }
56
+ end
57
+
58
+ allow(op).to receive(:resource) { apps.first }
59
+ allow(Aptible::Api::App).to receive(:all) { apps }
60
+
61
+ expect(subject).to receive(:environment_from_handle)
62
+ .with('foobar')
63
+ .and_return(account)
64
+ expect(subject).to receive(:apps_from_handle).and_return(apps)
40
65
  subject.send('apps:scale', 'web', 3)
41
66
  end
42
67
 
43
68
  it 'should fail if environment is non-existent' do
44
- allow(subject).to receive(:options) { { environment: 'foo', app: 'web' } }
69
+ allow(subject).to receive(:options) do
70
+ { environment: 'foo', app: 'web' }
71
+ end
45
72
  allow(service).to receive(:create_operation) { op }
46
73
  allow(Aptible::Api::Account).to receive(:all) { [] }
47
74
  allow(account).to receive(:apps) { [apps] }
@@ -70,5 +97,40 @@ describe Aptible::CLI::Agent do
70
97
  subject.send('apps:scale', 'web', 'potato')
71
98
  end.to raise_error(ArgumentError)
72
99
  end
100
+
101
+ it 'should fail if the service does not exist' do
102
+ allow(subject).to receive(:options) do
103
+ { app: 'hello', environment: 'foobar' }
104
+ end
105
+ expect(subject).to receive(:environment_from_handle)
106
+ .with('foobar')
107
+ .and_return(account)
108
+ expect(subject).to receive(:apps_from_handle).and_return(apps)
109
+ allow(Aptible::Api::App).to receive(:all) { apps }
110
+
111
+ expect do
112
+ subject.send('apps:scale', 'potato', 1)
113
+ end.to raise_error(Thor::Error, /Service.* potato.* does not exist/)
114
+ end
115
+
116
+ context 'no service' do
117
+ let(:services) { [] }
118
+
119
+ it 'should fail if the app has no services' do
120
+ expect(subject).to receive(:environment_from_handle)
121
+ .with('foobar')
122
+ .and_return(account)
123
+ expect(subject).to receive(:apps_from_handle).and_return(apps)
124
+ allow(subject).to receive(:options) do
125
+ { app: 'hello', environment: 'foobar' }
126
+ end
127
+
128
+ allow(Aptible::Api::App).to receive(:all) { apps }
129
+
130
+ expect do
131
+ subject.send('apps:scale', 'web', 1)
132
+ end.to raise_error(Thor::Error, /deploy the app first/)
133
+ end
134
+ end
73
135
  end
74
136
  end
@@ -33,8 +33,14 @@ describe Aptible::CLI::Agent do
33
33
 
34
34
  describe '#domains' do
35
35
  it 'should print out the hostnames' do
36
+ expect(subject).to receive(:environment_from_handle)
37
+ .with('foobar')
38
+ .and_return(account)
39
+ expect(subject).to receive(:apps_from_handle).and_return(apps)
36
40
  allow(service).to receive(:create_operation) { op }
37
- allow(subject).to receive(:options) { { app: 'hello' } }
41
+ allow(subject).to receive(:options) do
42
+ { environment: 'foobar', app: 'web' }
43
+ end
38
44
  allow(Aptible::Api::App).to receive(:all) { apps }
39
45
 
40
46
  expect(app).to receive(:vhosts) { [vhost1, vhost2] }
@@ -65,8 +71,14 @@ describe Aptible::CLI::Agent do
65
71
  end
66
72
 
67
73
  it 'should print hostnames if -v is passed' do
74
+ expect(subject).to receive(:environment_from_handle)
75
+ .with('foobar')
76
+ .and_return(account)
77
+ expect(subject).to receive(:apps_from_handle).and_return(apps)
68
78
  allow(service).to receive(:create_operation) { op }
69
- allow(subject).to receive(:options) { { verbose: true, app: 'hello' } }
79
+ allow(subject).to receive(:options) do
80
+ { verbose: true, app: 'hello', environment: 'foobar' }
81
+ end
70
82
  allow(Aptible::Api::App).to receive(:all) { apps }
71
83
 
72
84
  expect(app).to receive(:vhosts) { [vhost1, vhost2] }
@@ -1,6 +1,8 @@
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'
5
+
4
6
  # Load shared spec files
5
7
  Dir["#{File.dirname(__FILE__)}/shared/**/*.rb"].each do |file|
6
8
  require file
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: aptible-cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.6
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-04-04 00:00:00.000000000 Z
11
+ date: 2016-05-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-api
@@ -200,7 +200,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
200
200
  version: '0'
201
201
  requirements: []
202
202
  rubyforge_project:
203
- rubygems_version: 2.6.2
203
+ rubygems_version: 2.4.5.1
204
204
  signing_key:
205
205
  specification_version: 4
206
206
  summary: Command-line interface for Aptible services