本文整理汇总了Golang中github.com/cloudfoundry/bosh-agent/internal/github.com/pivotal-golang/clock/fakeclock.FakeClock.Now方法的典型用法代码示例。如果您正苦于以下问题:Golang FakeClock.Now方法的具体用法?Golang FakeClock.Now怎么用?Golang FakeClock.Now使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/cloudfoundry/bosh-agent/internal/github.com/pivotal-golang/clock/fakeclock.FakeClock
的用法示例。
在下文中一共展示了FakeClock.Now方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1:
sshMsg,
settingsService,
uuidGenerator,
timeService,
logger,
)
uuidGenerator.GeneratedUUID = "fake-uuid"
builtAlert, err := sshAdapter.Alert()
Expect(err).ToNot(HaveOccurred())
Expect(builtAlert.Title).To(Equal(expectedTitle))
Expect(builtAlert.ID).To(Equal("fake-uuid"))
Expect(builtAlert.Severity).To(Equal(SeverityWarning))
Expect(builtAlert.Summary).To(Equal(msgContent))
Expect(builtAlert.CreatedAt).To(Equal(timeService.Now().Unix()))
}
It("Returns logout when the user disconnects", func() {
itAdaptsMessage("Received disconnect from 9.9.9.9: 11: disconnected by user", "SSH Logout")
})
It("Returns login when login is successful (publickey)", func() {
itAdaptsMessage("Accepted publickey for vagrant from 9.9.9.9 port 58850 ssh2: RSA fake-rsa-key", "SSH Login")
})
It("Returns login when login is successful (password)", func() {
itAdaptsMessage("Accepted password for vcap from 9.9.9.9 port 63696 ssh2", "SSH Login")
})
It("Returns preauth connection closed when the connection is closed during preauth", func() {
示例2: init
func init() {
Describe("Agent", func() {
var (
logger boshlog.Logger
handler *fakembus.FakeHandler
platform *fakeplatform.FakePlatform
actionDispatcher *fakeagent.FakeActionDispatcher
jobSupervisor *fakejobsuper.FakeJobSupervisor
specService *fakeas.FakeV1Service
syslogServer *fakesyslog.FakeServer
settingsService *fakesettings.FakeSettingsService
uuidGenerator *fakeuuid.FakeGenerator
timeService *fakeclock.FakeClock
agent Agent
)
BeforeEach(func() {
logger = boshlog.NewLogger(boshlog.LevelNone)
handler = &fakembus.FakeHandler{}
platform = fakeplatform.NewFakePlatform()
actionDispatcher = &fakeagent.FakeActionDispatcher{}
jobSupervisor = fakejobsuper.NewFakeJobSupervisor()
specService = fakeas.NewFakeV1Service()
syslogServer = &fakesyslog.FakeServer{}
settingsService = &fakesettings.FakeSettingsService{}
uuidGenerator = &fakeuuid.FakeGenerator{}
timeService = fakeclock.NewFakeClock(time.Now())
agent = New(
logger,
handler,
platform,
actionDispatcher,
jobSupervisor,
specService,
syslogServer,
5*time.Millisecond,
settingsService,
uuidGenerator,
timeService,
)
})
Describe("Run", func() {
It("lets dispatcher handle requests arriving via handler", func() {
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
expectedResp := boshhandler.NewValueResponse("pong")
actionDispatcher.DispatchResp = expectedResp
req := boshhandler.NewRequest("fake-reply", "fake-action", []byte("fake-payload"))
resp := handler.RunFunc(req)
Expect(actionDispatcher.DispatchReq).To(Equal(req))
Expect(resp).To(Equal(expectedResp))
})
It("resumes persistent actions *before* dispatching new requests", func() {
resumedBeforeStartingToDispatch := false
handler.RunCallBack = func() {
resumedBeforeStartingToDispatch = actionDispatcher.ResumedPreviouslyDispatchedTasks
}
err := agent.Run()
Expect(err).ToNot(HaveOccurred())
Expect(resumedBeforeStartingToDispatch).To(BeTrue())
})
Context("when heartbeats can be sent", func() {
BeforeEach(func() {
handler.KeepOnRunning()
})
BeforeEach(func() {
jobName := "fake-job"
jobIndex := 1
specService.Spec = boshas.V1ApplySpec{
JobSpec: boshas.JobSpec{Name: &jobName},
Index: &jobIndex,
}
jobSupervisor.StatusStatus = "fake-state"
platform.FakeVitalsService.GetVitals = boshvitals.Vitals{
Load: []string{"a", "b", "c"},
}
})
expectedJobName := "fake-job"
expectedJobIndex := 1
expectedHb := Heartbeat{
Job: &expectedJobName,
Index: &expectedJobIndex,
JobState: "fake-state",
Vitals: boshvitals.Vitals{Load: []string{"a", "b", "c"}},
}
It("sends initial heartbeat", func() {
// Configure periodic heartbeat every 5 hours
// so that we are sure that we will not receive it
//.........这里部分代码省略.........