aptible-cli 0.18.2 → 0.19.2

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.
@@ -0,0 +1,207 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::CLI::Agent do
4
+ let(:account) { Fabricate(:account) }
5
+ let!(:log_drain) do
6
+ Fabricate(:log_drain, handle: 'test', account: account)
7
+ end
8
+
9
+ let(:token) { double('token') }
10
+ before { allow(subject).to receive(:fetch_token).and_return(token) }
11
+
12
+ before do
13
+ allow(Aptible::Api::Account).to receive(:all)
14
+ .with(token: token).and_return([account])
15
+ end
16
+
17
+ describe '#log_drain:list' do
18
+ it 'lists a log drains for an account' do
19
+ subject.send('log_drain:list')
20
+
21
+ out = "=== aptible\n" \
22
+ "test\n"
23
+ expect(captured_output_text).to eq(out)
24
+ end
25
+
26
+ it 'lists log drains across multiple accounts' do
27
+ other_account = Fabricate(:account)
28
+ Fabricate(:log_drain, handle: 'test2', account: other_account)
29
+ accounts = [account, other_account]
30
+ allow(Aptible::Api::Account).to receive(:all).and_return(accounts)
31
+
32
+ subject.send('log_drain:list')
33
+
34
+ out = "=== aptible\n" \
35
+ "test\n" \
36
+ "test2\n"
37
+ expect(captured_output_text).to eq(out)
38
+ end
39
+
40
+ it 'lists log drains for a single account when --environment is included' do
41
+ other_account = Fabricate(:account)
42
+ Fabricate(:log_drain, handle: 'test2', account: other_account)
43
+ accounts = [account, other_account]
44
+ allow(Aptible::Api::Account).to receive(:all).and_return(accounts)
45
+
46
+ subject.options = { environment: account.handle }
47
+ subject.send('log_drain:list')
48
+
49
+ out = "=== aptible\n" \
50
+ "test\n"
51
+ expect(captured_output_text).to eq(out)
52
+ end
53
+ end
54
+
55
+ describe '#log_drain:create' do
56
+ def expect_provision_log_drain(create_opts, provision_opts = {})
57
+ log_drain = Fabricate(:log_drain, account: account)
58
+ op = Fabricate(:operation)
59
+
60
+ expect(account).to receive(:create_log_drain!)
61
+ .with(**create_opts).and_return(log_drain)
62
+
63
+ expect(log_drain).to receive(:create_operation)
64
+ .with(type: :provision, **provision_opts).and_return(op)
65
+
66
+ expect(subject).to receive(:attach_to_operation_logs).with(op)
67
+ end
68
+
69
+ context 'elasticsearch' do
70
+ let(:db) { Fabricate(:database, account: account, id: 5) }
71
+
72
+ it 'creates a new Elasticsearch log drain' do
73
+ opts = {
74
+ handle: 'test',
75
+ drain_apps: nil,
76
+ drain_databases: nil,
77
+ drain_ephemeral_sessions: nil,
78
+ drain_proxies: nil,
79
+ drain_type: :elasticsearch_database,
80
+ logging_token: nil,
81
+ database_id: db.id
82
+ }
83
+ expect_provision_log_drain(opts)
84
+
85
+ subject.options = {
86
+ db: db.handle,
87
+ environment: account.handle
88
+ }
89
+ subject.send('log_drain:create:elasticsearch', 'test')
90
+ end
91
+
92
+ it 'creates a new Elasticsearch log drain with a pipeline' do
93
+ opts = {
94
+ handle: 'test-es',
95
+ drain_apps: nil,
96
+ drain_databases: nil,
97
+ drain_ephemeral_sessions: nil,
98
+ drain_proxies: nil,
99
+ drain_type: :elasticsearch_database,
100
+ logging_token: 'test-pipeline',
101
+ database_id: db.id
102
+ }
103
+ expect_provision_log_drain(opts)
104
+
105
+ subject.options = {
106
+ db: db.handle,
107
+ environment: account.handle,
108
+ pipeline: 'test-pipeline'
109
+ }
110
+ subject.send('log_drain:create:elasticsearch', 'test-es')
111
+ end
112
+ end
113
+
114
+ # HTTPS, Datadog, Sumologic, and LogDNA are all similar enough
115
+ # that they're not tested individually
116
+ context 'https' do
117
+ it 'creates a new HTTPS log drain' do
118
+ opts = {
119
+ handle: 'test-https',
120
+ drain_apps: nil,
121
+ drain_databases: nil,
122
+ drain_ephemeral_sessions: nil,
123
+ drain_proxies: nil,
124
+ drain_type: :https_post,
125
+ url: 'https://test.foo.com'
126
+ }
127
+ expect_provision_log_drain(opts)
128
+
129
+ subject.options = {
130
+ environment: account.handle,
131
+ url: 'https://test.foo.com'
132
+ }
133
+ subject.send('log_drain:create:https', 'test-https')
134
+ end
135
+ end
136
+
137
+ # Syslog and Papertrail are similar enough that they're
138
+ # not tested individually
139
+ context 'syslog' do
140
+ it 'creates a new syslog log drain' do
141
+ opts = {
142
+ handle: 'test-syslog',
143
+ drain_host: 'test.foo.com',
144
+ drain_port: 2468,
145
+ logging_token: nil,
146
+ drain_apps: nil,
147
+ drain_databases: nil,
148
+ drain_ephemeral_sessions: nil,
149
+ drain_proxies: nil,
150
+ drain_type: :syslog_tls_tcp
151
+ }
152
+ expect_provision_log_drain(opts)
153
+
154
+ subject.options = {
155
+ environment: account.handle,
156
+ host: 'test.foo.com',
157
+ port: 2468
158
+ }
159
+ subject.send('log_drain:create:syslog', 'test-syslog')
160
+ end
161
+
162
+ it 'creates a new syslog log drain with a logging token' do
163
+ opts = {
164
+ handle: 'test-syslog',
165
+ drain_host: 'test.foo.com',
166
+ drain_port: 2468,
167
+ logging_token: 'test-token',
168
+ drain_apps: nil,
169
+ drain_databases: nil,
170
+ drain_ephemeral_sessions: nil,
171
+ drain_proxies: nil,
172
+ drain_type: :syslog_tls_tcp
173
+ }
174
+ expect_provision_log_drain(opts)
175
+
176
+ subject.options = {
177
+ environment: account.handle,
178
+ host: 'test.foo.com',
179
+ port: 2468,
180
+ token: 'test-token'
181
+ }
182
+ subject.send('log_drain:create:syslog', 'test-syslog')
183
+ end
184
+ end
185
+ end
186
+
187
+ describe '#log_drain:deprovision' do
188
+ let(:operation) { Fabricate(:operation, resource: log_drain) }
189
+
190
+ it 'deprovisions a log drain' do
191
+ expect(log_drain).to receive(:create_operation)
192
+ .with(type: :deprovision).and_return(operation)
193
+ expect(subject).to receive(:attach_to_operation_logs).with(operation)
194
+ subject.send('log_drain:deprovision', log_drain.handle)
195
+ end
196
+
197
+ it 'does not fail if the operation cannot be found' do
198
+ expect(log_drain).to receive(:create_operation)
199
+ .with(type: :deprovision).and_return(operation)
200
+ response = Faraday::Response.new(status: 404)
201
+ error = HyperResource::ClientError.new('Not Found', response: response)
202
+ expect(subject).to receive(:attach_to_operation_logs).with(operation)
203
+ .and_raise(error)
204
+ subject.send('log_drain:deprovision', log_drain.handle)
205
+ end
206
+ end
207
+ end
@@ -0,0 +1,183 @@
1
+ require 'spec_helper'
2
+
3
+ describe Aptible::CLI::Agent do
4
+ let(:account) { Fabricate(:account) }
5
+ let!(:metric_drain) do
6
+ Fabricate(:metric_drain, handle: 'test', account: account)
7
+ end
8
+
9
+ let(:token) { double('token') }
10
+ before { allow(subject).to receive(:fetch_token).and_return(token) }
11
+
12
+ before do
13
+ allow(Aptible::Api::Account).to receive(:all)
14
+ .with(token: token).and_return([account])
15
+ end
16
+
17
+ describe '#metric_drain:list' do
18
+ it 'lists a metric drains for an account' do
19
+ subject.send('metric_drain:list')
20
+
21
+ out = "=== aptible\n" \
22
+ "test\n"
23
+ expect(captured_output_text).to eq(out)
24
+ end
25
+
26
+ it 'lists metric drains across multiple accounts' do
27
+ other_account = Fabricate(:account)
28
+ Fabricate(:metric_drain, handle: 'test2', account: other_account)
29
+ accounts = [account, other_account]
30
+ allow(Aptible::Api::Account).to receive(:all).and_return(accounts)
31
+
32
+ subject.send('metric_drain:list')
33
+
34
+ out = "=== aptible\n" \
35
+ "test\n" \
36
+ "test2\n"
37
+ expect(captured_output_text).to eq(out)
38
+ end
39
+
40
+ it 'lists metric drains for a single account with --environment' do
41
+ other_account = Fabricate(:account)
42
+ Fabricate(:metric_drain, handle: 'test2', account: other_account)
43
+ accounts = [account, other_account]
44
+ allow(Aptible::Api::Account).to receive(:all).and_return(accounts)
45
+
46
+ subject.options = { environment: account.handle }
47
+ subject.send('metric_drain:list')
48
+
49
+ out = "=== aptible\n" \
50
+ "test\n"
51
+ expect(captured_output_text).to eq(out)
52
+ end
53
+ end
54
+
55
+ describe '#metric_drain:create' do
56
+ def expect_provision_metric_drain(create_opts, provision_opts = {})
57
+ metric_drain = Fabricate(:metric_drain, account: account)
58
+ op = Fabricate(:operation)
59
+
60
+ expect(account).to receive(:create_metric_drain!)
61
+ .with(**create_opts).and_return(metric_drain)
62
+
63
+ expect(metric_drain).to receive(:create_operation)
64
+ .with(type: :provision, **provision_opts).and_return(op)
65
+
66
+ expect(subject).to receive(:attach_to_operation_logs).with(op)
67
+ end
68
+
69
+ context 'influxdb' do
70
+ let(:db) { Fabricate(:database, account: account, id: 5) }
71
+
72
+ it 'creates a new InfluxDB metric drain' do
73
+ opts = {
74
+ handle: 'test-influxdb',
75
+ drain_type: :influxdb_database,
76
+ database_id: db.id
77
+ }
78
+ expect_provision_metric_drain(opts)
79
+
80
+ subject.options = {
81
+ db: db.handle,
82
+ environment: account.handle
83
+ }
84
+ subject.send('metric_drain:create:influxdb', 'test-influxdb')
85
+ end
86
+ end
87
+
88
+ context 'influxdb:custom' do
89
+ it 'creates a new InfluxDB metric drain' do
90
+ opts = {
91
+ handle: 'test-influxdb-custom',
92
+ drain_type: :influxdb,
93
+ drain_configuration: {
94
+ address: 'https://test.foo.com:443',
95
+ database: 'foobar',
96
+ password: 'bar',
97
+ username: 'foo'
98
+ }
99
+ }
100
+ expect_provision_metric_drain(opts)
101
+
102
+ subject.options = {
103
+ environment: account.handle,
104
+ username: 'foo',
105
+ password: 'bar',
106
+ db: 'foobar',
107
+ url: 'https://test.foo.com:443'
108
+ }
109
+ subject.send('metric_drain:create:influxdb:custom',
110
+ 'test-influxdb-custom')
111
+ end
112
+ end
113
+
114
+ context 'datadog' do
115
+ it 'creates a new Datadog metric drain' do
116
+ opts = {
117
+ handle: 'test-datadog',
118
+ drain_type: :datadog,
119
+ drain_configuration: {
120
+ api_key: 'foobar'
121
+ }
122
+ }
123
+ expect_provision_metric_drain(opts)
124
+
125
+ subject.options = {
126
+ environment: account.handle,
127
+ api_key: 'foobar'
128
+ }
129
+ subject.send('metric_drain:create:datadog', 'test-datadog')
130
+ end
131
+
132
+ it 'raises an error when the Datadog site is invalid' do
133
+ subject.options = {
134
+ environment: account.handle,
135
+ api_key: 'foobar',
136
+ site: 'BAD'
137
+ }
138
+ expect { subject.send('metric_drain:create:datadog', 'test-datadog') }
139
+ .to raise_error(Thor::Error, /Invalid Datadog site/i)
140
+ end
141
+
142
+ it 'creates a new Datadog metric drain with a Datadog site defined' do
143
+ opts = {
144
+ handle: 'test-datadog',
145
+ drain_type: :datadog,
146
+ drain_configuration: {
147
+ api_key: 'foobar',
148
+ series_url: 'https://app.datadoghq.eu'
149
+ }
150
+ }
151
+ expect_provision_metric_drain(opts)
152
+
153
+ subject.options = {
154
+ environment: account.handle,
155
+ api_key: 'foobar',
156
+ site: 'EU1'
157
+ }
158
+ subject.send('metric_drain:create:datadog', 'test-datadog')
159
+ end
160
+ end
161
+ end
162
+
163
+ describe '#metric_drain:deprovision' do
164
+ let(:operation) { Fabricate(:operation, resource: metric_drain) }
165
+
166
+ it 'deprovisions a log drain' do
167
+ expect(metric_drain).to receive(:create_operation)
168
+ .with(type: :deprovision).and_return(operation)
169
+ expect(subject).to receive(:attach_to_operation_logs).with(operation)
170
+ subject.send('metric_drain:deprovision', metric_drain.handle)
171
+ end
172
+
173
+ it 'does not fail if the operation cannot be found' do
174
+ expect(metric_drain).to receive(:create_operation)
175
+ .with(type: :deprovision).and_return(operation)
176
+ response = Faraday::Response.new(status: 404)
177
+ error = HyperResource::ClientError.new('Not Found', response: response)
178
+ expect(subject).to receive(:attach_to_operation_logs).with(operation)
179
+ .and_raise(error)
180
+ subject.send('metric_drain:deprovision', metric_drain.handle)
181
+ end
182
+ end
183
+ end
@@ -26,5 +26,7 @@ Fabricator(:account, from: :stub_account) do
26
26
  apps { [] }
