github.com/swisscom/cloudfoundry-cli@v7.1.0+incompatible/actor/v2action/stack_test.go (about) 1 package v2action_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 . "code.cloudfoundry.org/cli/actor/v2action" 8 "code.cloudfoundry.org/cli/actor/v2action/v2actionfakes" 9 "code.cloudfoundry.org/cli/api/cloudcontroller/ccerror" 10 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 11 "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2/constant" 12 . "github.com/onsi/ginkgo" 13 . "github.com/onsi/gomega" 14 ) 15 16 var _ = Describe("Stack Actions", func() { 17 var ( 18 actor *Actor 19 fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient 20 ) 21 22 BeforeEach(func() { 23 fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient) 24 actor = NewActor(fakeCloudControllerClient, nil, nil) 25 }) 26 27 Describe("GetStack", func() { 28 When("the CC API client does not return any errors", func() { 29 BeforeEach(func() { 30 fakeCloudControllerClient.GetStackReturns( 31 ccv2.Stack{ 32 Name: "some-stack", 33 Description: "some stack description", 34 }, 35 ccv2.Warnings{"get-stack-warning"}, 36 nil, 37 ) 38 }) 39 40 It("returns the stack and all warnings", func() { 41 stack, warnings, err := actor.GetStack("stack-guid") 42 Expect(err).NotTo(HaveOccurred()) 43 Expect(warnings).To(ConsistOf("get-stack-warning")) 44 Expect(stack).To(Equal(Stack{ 45 Name: "some-stack", 46 Description: "some stack description", 47 })) 48 }) 49 }) 50 51 When("the stack does not exist", func() { 52 BeforeEach(func() { 53 fakeCloudControllerClient.GetStackReturns( 54 ccv2.Stack{}, 55 nil, 56 ccerror.ResourceNotFoundError{}, 57 ) 58 }) 59 60 It("returns a StackNotFoundError", func() { 61 _, _, err := actor.GetStack("stack-guid") 62 Expect(err).To(MatchError(actionerror.StackNotFoundError{GUID: "stack-guid"})) 63 }) 64 }) 65 66 When("the CC API client returns an error", func() { 67 var expectedErr error 68 69 BeforeEach(func() { 70 expectedErr = errors.New("get-stack-error") 71 fakeCloudControllerClient.GetStackReturns( 72 ccv2.Stack{}, 73 ccv2.Warnings{"stack-warning"}, 74 expectedErr, 75 ) 76 }) 77 78 It("returns the error and warnings", func() { 79 _, warnings, err := actor.GetStack("stack-guid") 80 Expect(err).To(MatchError("get-stack-error")) 81 Expect(warnings).To(ConsistOf("stack-warning")) 82 }) 83 }) 84 }) 85 86 Describe("GetStackByName", func() { 87 When("the CC API client does not return any errors", func() { 88 When("it returns one stack", func() { 89 BeforeEach(func() { 90 fakeCloudControllerClient.GetStacksReturns( 91 []ccv2.Stack{{ 92 Name: "some-stack", 93 Description: "some stack description", 94 }}, 95 ccv2.Warnings{"get-stacks-warning"}, 96 nil, 97 ) 98 }) 99 100 It("returns the stack and all warnings", func() { 101 stack, warnings, err := actor.GetStackByName("some-stack") 102 Expect(err).NotTo(HaveOccurred()) 103 Expect(warnings).To(ConsistOf("get-stacks-warning")) 104 Expect(stack).To(Equal(Stack{ 105 Name: "some-stack", 106 Description: "some stack description", 107 })) 108 109 Expect(fakeCloudControllerClient.GetStacksCallCount()).To(Equal(1)) 110 Expect(fakeCloudControllerClient.GetStacksArgsForCall(0)).To(Equal([]ccv2.Filter{ 111 { 112 Type: constant.NameFilter, 113 Operator: constant.EqualOperator, 114 Values: []string{"some-stack"}, 115 }, 116 })) 117 }) 118 }) 119 120 When("it returns no stacks", func() { 121 BeforeEach(func() { 122 fakeCloudControllerClient.GetStacksReturns( 123 []ccv2.Stack{}, 124 ccv2.Warnings{"get-stacks-warning"}, 125 nil, 126 ) 127 }) 128 129 It("returns a StackNotFoundError", func() { 130 _, warnings, err := actor.GetStackByName("some-stack") 131 Expect(err).To(MatchError(actionerror.StackNotFoundError{Name: "some-stack"})) 132 Expect(warnings).To(ConsistOf("get-stacks-warning")) 133 }) 134 }) 135 }) 136 137 When("the stack does not exist", func() { 138 BeforeEach(func() { 139 fakeCloudControllerClient.GetStackReturns( 140 ccv2.Stack{}, 141 nil, 142 ccerror.ResourceNotFoundError{}, 143 ) 144 }) 145 146 It("returns a StackNotFoundError", func() { 147 _, _, err := actor.GetStack("stack-guid") 148 Expect(err).To(MatchError(actionerror.StackNotFoundError{GUID: "stack-guid"})) 149 }) 150 }) 151 152 When("the CC API client returns an error", func() { 153 var expectedErr error 154 155 BeforeEach(func() { 156 expectedErr = errors.New("get-stack-error") 157 fakeCloudControllerClient.GetStackReturns( 158 ccv2.Stack{}, 159 ccv2.Warnings{"stack-warning"}, 160 expectedErr, 161 ) 162 }) 163 164 It("returns the error and warnings", func() { 165 _, warnings, err := actor.GetStack("stack-guid") 166 Expect(err).To(MatchError("get-stack-error")) 167 Expect(warnings).To(ConsistOf("stack-warning")) 168 }) 169 }) 170 }) 171 })