code.cloudfoundry.org/cli@v7.1.0+incompatible/actor/pushaction/domain_test.go (about) 1 package pushaction_test 2 3 import ( 4 "errors" 5 6 "code.cloudfoundry.org/cli/actor/actionerror" 7 . "code.cloudfoundry.org/cli/actor/pushaction" 8 "code.cloudfoundry.org/cli/actor/pushaction/pushactionfakes" 9 "code.cloudfoundry.org/cli/actor/v2action" 10 11 . "github.com/onsi/ginkgo" 12 . "github.com/onsi/gomega" 13 ) 14 15 var _ = Describe("Domains", func() { 16 var ( 17 actor *Actor 18 fakeV2Actor *pushactionfakes.FakeV2Actor 19 ) 20 21 BeforeEach(func() { 22 actor, fakeV2Actor, _, _ = getTestPushActor() 23 }) 24 25 Describe("DefaultDomain", func() { 26 var ( 27 orgGUID string 28 defaultDomain v2action.Domain 29 warnings Warnings 30 executeErr error 31 ) 32 33 BeforeEach(func() { 34 orgGUID = "some-org-guid" 35 }) 36 37 JustBeforeEach(func() { 38 defaultDomain, warnings, executeErr = actor.DefaultDomain(orgGUID) 39 }) 40 41 When("retrieving the domains is successful", func() { 42 When("there is an external domain", func() { 43 BeforeEach(func() { 44 fakeV2Actor.GetOrganizationDomainsReturns([]v2action.Domain{ 45 { 46 Name: "private-domain.com", 47 GUID: "some-private-domain-guid", 48 Internal: true, 49 }, 50 { 51 Name: "private-domain-2.com", 52 GUID: "some-private-domain-guid-2", 53 }, 54 { 55 Name: "shared-domain.com", 56 GUID: "some-shared-domain-guid", 57 }, 58 }, 59 v2action.Warnings{"private-domain-warnings", "shared-domain-warnings"}, 60 nil, 61 ) 62 }) 63 64 It("returns the first external domain and warnings", func() { 65 Expect(executeErr).ToNot(HaveOccurred()) 66 Expect(warnings).To(ConsistOf("private-domain-warnings", "shared-domain-warnings")) 67 Expect(defaultDomain).To(Equal(v2action.Domain{ 68 Name: "private-domain-2.com", 69 GUID: "some-private-domain-guid-2", 70 })) 71 72 Expect(fakeV2Actor.GetOrganizationDomainsCallCount()).To(Equal(1)) 73 Expect(fakeV2Actor.GetOrganizationDomainsArgsForCall(0)).To(Equal(orgGUID)) 74 }) 75 }) 76 77 When("all the domains are internal", func() { 78 BeforeEach(func() { 79 fakeV2Actor.GetOrganizationDomainsReturns([]v2action.Domain{ 80 { 81 Name: "internal-domain-1.com", 82 GUID: "some-internal-domain-guid", 83 Internal: true, 84 }, 85 { 86 Name: "internal-domain-2.com", 87 GUID: "some-internal-domain-guid", 88 Internal: true, 89 }, 90 }, 91 v2action.Warnings{"warnings-1", "warnings-2"}, 92 nil, 93 ) 94 }) 95 96 It("returns an error and warnings", func() { 97 Expect(executeErr).To(MatchError(actionerror.NoDomainsFoundError{OrganizationGUID: orgGUID})) 98 Expect(warnings).To(ConsistOf("warnings-1", "warnings-2")) 99 }) 100 101 }) 102 }) 103 104 Context("no domains exist", func() { 105 BeforeEach(func() { 106 fakeV2Actor.GetOrganizationDomainsReturns([]v2action.Domain{}, v2action.Warnings{"private-domain-warnings", "shared-domain-warnings"}, nil) 107 }) 108 109 It("returns an error and warnings", func() { 110 Expect(executeErr).To(MatchError(actionerror.NoDomainsFoundError{OrganizationGUID: orgGUID})) 111 Expect(warnings).To(ConsistOf("private-domain-warnings", "shared-domain-warnings")) 112 }) 113 }) 114 115 When("retrieving the domains errors", func() { 116 var expectedErr error 117 118 BeforeEach(func() { 119 expectedErr = errors.New("whoops") 120 fakeV2Actor.GetOrganizationDomainsReturns([]v2action.Domain{}, v2action.Warnings{"private-domain-warnings", "shared-domain-warnings"}, expectedErr) 121 }) 122 123 It("returns errors and warnings", func() { 124 Expect(executeErr).To(MatchError(expectedErr)) 125 Expect(warnings).To(ConsistOf("private-domain-warnings", "shared-domain-warnings")) 126 }) 127 }) 128 }) 129 })