27
27
  databases { [] }
28
28
  certificates { [] }
29
+ log_drains { [] }
30
+ metric_drains { [] }
29
31
  created_at { Time.now }
30
32
  end
@@ -0,0 +1,21 @@
1
+ class StubLogDrain < OpenStruct
2
+ def attributes
3
+ # I foresee hard-coding values like this
4
+ # being hard to debug in the future,
5
+ # so sorry if you're here and cursing me, but
6
+ # I can't think of a better way to fake this.
7
+ {
8
+ 'drain_username' => drain_username,
9
+ 'drain_host' => drain_host,
10
+ 'drain_port' => drain_port,
11
+ 'url' => url
12
+ }
13
+ end
14
+ end
15
+
16
+ Fabricator(:log_drain, from: :stub_log_drain) do
17
+ id { sequence(:log_drain_id) }
18
+ account
19
+
20
+ after_create { |drain| drain.account.log_drains << drain }
21
+ end
@@ -0,0 +1,8 @@
1
+ class StubMetricDrain < OpenStruct; end
2
+
3
+ Fabricator(:metric_drain, from: :stub_metric_drain) do
4
+ id { sequence(:metric_drain_id) }
5
+ account
6
+
7
+ after_create { |drain| drain.account.metric_drains << drain }
8
+ end
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.18.2
4
+ version: 0.19.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Frank Macreery
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-06-09 00:00:00.000000000 Z
11
+ date: 2022-02-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: aptible-resource
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: 1.2.3
47
+ version: 1.2.4
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: 1.2.3
54
+ version: 1.2.4
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: aptible-billing
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -274,8 +274,11 @@ files:
274
274
  - lib/aptible/cli/formatter/value.rb
