Expect(request.URL.RawQuery).To(Equal("app=my-app-guid")) Expect(request.Method).To(Equal("GET")) Expect(request.Header.Get("Authorization")).To(ContainSubstring("BEARER my_access_token")) for _, msg := range messagesToSend { conn.Write(msg) } time.Sleep(time.Duration(50) * time.Millisecond) conn.Close() } testServer = httptest.NewTLSServer(websocket.Handler(requestHandler.handlerFunc)) configRepo = testconfig.NewRepositoryWithDefaults() configRepo.SetApiEndpoint("https://localhost") configRepo.SetLoggregatorEndpoint(strings.Replace(testServer.URL, "https", "wss", 1)) repo := NewLoggregatorLogsRepository(configRepo) logsRepo = &repo logsRepo.AddTrustedCerts(testServer.TLS.Certificates) }) AfterEach(func() { testServer.Close() }) Describe("RecentLogsFor", func() { BeforeEach(func() { err := logsRepo.RecentLogsFor("my-app-guid", func() {}, logChan) Expect(err).NotTo(HaveOccurred()) close(logChan)
}) Describe("getting API endpoints from a saved config", func() { It("TestGetCloudControllerEndpoint", func() { config.SetApiEndpoint("http://api.example.com") repo := NewEndpointRepository(config, net.NewCloudControllerGateway()) endpoint, apiResponse := repo.GetCloudControllerEndpoint() Expect(apiResponse.IsSuccessful()).To(BeTrue()) Expect(endpoint).To(Equal("http://api.example.com")) }) It("TestGetLoggregatorEndpoint", func() { config.SetLoggregatorEndpoint("wss://loggregator.example.com:4443") repo := NewEndpointRepository(config, net.NewCloudControllerGateway()) endpoint, apiResponse := repo.GetLoggregatorEndpoint() Expect(apiResponse.IsSuccessful()).To(BeTrue()) Expect(endpoint).To(Equal("wss://loggregator.example.com:4443")) }) Describe("when the loggregator endpoint is not saved in the config (old CC)", func() { BeforeEach(func() { config.SetLoggregatorEndpoint("") }) It("extrapolates the loggregator URL based on the API URL (SSL API)", func() {
testapi "testhelpers/api" testconfig "testhelpers/configuration" "time" ) var _ = Describe("loggregator logs repository", func() { var ( fakeConsumer *testapi.FakeLoggregatorConsumer logsRepo *LoggregatorLogsRepository configRepo configuration.ReadWriter ) BeforeEach(func() { fakeConsumer = testapi.NewFakeLoggregatorConsumer() configRepo = testconfig.NewRepositoryWithDefaults() configRepo.SetLoggregatorEndpoint("loggregator-server.test.com") configRepo.SetAccessToken("the-access-token") repo := NewLoggregatorLogsRepository(configRepo, fakeConsumer) logsRepo = &repo }) Describe("RecentLogsFor", func() { Context("when an error occurs", func() { BeforeEach(func() { fakeConsumer.RecentReturns.Err = errors.New("oops") }) It("returns the error", func() { _, err := logsRepo.RecentLogsFor("app-guid") Expect(err).To(Equal(errors.New("oops"))) })