github.com/liamawhite/cli-with-i18n@v6.32.1-0.20171122084555-dede0a5c3448+incompatible/actor/v3action/organization_test.go (about)

     1  package v3action_test
     2  
     3  import (
     4  	"errors"
     5  	"net/url"
     6  
     7  	. "github.com/liamawhite/cli-with-i18n/actor/v3action"
     8  	"github.com/liamawhite/cli-with-i18n/actor/v3action/v3actionfakes"
     9  	"github.com/liamawhite/cli-with-i18n/api/cloudcontroller/ccv3"
    10  
    11  	. "github.com/onsi/ginkgo"
    12  	. "github.com/onsi/gomega"
    13  )
    14  
    15  var _ = Describe("Organization Actions", func() {
    16  	var (
    17  		actor                     *Actor
    18  		fakeCloudControllerClient *v3actionfakes.FakeCloudControllerClient
    19  	)
    20  
    21  	BeforeEach(func() {
    22  		fakeCloudControllerClient = new(v3actionfakes.FakeCloudControllerClient)
    23  		actor = NewActor(nil, fakeCloudControllerClient, nil)
    24  	})
    25  
    26  	Describe("GetOrganizationByName", func() {
    27  		Context("when the org exists", func() {
    28  			BeforeEach(func() {
    29  				fakeCloudControllerClient.GetOrganizationsReturns(
    30  					[]ccv3.Organization{
    31  						{
    32  							Name: "some-org-name",
    33  							GUID: "some-org-guid",
    34  						},
    35  					},
    36  					ccv3.Warnings{"some-warning"},
    37  					nil,
    38  				)
    39  			})
    40  
    41  			It("returns the organization and warnings", func() {
    42  				org, warnings, err := actor.GetOrganizationByName("some-org-name")
    43  				Expect(err).ToNot(HaveOccurred())
    44  				Expect(org).To(Equal(Organization{
    45  					Name: "some-org-name",
    46  					GUID: "some-org-guid",
    47  				}))
    48  				Expect(warnings).To(Equal(Warnings{"some-warning"}))
    49  
    50  				Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
    51  				expectedQuery := url.Values{
    52  					ccv3.NameFilter: []string{"some-org-name"},
    53  				}
    54  				query := fakeCloudControllerClient.GetOrganizationsArgsForCall(0)
    55  				Expect(query).To(Equal(expectedQuery))
    56  			})
    57  		})
    58  
    59  		Context("when the cloud controller client returns an error", func() {
    60  			var expectedError error
    61  
    62  			BeforeEach(func() {
    63  				expectedError = errors.New("I am a CloudControllerClient Error")
    64  				fakeCloudControllerClient.GetOrganizationsReturns(
    65  					[]ccv3.Organization{},
    66  					ccv3.Warnings{"some-warning"},
    67  					expectedError)
    68  			})
    69  
    70  			It("returns the warnings and the error", func() {
    71  				_, warnings, err := actor.GetOrganizationByName("some-org-name")
    72  				Expect(warnings).To(ConsistOf("some-warning"))
    73  				Expect(err).To(MatchError(expectedError))
    74  				Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
    75  				expectedQuery := url.Values{
    76  					ccv3.NameFilter: []string{"some-org-name"},
    77  				}
    78  				query := fakeCloudControllerClient.GetOrganizationsArgsForCall(0)
    79  				Expect(query).To(Equal(expectedQuery))
    80  			})
    81  		})
    82  	})
    83  
    84  	Context("when the org does not exist", func() {
    85  		BeforeEach(func() {
    86  			fakeCloudControllerClient.GetOrganizationsReturns(
    87  				[]ccv3.Organization{},
    88  				ccv3.Warnings{"some-warning"},
    89  				nil,
    90  			)
    91  		})
    92  
    93  		It("returns an OrganizationNotFoundError and the warnings", func() {
    94  			_, warnings, err := actor.GetOrganizationByName("some-org-name")
    95  			Expect(warnings).To(ConsistOf("some-warning"))
    96  			Expect(err).To(MatchError(OrganizationNotFoundError{Name: "some-org-name"}))
    97  			Expect(fakeCloudControllerClient.GetOrganizationsCallCount()).To(Equal(1))
    98  			expectedQuery := url.Values{
    99  				ccv3.NameFilter: []string{"some-org-name"},
   100  			}
   101  			query := fakeCloudControllerClient.GetOrganizationsArgsForCall(0)
   102  			Expect(query).To(Equal(expectedQuery))
   103  		})
   104  	})
   105  })