275
275
  - lib/aptible/cli/helpers/app.rb
276
276
  - lib/aptible/cli/helpers/app_or_database.rb
277
+ - lib/aptible/cli/helpers/config_path.rb
277
278
  - lib/aptible/cli/helpers/database.rb
278
279
  - lib/aptible/cli/helpers/environment.rb
280
+ - lib/aptible/cli/helpers/log_drain.rb
281
+ - lib/aptible/cli/helpers/metric_drain.rb
279
282
  - lib/aptible/cli/helpers/operation.rb
280
283
  - lib/aptible/cli/helpers/security_key.rb
281
284
  - lib/aptible/cli/helpers/ssh.rb
@@ -294,11 +297,12 @@ files:
294
297
  - lib/aptible/cli/subcommands/config.rb
295
298
  - lib/aptible/cli/subcommands/db.rb
296
299
  - lib/aptible/cli/subcommands/deploy.rb
297
- - lib/aptible/cli/subcommands/domains.rb
298
300
  - lib/aptible/cli/subcommands/endpoints.rb
299
301
  - lib/aptible/cli/subcommands/environment.rb
300
302
  - lib/aptible/cli/subcommands/inspect.rb
303
+ - lib/aptible/cli/subcommands/log_drain.rb
301
304
  - lib/aptible/cli/subcommands/logs.rb
