github.com/dcarley/cf-cli@v6.24.1-0.20170220111324-4225ff346898+incompatible/api/cloudcontroller/ccv2/domain_test.go (about) 1 package ccv2_test 2 3 import ( 4 "net/http" 5 6 "code.cloudfoundry.org/cli/api/cloudcontroller" 7 . "code.cloudfoundry.org/cli/api/cloudcontroller/ccv2" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("Domain", func() { 14 var client *Client 15 16 BeforeEach(func() { 17 client = NewTestClient() 18 }) 19 20 Describe("GetSharedDomain", func() { 21 Context("when the shared domain exists", func() { 22 BeforeEach(func() { 23 response := `{ 24 "metadata": { 25 "guid": "shared-domain-guid", 26 "updated_at": null 27 }, 28 "entity": { 29 "name": "shared-domain-1.com" 30 } 31 }` 32 server.AppendHandlers( 33 CombineHandlers( 34 VerifyRequest(http.MethodGet, "/v2/shared_domains/shared-domain-guid"), 35 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 36 ), 37 ) 38 }) 39 40 It("returns the shared domain and all warnings", func() { 41 domain, warnings, err := client.GetSharedDomain("shared-domain-guid") 42 Expect(err).NotTo(HaveOccurred()) 43 Expect(domain).To(Equal(Domain{Name: "shared-domain-1.com", GUID: "shared-domain-guid"})) 44 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 45 }) 46 }) 47 48 Context("when the shared domain does not exist", func() { 49 BeforeEach(func() { 50 response := `{ 51 "code": 130002, 52 "description": "The domain could not be found: shared-domain-guid", 53 "error_code": "CF-DomainNotFound" 54 }` 55 server.AppendHandlers( 56 CombineHandlers( 57 VerifyRequest(http.MethodGet, "/v2/shared_domains/shared-domain-guid"), 58 RespondWith(http.StatusNotFound, response), 59 ), 60 ) 61 }) 62 63 It("returns an error", func() { 64 domain, _, err := client.GetSharedDomain("shared-domain-guid") 65 Expect(err).To(MatchError(cloudcontroller.ResourceNotFoundError{ 66 Message: "The domain could not be found: shared-domain-guid", 67 })) 68 Expect(domain).To(Equal(Domain{})) 69 }) 70 }) 71 }) 72 73 Describe("GetPrivateDomain", func() { 74 Context("when the private domain exists", func() { 75 BeforeEach(func() { 76 response := `{ 77 "metadata": { 78 "guid": "private-domain-guid", 79 "updated_at": null 80 }, 81 "entity": { 82 "name": "private-domain-1.com" 83 } 84 }` 85 server.AppendHandlers( 86 CombineHandlers( 87 VerifyRequest(http.MethodGet, "/v2/private_domains/private-domain-guid"), 88 RespondWith(http.StatusOK, response, http.Header{"X-Cf-Warnings": {"this is a warning"}}), 89 ), 90 ) 91 }) 92 93 It("returns the private domain and all warnings", func() { 94 domain, warnings, err := client.GetPrivateDomain("private-domain-guid") 95 Expect(err).NotTo(HaveOccurred()) 96 Expect(domain).To(Equal(Domain{Name: "private-domain-1.com", GUID: "private-domain-guid"})) 97 Expect(warnings).To(ConsistOf(Warnings{"this is a warning"})) 98 }) 99 }) 100 101 Context("when the private domain does not exist", func() { 102 BeforeEach(func() { 103 response := `{ 104 "code": 130002, 105 "description": "The domain could not be found: private-domain-guid", 106 "error_code": "CF-DomainNotFound" 107 }` 108 server.AppendHandlers( 109 CombineHandlers( 110 VerifyRequest(http.MethodGet, "/v2/private_domains/private-domain-guid"), 111 RespondWith(http.StatusNotFound, response), 112 ), 113 ) 114 }) 115 116 It("returns an error", func() { 117 domain, _, err := client.GetPrivateDomain("private-domain-guid") 118 Expect(err).To(MatchError(cloudcontroller.ResourceNotFoundError{ 119 Message: "The domain could not be found: private-domain-guid", 120 })) 121 Expect(domain).To(Equal(Domain{})) 122 }) 123 }) 124 }) 125 })