本文整理汇总了Golang中github.com/turnkey-commerce/go-ping-sites/database.Site.UpdateSiteFirstPing方法的典型用法代码示例。如果您正苦于以下问题:Golang Site.UpdateSiteFirstPing方法的具体用法?Golang Site.UpdateSiteFirstPing怎么用?Golang Site.UpdateSiteFirstPing使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/turnkey-commerce/go-ping-sites/database.Site
的用法示例。
在下文中一共展示了Site.UpdateSiteFirstPing方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestUpdateSiteStatus
// TestUpdateSiteStatus tests updating the up/down status of the site.
func TestUpdateSiteStatus(t *testing.T) {
db, err := database.InitializeTestDB("")
if err != nil {
t.Fatal("Failed to create database:", err)
}
defer db.Close()
// First create a site to update status.
s := database.Site{SiteID: 1, Name: "Test", IsActive: true, URL: "http://www.google.com", PingIntervalSeconds: 60, TimeoutSeconds: 30}
err = s.CreateSite(db)
if err != nil {
t.Fatal("Failed to create new site:", err)
}
// Update the status of the site to down
err = s.UpdateSiteStatus(db, false)
if err != nil {
t.Fatal("Failed to update site status:", err)
}
//Get the saved site
var updatedSite database.Site
err = updatedSite.GetSite(db, s.SiteID)
if err != nil {
t.Fatal("Failed to retrieve updated site:", err)
}
if updatedSite.IsSiteUp != false {
t.Errorf("Site status should be down.")
}
// Update the status of the site to up
err = s.UpdateSiteStatus(db, true)
if err != nil {
t.Fatal("Failed to update site status:", err)
}
// Update the first ping time of the site.
firstPingTime := time.Date(2015, time.November, 10, 23, 22, 22, 00, time.UTC)
err = s.UpdateSiteFirstPing(db, firstPingTime)
if err != nil {
t.Fatal("Failed to update first ping time:", err)
}
err = updatedSite.GetSite(db, s.SiteID)
if err != nil {
t.Fatal("Failed to retrieve updated site:", err)
}
if updatedSite.IsSiteUp != true {
t.Errorf("Site status should be up.")
}
if updatedSite.FirstPing != firstPingTime {
t.Errorf("Site first ping time %s does not match input %s.", updatedSite.FirstPing, firstPingTime)
}
}