305
+ - lib/aptible/cli/subcommands/metric_drain.rb
302
306
  - lib/aptible/cli/subcommands/operation.rb
303
307
  - lib/aptible/cli/subcommands/rebuild.rb
304
308
  - lib/aptible/cli/subcommands/restart.rb
@@ -323,11 +327,12 @@ files:
323
327
  - spec/aptible/cli/subcommands/config_spec.rb
324
328
  - spec/aptible/cli/subcommands/db_spec.rb
325
329
  - spec/aptible/cli/subcommands/deploy_spec.rb
326
- - spec/aptible/cli/subcommands/domains_spec.rb
327
330
  - spec/aptible/cli/subcommands/endpoints_spec.rb
328
331
  - spec/aptible/cli/subcommands/environment_spec.rb
329
332
  - spec/aptible/cli/subcommands/inspect_spec.rb
333
+ - spec/aptible/cli/subcommands/log_drain_spec.rb
330
334
  - spec/aptible/cli/subcommands/logs_spec.rb
335
+ - spec/aptible/cli/subcommands/metric_drain_spec.rb
331
336
  - spec/aptible/cli/subcommands/operation_spec.rb
332
337
  - spec/aptible/cli/subcommands/rebuild_spec.rb
333
338
  - spec/aptible/cli/subcommands/restart_spec.rb
