github.com/wanddynosios/cli/v8@v8.7.9-0.20240221182337-1a92e3a7017f/actor/v7action/info_test.go (about)

     1  package v7action_test
     2  
     3  import (
     4  	"errors"
     5  
     6  	. "code.cloudfoundry.org/cli/actor/v7action"
     7  	"code.cloudfoundry.org/cli/actor/v7action/v7actionfakes"
     8  	"code.cloudfoundry.org/cli/api/cloudcontroller/ccv3"
     9  	"code.cloudfoundry.org/cli/resources"
    10  	. "github.com/onsi/ginkgo"
    11  	. "github.com/onsi/gomega"
    12  )
    13  
    14  var _ = Describe("Info Actions", func() {
    15  	var (
    16  		actor                     *Actor
    17  		fakeCloudControllerClient *v7actionfakes.FakeCloudControllerClient
    18  	)
    19  
    20  	BeforeEach(func() {
    21  		fakeCloudControllerClient = new(v7actionfakes.FakeCloudControllerClient)
    22  		actor = NewActor(fakeCloudControllerClient, nil, nil, nil, nil, nil)
    23  	})
    24  
    25  	Describe("GetRootResponse", func() {
    26  		When("getting info is successful", func() {
    27  			BeforeEach(func() {
    28  				fakeCloudControllerClient.GetInfoReturns(
    29  					ccv3.Info{
    30  						Links: ccv3.InfoLinks{
    31  							LogCache: resources.APILink{HREF: "some-log-cache-url"},
    32  						},
    33  					},
    34  					ccv3.Warnings{"warning-1", "warning-2"},
    35  					nil,
    36  				)
    37  			})
    38  
    39  			It("returns all warnings and root info", func() {
    40  				rootInfo, warnings, err := actor.GetRootResponse()
    41  				Expect(err).ToNot(HaveOccurred())
    42  
    43  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
    44  
    45  				Expect(fakeCloudControllerClient.GetInfoCallCount()).To(Equal(1))
    46  				Expect(rootInfo.Links.LogCache.HREF).To(Equal("some-log-cache-url"))
    47  			})
    48  		})
    49  
    50  		When("the cloud controller client returns an error", func() {
    51  			var expectedErr error
    52  
    53  			BeforeEach(func() {
    54  				expectedErr = errors.New("I am a CloudControllerClient Error")
    55  				fakeCloudControllerClient.GetInfoReturns(
    56  					ccv3.Info{},
    57  					ccv3.Warnings{"warning-1", "warning-2"},
    58  					expectedErr,
    59  				)
    60  			})
    61  
    62  			It("returns the same error and all warnings", func() {
    63  				_, warnings, err := actor.GetRootResponse()
    64  				Expect(err).To(MatchError(expectedErr))
    65  				Expect(warnings).To(ConsistOf("warning-1", "warning-2"))
    66  			})
    67  		})
    68  	})
    69  })