Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 17 additions & 3 deletions lib/aptible/cli/resource_formatter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,22 @@ def inject_deleted_database(node, database, account)
attach_account(node, account)
end

def inject_account(node, account)
def inject_account(node, account, include_stack = false)
node.value('id', account.id)
node.value('handle', account.handle)
node.value('created_at', account.created_at)

if include_stack && account.stack
node.keyed_object('stack', 'name') do |n|
n.value('name', account.stack.name)
n.value('id', account.stack.id)
n.value('region', account.stack.region)
n.value(
'outbound_ip_addresses',
account.stack.outbound_ip_addresses
)
end
end
end

def inject_operation(node, operation)
Expand Down Expand Up @@ -145,6 +157,8 @@ def inject_database(node, database, account)
if database.service
node.value('container_size', \
database.service.container_memory_limit_mb)
node.value('container_profile', \
database.service.instance_class.to_s[/[a-z]/])
end
end

Expand Down Expand Up @@ -309,10 +323,10 @@ def inject_service_sizing_policy(node, policy, service)

private

def attach_account(node, account)
def attach_account(node, account, include_stack = false)
return if NO_NESTING.eql?(account)
node.keyed_object('environment', 'handle') do |n|
inject_account(n, account)
inject_account(n, account, include_stack)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/aptible/cli/subcommands/environment.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ def self.included(thor)
) do |node|
scoped_environments(options).each do |account|
node.object do |n|
ResourceFormatter.inject_account(n, account)
ResourceFormatter.inject_account(n, account, true)
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions spec/aptible/cli/helpers/s3_log_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@
]
)
before do
subject.stub(:s3_client) do
allow(subject).to receive(:s3_client) do
Aws::S3::Resource.new(region: 'us-east-1', client: client_stub)
end
end
Expand Down Expand Up @@ -227,7 +227,7 @@
{ key: v3app }
]
)
subject.stub(:s3_client) do
allow(subject).to receive(:s3_client) do
Aws::S3::Resource.new(region: 'us-east-1', client: client_stub)
end
end
Expand Down
2 changes: 1 addition & 1 deletion spec/aptible/cli/subcommands/db_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ class SocatHelperMock < OpenStruct
allow(Aptible::Api::Account).to receive(:all).and_return([account])
end
before do
subject.stub(:validate_image_type) { true }
allow(subject).to receive(:validate_image_type).and_return(true)
end

def expect_provision_database(create_opts, provision_opts = {})
Expand Down
53 changes: 50 additions & 3 deletions spec/aptible/cli/subcommands/environment_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,58 @@
end

describe('#environment:list') do
it 'lists avaliable environments' do
it 'lists available environments' do
subject.send('environment:list')

expect(captured_output_text.split("\n")).to include('foo')
expect(captured_output_text.split("\n")).to include('bar')
end

it 'includes stack information in JSON output' do
stack1 = Fabricate(
:stack,
name: 'stack1',
region: 'us-east-1',
outbound_ip_addresses: ['1.1.1.1']
)
stack2 = Fabricate(
:stack,
name: 'stack2',
region: 'us-west-1',
outbound_ip_addresses: ['2.2.2.2']
)
a1.stack = stack1
a2.stack = stack2

subject.send('environment:list')

expected_json = [
{
'id' => a1.id,
'handle' => 'foo',
'created_at' => fmt_time(a1.created_at),
'stack' => {
'id' => stack1.id,
'name' => 'stack1',
'region' => 'us-east-1',
'outbound_ip_addresses' => ['1.1.1.1']
}
},
{
'id' => a2.id,
'handle' => 'bar',
'created_at' => fmt_time(a2.created_at),
'stack' => {
'id' => stack2.id,
'name' => 'stack2',
'region' => 'us-west-1',
'outbound_ip_addresses' => ['2.2.2.2']
}
}
]

expect(captured_output_json).to eq(expected_json)
end
end

describe('#environment:ca_cert') do
Expand All @@ -46,8 +92,9 @@
'created_at' => fmt_time(a2.created_at)
}
]
expect(captured_output_json.map! { |account| account.except('id') })
.to eq(expected_accounts)
expect(
captured_output_json.map! { |account| account.except('id', 'stack') }
).to eq(expected_accounts)
end

it 'fetches certs for specified environment' do
Expand Down
15 changes: 9 additions & 6 deletions spec/aptible/cli/subcommands/logs_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -73,8 +73,9 @@
string_matches: 'foo',
download_location: './'
}
subject.stub(:info_from_path) { { shasum: 'foo' } }
subject.stub(:encryption_key) { subject.options[:decryption_keys] }
allow(subject).to receive(:info_from_path).and_return(shasum: 'foo')
allow(subject).to receive(:encryption_key)
.and_return(subject.options[:decryption_keys])
end

it 'download all files' do
Expand Down Expand Up @@ -116,8 +117,9 @@
app_id: 123,
download_location: './'
}
subject.stub(:info_from_path) { { shasum: 'foo' } }
subject.stub(:encryption_key) { subject.options[:decryption_keys] }
allow(subject).to receive(:info_from_path).and_return(shasum: 'foo')
allow(subject).to receive(:encryption_key)
.and_return(subject.options[:decryption_keys])
end

it 'download all files' do
Expand Down Expand Up @@ -161,8 +163,9 @@
'9080b96447f98b31ef9831d5fd98b09e3c5c545269734e2e825644571152457c',
download_location: './'
}
subject.stub(:info_from_path) { { shasum: 'foo' } }
subject.stub(:encryption_key) { subject.options[:decryption_keys] }
allow(subject).to receive(:info_from_path).and_return(shasum: 'foo')
allow(subject).to receive(:encryption_key)
.and_return(subject.options[:decryption_keys])
end

it 'download all files' do
Expand Down