@@ -343,6 +348,8 @@ files:
343
348
  - spec/fabricators/database_disk_fabricator.rb
344
349
  - spec/fabricators/database_fabricator.rb
345
350
  - spec/fabricators/database_image_fabricator.rb
351
+ - spec/fabricators/log_drain_fabricator.rb
352
+ - spec/fabricators/metric_drain_fabricator.rb
346
353
  - spec/fabricators/operation_fabricator.rb
347
354
  - spec/fabricators/service_fabricator.rb
348
355
  - spec/fabricators/stack_fabricator.rb
@@ -361,7 +368,7 @@ homepage: https://github.com/aptible/aptible-cli
361
368
  licenses:
362
369
  - MIT
363
370
  metadata: {}
364
- post_install_message:
371
+ post_install_message:
365
372
  rdoc_options: []
366
373
  require_paths:
367
374
  - lib
@@ -376,8 +383,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
376
383
  - !ruby/object:Gem::Version
377
384
  version: '0'
378
385
  requirements: []
379
- rubygems_version: 3.0.3
380
- signing_key:
386
+ rubygems_version: 3.0.3.1
387
+ signing_key:
381
388
  specification_version: 4
382
389
  summary: Command-line interface for Aptible services
383
390
  test_files:
@@ -398,11 +405,12 @@ test_files:
398
405
  - spec/aptible/cli/subcommands/config_spec.rb
399
406
  - spec/aptible/cli/subcommands/db_spec.rb
400
407
  - spec/aptible/cli/subcommands/deploy_spec.rb
401
- - spec/aptible/cli/subcommands/domains_spec.rb
402
408
  - spec/aptible/cli/subcommands/endpoints_spec.rb
403
409
  - spec/aptible/cli/subcommands/environment_spec.rb
404
410
  - spec/aptible/cli/subcommands/inspect_spec.rb
411
+ - spec/aptible/cli/subcommands/log_drain_spec.rb
405
412
  - spec/aptible/cli/subcommands/logs_spec.rb
413
+ - spec/aptible/cli/subcommands/metric_drain_spec.rb
406
414
  - spec/aptible/cli/subcommands/operation_spec.rb
407
415
  - spec/aptible/cli/subcommands/rebuild_spec.rb
408
416
  - spec/aptible/cli/subcommands/restart_spec.rb
@@ -418,6 +426,8 @@ test_files:
418
426
  - spec/fabricators/database_disk_fabricator.rb
