当前位置: 首页>>代码示例>>Golang>>正文


Golang TestLogger.Logs方法代码示例

本文整理汇总了Golang中github.com/pivotal-golang/lager/lagertest.TestLogger.Logs方法的典型用法代码示例。如果您正苦于以下问题:Golang TestLogger.Logs方法的具体用法?Golang TestLogger.Logs怎么用?Golang TestLogger.Logs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在github.com/pivotal-golang/lager/lagertest.TestLogger的用法示例。


在下文中一共展示了TestLogger.Logs方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。

示例1:

			})

			It("logs the route deletion", func() {
				request = handlers.NewTestRequest(route)
				routesHandler.Delete(responseRecorder, request)

				data := map[string]interface{}{
					"ip":       "1.2.3.4",
					"log_guid": "",
					"port":     float64(7000),
					"route":    "post_here",
					"ttl":      float64(0),
				}
				log_data := map[string][]interface{}{"route_deletion": []interface{}{data}}

				Expect(logger.Logs()[0].Message).To(ContainSubstring("request"))
				Expect(logger.Logs()[0].Data["route_deletion"]).To(Equal(log_data["route_deletion"]))
			})

			Context("when the database deletion fails", func() {
				It("returns a 204 if the key was not found", func() {
					database.DeleteRouteReturns(db.DBError{Type: db.KeyNotFound, Message: "The specified route could not be found."})

					request = handlers.NewTestRequest(route)
					routesHandler.Delete(responseRecorder, request)

					Expect(responseRecorder.Code).To(Equal(http.StatusNoContent))
				})

				It("responds with a server error", func() {
					database.DeleteRouteReturns(errors.New("stuff broke"))
开发者ID:markstgodard,项目名称:routing-api,代码行数:31,代码来源:routes_handler_test.go

示例2:

			path := "/v2/service_instances/" + instanceID

			buffer := &bytes.Buffer{}
			json.NewEncoder(buffer).Encode(details)
			request, err := http.NewRequest("PUT", path, buffer)
			Expect(err).NotTo(HaveOccurred())
			request.Header.Add("Content-Type", "application/json")
			request.SetBasicAuth(credentials.Username, credentials.Password)

			response = r.Do(request)
		})
		return response
	}

	lastLogLine := func() lager.LogFormat {
		if len(brokerLogger.Logs()) == 0 {
			// better way to raise error?
			err := errors.New("expected some log lines but there were none!")
			Expect(err).NotTo(HaveOccurred())
		}

		return brokerLogger.Logs()[0]
	}

	BeforeEach(func() {
		fakeServiceBroker = &fakes.FakeServiceBroker{
			InstanceLimit: 3,
		}
		brokerLogger = lagertest.NewTestLogger("broker-api")
		brokerAPI = brokerapi.New(fakeServiceBroker, brokerLogger, credentials)
	})
开发者ID:allomov,项目名称:cf-subway,代码行数:31,代码来源:api_test.go

示例3:

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("LagerWriter", func() {
	var logger *lagertest.TestLogger
	var lagerWriter io.Writer

	BeforeEach(func() {
		logger = lagertest.NewTestLogger("test")
		lagerWriter = helpers.NewLagerWriter(logger)
	})

	It("writes the payload as lager.Data", func() {
		payload := []byte("Hello, world!\n")

		n, err := lagerWriter.Write(payload)
		Expect(err).NotTo(HaveOccurred())
		Expect(n).To(Equal(len(payload)))

		Expect(logger.Logs()).To(HaveLen(1))

		log := logger.Logs()[0]
		Expect(log.Source).To(Equal("test"))
		Expect(log.Message).To(Equal("test.write"))
		Expect(log.LogLevel).To(Equal(lager.INFO))
		Expect(log.Data).To(Equal(lager.Data{"payload": string(payload)}))
	})
})
开发者ID:benjaminharnett,项目名称:diego-ssh,代码行数:29,代码来源:lager_writer_test.go

示例4:

					Eventually(database.SaveRouteCallCount).Should(Equal(2))
					Eventually(func() models.Route { return database.SaveRouteArgsForCall(1) }).Should(Equal(route))
					Eventually(logger.Logs).Should(HaveLen(0))
				})
			})

			Context("when there are errors", func() {
				BeforeEach(func() {
					database.SaveRouteStub = func(route models.Route) error {
						return errors.New("beep boop, self destruct mode engaged")
					}
				})

				It("only logs the error once for each attempt", func() {

					Consistently(func() int { return len(logger.Logs()) }).Should(BeNumerically("<=", 1))
					Eventually(func() string {
						if len(logger.Logs()) > 0 {
							return logger.Logs()[0].Data["error"].(string)
						} else {
							return ""
						}
					}).Should(ContainSubstring("beep boop, self destruct mode engaged"))
				})
			})
		})

		Context("unregistration", func() {
			It("unregisters the routing api when a SIGTERM is received", func() {
				process.Signal(syscall.SIGTERM)
				Eventually(database.DeleteRouteCallCount).Should(Equal(1))
开发者ID:yingkitw,项目名称:gorouter,代码行数:31,代码来源:helpers_test.go

示例5: expectInvalidInput

func expectInvalidInput(responseRecorder *httptest.ResponseRecorder, database *fake_db.FakeDB, logger *lagertest.TestLogger) {
	Expect(responseRecorder.Code).To(Equal(http.StatusBadRequest))
	Expect(responseRecorder.Body.String()).To(ContainSubstring("Each tcp mapping requires a positive host port"))
	Expect(database.SaveRouteCallCount()).To(Equal(0))
	Expect(logger.Logs()[0].Message).To(ContainSubstring("error"))
}
开发者ID:krumts,项目名称:gorouter,代码行数:6,代码来源:tcp_route_mappings_handler_test.go

示例6:

					tcpRouteMappingsHandler.Upsert(responseRecorder, request)

					tcpMapping = db.NewTcpRouteMapping("router-group-guid-001", 52000, "1.2.3.4", 60000)

					routeData := map[string]interface{}{
						"router_group_guid": "router-group-guid-001",
						"external_port":     float64(52000),
					}
					data := map[string]interface{}{
						"host_ip":   "1.2.3.4",
						"host_port": float64(60000),
						"route":     routeData,
					}
					log_data := map[string][]interface{}{"tcp_mapping_creation": []interface{}{data}}

					Expect(logger.Logs()[0].Message).To(ContainSubstring("request"))
					Expect(logger.Logs()[0].Data["tcp_mapping_creation"]).To(Equal(log_data["tcp_mapping_creation"]))
				})

				Context("when database fails to save", func() {
					BeforeEach(func() {
						database.SaveTcpRouteMappingReturns(errors.New("stuff broke"))
					})
					It("responds with a server error", func() {
						request = handlers.NewTestRequest(tcpMappings)
						tcpRouteMappingsHandler.Upsert(responseRecorder, request)

						Expect(responseRecorder.Code).To(Equal(http.StatusInternalServerError))
						Expect(responseRecorder.Body.String()).To(ContainSubstring("stuff broke"))
					})
				})
开发者ID:krumts,项目名称:gorouter,代码行数:31,代码来源:tcp_route_mappings_handler_test.go

示例7:

	}

	makeInstanceProvisioningRequestWithAcceptsIncomplete := func(instanceID string, details brokerapi.ProvisionDetails, acceptsIncomplete bool) *testflight.Response {
		var acceptsIncompleteFlag string

		if acceptsIncomplete {
			acceptsIncompleteFlag = "?accepts_incomplete=true"
		} else {
			acceptsIncompleteFlag = "?accepts_incomplete=false"
		}

		return makeInstanceProvisioningRequest(instanceID, details, acceptsIncompleteFlag)
	}

	lastLogLine := func() lager.LogFormat {
		noOfLogLines := len(brokerLogger.Logs())
		if noOfLogLines == 0 {
			// better way to raise error?
			err := errors.New("expected some log lines but there were none")
			Expect(err).NotTo(HaveOccurred())
		}

		return brokerLogger.Logs()[noOfLogLines-1]
	}

	BeforeEach(func() {
		fakeServiceBroker = &fakes.FakeServiceBroker{
			InstanceLimit: 3,
		}
		brokerLogger = lagertest.NewTestLogger("broker-api")
		brokerAPI = brokerapi.New(fakeServiceBroker, brokerLogger, credentials)
开发者ID:cfmobile,项目名称:brokerapi,代码行数:31,代码来源:api_test.go

示例8:

			))
		})

		It("changes the container's state to active", func() {
			Expect(container.State()).To(Equal(linux_backend.StateBorn))

			err := container.Start()
			Expect(err).ToNot(HaveOccurred())

			Expect(container.State()).To(Equal(linux_backend.StateActive))
		})

		It("should log before and after", func() {
			Expect(container.Start()).To(Succeed())

			logs := logger.Logs()
			expectedData := lager.Data{"handle": "some-handle"}
			Expect(logs).To(ContainLogWithData("linux-container.start.iptables-setup-starting", expectedData))
			Expect(logs).To(ContainLogWithData("linux-container.start.iptables-setup-ended", expectedData))
			Expect(logs).To(ContainLogWithData("linux-container.start.wshd-start-starting", expectedData))
			Expect(logs).To(ContainLogWithData("linux-container.start.wshd-start-ended", expectedData))
		})

		Context("when start.sh fails", func() {
			nastyError := errors.New("oh no!")

			JustBeforeEach(func() {
				fakeRunner.WhenRunning(
					fake_command_runner.CommandSpec{
						Path: containerDir + "/start.sh",
					}, func(*exec.Cmd) error {
开发者ID:nagyistoce,项目名称:garden-linux,代码行数:31,代码来源:linux_container_test.go

示例9:

			originalMigration := func(otx migration.LimitedTx) error {
				_, err := otx.Exec(`SELECT 1`)
				if err != nil {
					return err
				}

				return nil
			}

			newMigration := migrations.WithLogger(logger, originalMigration)
			newMigration(tx)

			Expect(logger).To(gbytes.Say("starting-migration"))
			Expect(logger).To(gbytes.Say("finishing-migration"))

			Expect(logger.Logs()[0].LogLevel).To(Equal(lager.INFO))
			Expect(logger.Logs()[1].LogLevel).To(Equal(lager.INFO))
		})

		It("logs the time that the migration took to apply", func() {
			tx := new(fakes.FakeLimitedTx)

			originalMigration := func(otx migration.LimitedTx) error {
				time.Sleep(1 * time.Millisecond)
				return nil
			}

			newMigration := migrations.WithLogger(logger, originalMigration)
			newMigration(tx)

			Expect(logger).To(gbytes.Say("finishing-migration"))
开发者ID:ACPK,项目名称:atc,代码行数:31,代码来源:log_test.go


注:本文中的github.com/pivotal-golang/lager/lagertest.TestLogger.Logs方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。