github.com/jghiloni/cli@v6.28.1-0.20170628223758-0ce05fe032a2+incompatible/actor/v2action/stack_test.go (about)

     1  package v2action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v2action"
     7  	"code.cloudfoundry.org/cli/actor/v2action/v2actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccerror"
     9  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv2"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Stack Actions", func() {
    15  	var (
    16  		actor                     *Actor
    17  		fakeCloudControllerClient *v2actionfakes.FakeCloudControllerClient
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		fakeCloudControllerClient = new(v2actionfakes.FakeCloudControllerClient)
    22  		actor = NewActor(fakeCloudControllerClient, nil)
    23  	})
    24  
    25  	Describe("GetStack", func() {
    26  		Context("when the CC API client does not return any errors", func() {
    27  			BeforeEach(func() {
    28  				fakeCloudControllerClient.GetStackReturns(
    29  					ccv2.Stack{
    30  						Name:        "some-stack",
    31  						Description: "some stack description",
    32  					},
    33  					ccv2.Warnings{"get-stack-warning"},
    34  					nil,
    35  				)
    36  			})
    37  
    38  			It("returns the stack and all warnings", func() {
    39  				stack, warnings, err := actor.GetStack("stack-guid")
    40  				Expect(err).NotTo(HaveOccurred())
    41  				Expect(warnings).To(ConsistOf("get-stack-warning"))
    42  				Expect(stack).To(Equal(Stack{
    43  					Name:        "some-stack",
    44  					Description: "some stack description",
    45  				}))
    46  			})
    47  		})
    48  
    49  		Context("when the stack does not exist", func() {
    50  			BeforeEach(func() {
    51  				fakeCloudControllerClient.GetStackReturns(
    52  					ccv2.Stack{},
    53  					nil,
    54  					ccerror.ResourceNotFoundError{},
    55  				)
    56  			})
    57  
    58  			It("returns a StackNotFoundError", func() {
    59  				_, _, err := actor.GetStack("stack-guid")
    60  				Expect(err).To(MatchError(StackNotFoundError{GUID: "stack-guid"}))
    61  			})
    62  		})
    63  
    64  		Context("when the CC API client returns an error", func() {
    65  			var expectedErr error
    66  
    67  			BeforeEach(func() {
    68  				expectedErr = errors.New("get-stack-error")
    69  				fakeCloudControllerClient.GetStackReturns(
    70  					ccv2.Stack{},
    71  					ccv2.Warnings{"stack-warning"},
    72  					expectedErr,
    73  				)
    74  			})
    75  
    76  			It("returns the error and warnings", func() {
    77  				_, warnings, err := actor.GetStack("stack-guid")
    78  				Expect(err).To(MatchError("get-stack-error"))
    79  				Expect(warnings).To(ConsistOf("stack-warning"))
    80  			})
    81  		})
    82  	})
    83  })