419
427
  - spec/fabricators/database_fabricator.rb
420
428
  - spec/fabricators/database_image_fabricator.rb
429
+ - spec/fabricators/log_drain_fabricator.rb
430
+ - spec/fabricators/metric_drain_fabricator.rb
421
431
  - spec/fabricators/operation_fabricator.rb
422
432
  - spec/fabricators/service_fabricator.rb
423
433
  - spec/fabricators/stack_fabricator.rb
@@ -1,40 +0,0 @@
1
- require 'shellwords'
2
-
3
- module Aptible
4
- module CLI
5
- module Subcommands
6
- module Domains
7
- def self.included(thor)
8
- thor.class_eval do
9
- include Helpers::Operation
10
- include Helpers::App
11
-
12
- desc 'domains',
13
- "Print an app's current virtual domains - DEPRECATED"
14
- app_options
15
- option :verbose, aliases: '-v'
16
- def domains
17
- deprecated 'This command is deprecated in favor of endpoints:list'
18
- app = ensure_app(options)
19
- print_vhosts(app) do |vhost|
20
- if options[:verbose]
21
- "#{vhost.virtual_domain} -> #{vhost.external_host}"
22
- else
23
- vhost.virtual_domain
24
- end
25
- end
26
- end
27
-
28
- private
29
-
30
- def print_vhosts(app)
31
- (app.vhosts || []).each do |vhost|
32
- say yield(vhost)
33
- end
34
- end
35
- end
36
- end
37
- end
38
- end
39
- end
40
- end
@@ -1,76 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe Aptible::CLI::Agent do
4
- before do
5
- allow(subject).to receive(:ask)
6
- allow(subject).to receive(:save_token)
7
- allow(subject).to receive(:fetch_token) { double 'token' }
8
- end
9
-
10
- let!(:account) { Fabricate(:account) }
11
- let!(:app) { Fabricate(:app, handle: 'hello', account: account) }
12
- let!(:service) { Fabricate(:service, app: app) }
13
- let(:op) { Fabricate(:operation, status: 'succeeded', resource: app) }
14
-
15
- before do
16
- allow(Aptible::Api::App).to receive(:all) { [app] }
17
- allow(Aptible::Api::Account).to receive(:all) { [account] }
18
- end
19
-
20
- let!(:vhost1) do
21
- Fabricate(:vhost, virtual_domain: 'domain1', external_host: 'host1',
22
- service: service)
23
- end
24
-
25
- let!(:vhost2) do
26
- Fabricate(:vhost, virtual_domain: 'domain2', external_host: 'host2',
27
- service: service)
28
- end
29
-
30
- describe '#domains' do
31
- it 'should print out the hostnames' do
32
- expect(subject).to receive(:environment_from_handle)
33
- .with('foobar')
34
- .and_return(account)
35
- expect(subject).to receive(:apps_from_handle).and_return([app])
36
- allow(subject).to receive(:options) do
37
- { environment: 'foobar', app: 'web' }
38
- end
39
- expect(subject).to receive(:say).with('domain1')
40
- expect(subject).to receive(:say).with('domain2')
41
-
42
- subject.send('domains')
43
- end
44
-
45
- it 'should fail if app is non-existent' do
46
- allow(subject).to receive(:options) { { app: 'not-an-app' } }
47
-
48
- expect do
49
- subject.send('domains')
50
- end.to raise_error(Thor::Error, /Could not find app/)
51
- end
52
-
53
- it 'should fail if environment is non-existent' do
54
- allow(Aptible::Api::Account).to receive(:all) { [] }
55
-
56
- expect do
57
- subject.send('domains')
58
- end.to raise_error(Thor::Error)
59
- end
60
-
61
- it 'should print hostnames if -v is passed' do
62
- expect(subject).to receive(:environment_from_handle)
63
- .with('foobar')
64
- .and_return(account)
65
- expect(subject).to receive(:apps_from_handle).and_return([app])
66
- allow(subject).to receive(:options) do
67
- { verbose: true, app: 'hello', environment: 'foobar' }
68
- end
69
-
70
- expect(subject).to receive(:say).with('domain1 -> host1')
71
- expect(subject).to receive(:say).with('domain2 -> host2')
72
-
73
- subject.send('domains')
74
- end
75
- end
76
- end