Skip to content

Commit

Permalink
Present run and build rootfs images for v3 endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
dsabeti committed Jun 29, 2023
1 parent 9e76aa0 commit fdc8c93
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 1 deletion.
2 changes: 2 additions & 0 deletions app/presenters/v3/stack_presenter.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ def to_hash
updated_at: stack.updated_at,
name: stack.name,
description: stack.description,
run_rootfs_image: stack.run_rootfs_image,
build_rootfs_image: stack.build_rootfs_image,
default: stack.default?,
metadata: {
labels: hashified_labels(stack.labels),
Expand Down
22 changes: 22 additions & 0 deletions spec/request/stacks_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
{
'name' => stack1.name,
'description' => stack1.description,
'run_rootfs_image' => stack1.run_rootfs_image,
'build_rootfs_image' => stack1.build_rootfs_image,
'guid' => stack1.guid,
'default' => false,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand All @@ -36,6 +38,8 @@
{
'name' => stack2.name,
'description' => stack2.description,
'run_rootfs_image' => stack2.run_rootfs_image,
'build_rootfs_image' => stack2.build_rootfs_image,
'guid' => stack2.guid,
'default' => true,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand Down Expand Up @@ -114,6 +118,8 @@
{
'name' => stack1.name,
'description' => stack1.description,
'run_rootfs_image' => stack1.run_rootfs_image,
'build_rootfs_image' => stack1.build_rootfs_image,
'guid' => stack1.guid,
'default' => false,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand All @@ -128,6 +134,8 @@
{
'name' => stack2.name,
'description' => stack2.description,
'run_rootfs_image' => stack2.run_rootfs_image,
'build_rootfs_image' => stack2.build_rootfs_image,
'guid' => stack2.guid,
'default' => true,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand Down Expand Up @@ -165,6 +173,8 @@
{
'name' => stack1.name,
'description' => stack1.description,
'run_rootfs_image' => stack1.run_rootfs_image,
'build_rootfs_image' => stack1.build_rootfs_image,
'guid' => stack1.guid,
'default' => false,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand All @@ -179,6 +189,8 @@
{
'name' => stack3.name,
'description' => stack3.description,
'run_rootfs_image' => stack3.run_rootfs_image,
'build_rootfs_image' => stack3.build_rootfs_image,
'guid' => stack3.guid,
'default' => false,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand Down Expand Up @@ -216,6 +228,8 @@
{
'name' => stack2.name,
'description' => stack2.description,
'run_rootfs_image' => stack2.run_rootfs_image,
'build_rootfs_image' => stack2.build_rootfs_image,
'guid' => stack2.guid,
'default' => true,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand Down Expand Up @@ -267,6 +281,8 @@
{
'name' => stack1.name,
'description' => stack1.description,
'run_rootfs_image' => stack1.run_rootfs_image,
'build_rootfs_image' => stack1.build_rootfs_image,
'guid' => stack1.guid,
'default' => false,
'metadata' => {
Expand Down Expand Up @@ -301,6 +317,8 @@
{
'name' => stack.name,
'description' => stack.description,
'run_rootfs_image' => stack.run_rootfs_image,
'build_rootfs_image' => stack.build_rootfs_image,
'guid' => stack.guid,
'default' => false,
'metadata' => { 'labels' => {}, 'annotations' => {} },
Expand Down Expand Up @@ -617,6 +635,8 @@
{
'name' => 'the-name',
'description' => 'the-description',
'run_rootfs_image' => created_stack.run_rootfs_image,
'build_rootfs_image' => created_stack.build_rootfs_image,
'default' => false,
'metadata' => {
'labels' => {
Expand Down Expand Up @@ -679,6 +699,8 @@
{
'name' => stack.name,
'description' => stack.description,
'run_rootfs_image' => stack.run_rootfs_image,
'build_rootfs_image' => stack.build_rootfs_image,
'default' => false,
'metadata' => {
'labels' => {
Expand Down
16 changes: 15 additions & 1 deletion spec/unit/presenters/v3/stack_presenter_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,12 @@
require 'presenters/v3/stack_presenter'

RSpec.describe VCAP::CloudController::Presenters::V3::StackPresenter do
let(:stack) { VCAP::CloudController::Stack.make }
let(:stack) do
VCAP::CloudController::Stack.make(
run_rootfs_image: 'run-image',
build_rootfs_image: 'build-image',
)
end

let!(:release_label) do
VCAP::CloudController::StackLabelModel.make(
Expand Down Expand Up @@ -47,6 +52,8 @@
expect(result[:updated_at]).to eq(stack.updated_at)
expect(result[:name]).to eq(stack.name)
expect(result[:description]).to eq(stack.description)
expect(result[:run_rootfs_image]).to eq(stack.run_rootfs_image)
expect(result[:build_rootfs_image]).to eq(stack.build_rootfs_image)
expect(result[:default]).to eq(false)
expect(result[:metadata][:labels]).to eq('release' => 'stable', 'canberra.au/potato' => 'mashed')
expect(result[:metadata][:annotations]).to eq('altitude' => '14,412', 'maize' => 'hfcs')
Expand All @@ -57,12 +64,19 @@
context 'when optional fields are missing' do
before do
stack.description = nil
stack.run_rootfs_image = nil
stack.build_rootfs_image = nil
end

it 'still presents their keys with nil values' do
expect(result.fetch(:description)).to be_nil
end

it 'presents their fallback values' do
expect(result.fetch(:run_rootfs_image)).to eq(stack.name)
expect(result.fetch(:build_rootfs_image)).to eq(stack.name)
end

it 'still presents all other values' do
expect(result[:guid]).to eq(stack.guid)
expect(result[:created_at]).to eq(stack.created_at)
Expand Down

0 comments on commit fdc8c93

Please sign in to comment.