Skip to content
Open
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
1 change: 1 addition & 0 deletions actor/v7action/cloud_controller_client.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ type CloudControllerClient interface {
GetAppFeature(appGUID string, featureName string) (resources.ApplicationFeature, ccv3.Warnings, error)
GetStacks(query ...ccv3.Query) ([]resources.Stack, ccv3.Warnings, error)
GetStagingSecurityGroups(spaceGUID string, queries ...ccv3.Query) ([]resources.SecurityGroup, ccv3.Warnings, error)
UpdateStack(stackGUID string, state string) (resources.Stack, ccv3.Warnings, error)
GetTask(guid string) (resources.Task, ccv3.Warnings, error)
GetUser(userGUID string) (resources.User, ccv3.Warnings, error)
GetUsers(query ...ccv3.Query) ([]resources.User, ccv3.Warnings, error)
Expand Down
9 changes: 9 additions & 0 deletions actor/v7action/stack.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,3 +46,12 @@ func (actor Actor) GetStacks(labelSelector string) ([]resources.Stack, Warnings,

return stacks, Warnings(warnings), nil
}

func (actor Actor) UpdateStack(stackGUID string, state string) (resources.Stack, Warnings, error) {
stack, warnings, err := actor.CloudControllerClient.UpdateStack(stackGUID, state)
if err != nil {
return resources.Stack{}, Warnings(warnings), err
}

return stack, Warnings(warnings), nil
}
104 changes: 103 additions & 1 deletion actor/v7action/stack_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ var _ = Describe("Stack", func() {

Context("there are no errors", func() {

When("the stack exists", func() {
When("the stack exists without state", func() {
expectedStack := resources.Stack{
GUID: "some-stack-guid",
Name: "some-stack-name",
Expand Down Expand Up @@ -98,6 +98,43 @@ var _ = Describe("Stack", func() {
Expect(stack.GUID).To(Equal(expectedStack.GUID))
Expect(stack.Name).To(Equal(expectedStack.Name))
Expect(stack.Description).To(Equal(expectedStack.Description))
Expect(stack.State).To(Equal(""))
Expect(err).To(BeNil())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
})
})

When("the stack exists with state", func() {
expectedStack := resources.Stack{
GUID: "some-stack-guid",
Name: "some-stack-name",
Description: "Some stack desc",
State: "ACTIVE",
}

expectedParams := []ccv3.Query{
{Key: ccv3.NameFilter, Values: []string{"some-stack-name"}},
{Key: ccv3.PerPage, Values: []string{"1"}},
{Key: ccv3.Page, Values: []string{"1"}},
}

BeforeEach(func() {
fakeCloudControllerClient.GetStacksReturns(
[]resources.Stack{expectedStack},
ccv3.Warnings{"warning-1", "warning-2"},
nil,
)
})

It("returns the desired stack with state", func() {

actualParams := fakeCloudControllerClient.GetStacksArgsForCall(0)
Expect(actualParams).To(Equal(expectedParams))
Expect(fakeCloudControllerClient.GetStacksCallCount()).To(Equal(1))
Expect(stack.GUID).To(Equal(expectedStack.GUID))
Expect(stack.Name).To(Equal(expectedStack.Name))
Expect(stack.Description).To(Equal(expectedStack.Description))
Expect(stack.State).To(Equal(resources.StackStateActive))
Expect(err).To(BeNil())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
})
Expand Down Expand Up @@ -196,4 +233,69 @@ var _ = Describe("Stack", func() {
})
})
})

Describe("UpdateStack", func() {
var (
stackGUID string
state string
stack resources.Stack
warnings Warnings
executeErr error
)

BeforeEach(func() {
stackGUID = "some-stack-guid"
state = "DEPRECATED"
})

JustBeforeEach(func() {
stack, warnings, executeErr = actor.UpdateStack(stackGUID, state)
})

When("the cloud controller request is successful", func() {
BeforeEach(func() {
fakeCloudControllerClient.UpdateStackReturns(
resources.Stack{
GUID: "some-stack-guid",
Name: "some-stack",
Description: "some description",
State: "DEPRECATED",
},
ccv3.Warnings{"warning-1", "warning-2"},
nil,
)
})

It("returns the updated stack and warnings", func() {
Expect(executeErr).ToNot(HaveOccurred())
Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
Expect(stack).To(Equal(resources.Stack{
GUID: "some-stack-guid",
Name: "some-stack",
Description: "some description",
State: "DEPRECATED",
}))

Expect(fakeCloudControllerClient.UpdateStackCallCount()).To(Equal(1))
actualGUID, actualState := fakeCloudControllerClient.UpdateStackArgsForCall(0)
Expect(actualGUID).To(Equal(stackGUID))
Expect(actualState).To(Equal(state))
})
})

When("the cloud controller request fails", func() {
BeforeEach(func() {
fakeCloudControllerClient.UpdateStackReturns(
resources.Stack{},
ccv3.Warnings{"warning-1"},
errors.New("some-error"),
)
})

It("returns the error and warnings", func() {
Expect(executeErr).To(MatchError("some-error"))
Expect(warnings).To(ConsistOf("warning-1"))
})
})
})
})
Loading
Loading