github.com/jenspinney/cli@v6.42.1-0.20190207184520-7450c600020e+incompatible/api/uaa/resources_test.go (about) 1 package uaa_test 2 3 import ( 4 "net/http" 5 6 . "code.cloudfoundry.org/cli/api/uaa" 7 "code.cloudfoundry.org/cli/api/uaa/uaafakes" 8 . "github.com/onsi/ginkgo" 9 . "github.com/onsi/gomega" 10 . "github.com/onsi/gomega/ghttp" 11 ) 12 13 var _ = Describe("SetupResources", func() { 14 var ( 15 client *Client 16 fakeConfig *uaafakes.FakeConfig 17 18 setupResourcesErr error 19 ) 20 21 BeforeEach(func() { 22 fakeConfig = NewTestConfig() 23 client = NewClient(fakeConfig) 24 }) 25 26 JustBeforeEach(func() { 27 setupResourcesErr = client.SetupResources(server.URL()) 28 }) 29 30 When("the authentication server returns an error", func() { 31 BeforeEach(func() { 32 server.AppendHandlers( 33 CombineHandlers( 34 VerifyRequest(http.MethodGet, "/login"), 35 RespondWith(http.StatusNotFound, `{"errors": [{}]}`, nil), 36 ), 37 ) 38 }) 39 40 It("returns the error", func() { 41 Expect(setupResourcesErr).To(HaveOccurred()) 42 Expect(fakeConfig.SetUAAEndpointCallCount()).To(Equal(0)) 43 }) 44 }) 45 46 When("the request succeeds", func() { 47 Context("and the UAA field is populated", func() { 48 BeforeEach(func() { 49 response := `{ 50 "app": { 51 "version": "sem.var" 52 }, 53 "links": { 54 "uaa": "https://uaa.bosh-lite.com" 55 } 56 }` 57 58 server.AppendHandlers( 59 CombineHandlers( 60 VerifyRequest(http.MethodGet, "/login"), 61 RespondWith(http.StatusOK, response, nil), 62 ), 63 ) 64 }) 65 66 It("sets the UAA endpoint to the UAA link and does not return an error", func() { 67 Expect(setupResourcesErr).ToNot(HaveOccurred()) 68 Expect(client.UAALink()).To(Equal("https://uaa.bosh-lite.com")) 69 Expect(client.APIVersion()).To(Equal("sem.var")) 70 71 Expect(fakeConfig.SetUAAEndpointCallCount()).To(Equal(1)) 72 Expect(fakeConfig.SetUAAEndpointArgsForCall(0)).To(Equal("https://uaa.bosh-lite.com")) 73 }) 74 }) 75 76 When("the UAA field is not populated", func() { 77 BeforeEach(func() { 78 response := `{ 79 "links": {} 80 }` 81 82 server.AppendHandlers( 83 CombineHandlers( 84 VerifyRequest(http.MethodGet, "/login"), 85 RespondWith(http.StatusOK, response, nil), 86 ), 87 ) 88 }) 89 90 It("sets the UAA endpoint to the bootstrap endpoint and does not return an error", func() { 91 Expect(setupResourcesErr).ToNot(HaveOccurred()) 92 Expect(fakeConfig.SetUAAEndpointCallCount()).To(Equal(1)) 93 Expect(fakeConfig.SetUAAEndpointArgsForCall(0)).To(Equal(server.URL())) 94 }) 95 }) 96 }) 97 })