本文整理汇总了Golang中github.com/turnkey-commerce/go-ping-sites/database.Site类的典型用法代码示例。如果您正苦于以下问题:Golang Site类的具体用法?Golang Site怎么用?Golang Site使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Site类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: TestCreateUniqueSite
// TestCreateUniqueSite tests that the same URL and Site Name can't be entered twice.
func TestCreateUniqueSite(t *testing.T) {
var err error
db, err := database.InitializeTestDB("")
if err != nil {
t.Fatal("Failed to create database:", err)
}
defer db.Close()
s := database.Site{Name: "Test", IsActive: true, URL: "http://www.test.com",
PingIntervalSeconds: 60, TimeoutSeconds: 30}
err = s.CreateSite(db)
if err != nil {
t.Fatal("Failed to create new site:", err)
}
//Test where the URL is the same and the Name is different should fail uniqueness constraint.
s2 := database.Site{Name: "Test2", IsActive: true, URL: "http://www.test.com",
PingIntervalSeconds: 60, TimeoutSeconds: 30}
err = s2.CreateSite(db)
if err == nil {
t.Fatal("Should throw uniqueness constraint error for URL.")
}
//Test where the Name is the same and the URL is different should fail with uniqueness constraint.
s3 := database.Site{Name: "Test", IsActive: true, URL: "http://www.test.edu",
PingIntervalSeconds: 60, TimeoutSeconds: 30}
err = s3.CreateSite(db)
if err == nil {
t.Fatal("Should throw uniqueness constraint error for Name.")
}
}
示例2: addContactToSite
func addContactToSite(controller *contactsController, contactID int64, siteID int64) error {
var site database.Site
err := site.GetSite(controller.DB, siteID)
if err != nil {
return err
}
err = site.AddContactToSite(controller.DB, contactID)
if err != nil {
return err
}
return nil
}
示例3: removeContactFromSite
func removeContactFromSite(controller *contactsController, contactID int64, siteID int64) error {
var site database.Site
err := site.GetSite(controller.DB, siteID)
if err != nil {
return err
}
err = site.RemoveContactFromSite(controller.DB, contactID)
if err != nil {
return err
}
return nil
}
示例4: newPost
func (controller *sitesController) newPost(rw http.ResponseWriter, req *http.Request) (int, error) {
err := req.ParseForm()
if err != nil {
return http.StatusInternalServerError, err
}
decoder := schema.NewDecoder()
// Ignore unknown keys to prevent errors from the CSRF token.
decoder.IgnoreUnknownKeys(true)
formSite := new(viewmodels.SitesEditViewModel)
err = decoder.Decode(formSite, req.PostForm)
if err != nil {
return http.StatusInternalServerError, err
}
valErrors := validateSiteForm(formSite)
if len(valErrors) > 0 {
isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer)
var contacts database.Contacts
err = contacts.GetContacts(controller.DB)
if err != nil {
return http.StatusInternalServerError, err
}
vm := viewmodels.NewSiteViewModel(formSite, contacts, isAuthenticated, user, valErrors)
vm.CsrfField = csrf.TemplateField(req)
return http.StatusOK, controller.newTemplate.Execute(rw, vm)
}
site := database.Site{}
viewmodels.MapSiteVMtoDB(formSite, &site)
err = site.CreateSite(controller.DB)
if err != nil {
return http.StatusInternalServerError, err
}
//Add any selected contacts
for _, contactSelID := range formSite.SelectedContacts {
err = site.AddContactToSite(controller.DB, contactSelID)
if err != nil {
return http.StatusInternalServerError, err
}
}
// Refresh the pinger with the changes.
err = controller.pinger.UpdateSiteSettings()
if err != nil {
return http.StatusInternalServerError, err
}
http.Redirect(rw, req, "/settings", http.StatusSeeOther)
return http.StatusSeeOther, nil
}
示例5: getTestSite
// Create the struct for the Site and its contacts used for testing.
func getTestSite() database.Site {
s1 := database.Site{Name: "Test", IsActive: true, URL: "http://www.google.com",
PingIntervalSeconds: 2, TimeoutSeconds: 1}
// Create first contact
c1 := database.Contact{Name: "Joe Contact", EmailAddress: "[email protected]", SmsNumber: "5125551212",
SmsActive: false, EmailActive: true}
// Create second contact
c2 := database.Contact{Name: "Jack Contact", EmailAddress: "[email protected]", SmsNumber: "5125551213",
SmsActive: true, EmailActive: false}
// Add the contacts to the sites
s1.Contacts = append(s1.Contacts, c1, c2)
return s1
}
示例6: TestSavePings
// TestGetSites tests the saving of the ping information to the DB.
func TestSavePings(t *testing.T) {
db, err := database.InitializeTestDB("")
if err != nil {
t.Fatal("Failed to create database:", err)
}
defer db.Close()
s1 := database.Site{Name: "Test", IsActive: true, URL: "http://www.github.com",
PingIntervalSeconds: 1, TimeoutSeconds: 30}
err = s1.CreateSite(db)
if err != nil {
t.Fatal("Failed to create new site:", err)
}
// For this test will pass the normal GetSites to use the DB...
pinger.ResetHitCount()
p := pinger.NewPinger(db, pinger.GetSites, pinger.RequestURLMock,
notifier.SendEmailMock, notifier.SendSmsMock)
p.Start()
// Sleep to allow running the tests before stopping.
time.Sleep(7 * time.Second)
p.Stop()
// Get the site pings since the test began and validate.
var saved database.Site
err = saved.GetSitePings(db, s1.SiteID, time.Now().Add(-10*time.Second), time.Now())
if err != nil {
t.Fatal("Failed to retrieve site pings:", err)
}
if !saved.Pings[0].SiteDown {
t.Error("First ping should show site down.")
}
if saved.Pings[3].SiteDown {
t.Error("Fourth ping should show site up.")
}
// Get the Site updates to make sure the status changes are being set.
err = saved.GetSite(db, s1.SiteID)
if err != nil {
t.Fatal("Failed to retrieve site updates:", err)
}
if saved.LastStatusChange.IsZero() {
t.Error("Last Status Change time not saved.")
}
if saved.LastPing.IsZero() {
t.Error("Last Ping time not saved.")
}
if !saved.IsSiteUp {
t.Error("Site should be saved as up.")
}
}
示例7: editGet
func (controller *sitesController) editGet(rw http.ResponseWriter, req *http.Request) (int, error) {
vars := mux.Vars(req)
siteID, err := strconv.ParseInt(vars["siteID"], 10, 64)
if err != nil {
return http.StatusInternalServerError, err
}
// Get the site to edit
site := new(database.Site)
err = site.GetSite(controller.DB, siteID)
if err != nil {
return http.StatusInternalServerError, err
}
// Get all of the contacts to display in the table.
var contacts database.Contacts
err = contacts.GetContacts(controller.DB)
if err != nil {
return http.StatusInternalServerError, err
}
// Also get the site contacts to display in a table.
err = site.GetSiteContacts(controller.DB, siteID)
if err != nil {
return http.StatusInternalServerError, err
}
selectedContacts := []int64{}
for _, contact := range site.Contacts {
selectedContacts = append(selectedContacts, contact.ContactID)
}
isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer)
siteEdit := new(viewmodels.SitesEditViewModel)
viewmodels.MapSiteDBtoVM(site, siteEdit)
siteEdit.SelectedContacts = selectedContacts
vm := viewmodels.EditSiteViewModel(siteEdit, contacts, isAuthenticated, user, make(map[string]string))
vm.CsrfField = csrf.TemplateField(req)
return http.StatusOK, controller.editTemplate.Execute(rw, vm)
}
示例8: getDetails
func (controller *sitesController) getDetails(rw http.ResponseWriter, req *http.Request) (int, error) {
vars := mux.Vars(req)
siteID, err := strconv.ParseInt(vars["siteID"], 10, 64)
if err != nil {
return http.StatusInternalServerError, err
}
site := new(database.Site)
err = site.GetSite(controller.DB, siteID)
if err != nil {
return http.StatusInternalServerError, err
}
// Also get the contacts to display in a table.
err = site.GetSiteContacts(controller.DB, siteID)
if err != nil {
return http.StatusInternalServerError, err
}
isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer)
vm := viewmodels.GetSiteDetailsViewModel(site, isAuthenticated, user)
return http.StatusOK, controller.detailsTemplate.Execute(rw, vm)
}
示例9: MapSiteVMtoDB
// MapSiteVMtoDB maps the site view model properties to the site database properties.
func MapSiteVMtoDB(siteVM *SitesEditViewModel, site *database.Site) error {
site.SiteID = siteVM.SiteID
site.Name = siteVM.Name
site.IsActive = siteVM.IsActive
site.URL = strings.TrimSpace(siteVM.URL)
site.ContentExpected = strings.TrimSpace(siteVM.ContentExpected)
site.ContentUnexpected = strings.TrimSpace(siteVM.ContentUnexpected)
// Conversion on these two is necessary because they are a string in the
// view model to allow the validation to work
pingInterval, err := strconv.Atoi(siteVM.PingIntervalSeconds)
if err != nil {
return err
}
site.PingIntervalSeconds = pingInterval
timeout, err := strconv.Atoi(siteVM.TimeoutSeconds)
if err != nil {
return err
}
site.TimeoutSeconds = timeout
return nil
}
示例10: TestGetSites
// TestGetSites tests the database retrieval of the list of sites.
func TestGetSites(t *testing.T) {
var sites database.Sites
db, err := database.InitializeTestDB("")
if err != nil {
t.Fatal("Failed to create database:", err)
}
defer db.Close()
s1 := database.Site{Name: "Test", IsActive: true, URL: "http://www.test.com",
PingIntervalSeconds: 1, TimeoutSeconds: 30}
err = s1.CreateSite(db)
if err != nil {
t.Fatal("Failed to create new site:", err)
}
// Create the second site.
s2 := database.Site{Name: "Test 2", IsActive: true, URL: "http://www.example.com",
PingIntervalSeconds: 1, TimeoutSeconds: 30}
err = s2.CreateSite(db)
if err != nil {
t.Fatal("Failed to create second site:", err)
}
sites, err = pinger.GetSites(db)
if err != nil {
t.Fatal("Failed to get sites:", err)
}
// Verify the first site was Loaded with proper attributes.
if !database.CompareSites(s1, sites[0]) {
t.Error("First saved site not equal to input:\n", sites[0], s1)
}
// Verify the second site was Loaded with proper attributes.
if !database.CompareSites(s2, sites[1]) {
t.Error("Second saved site not equal to input:\n", sites[1], s2)
}
}
示例11: GetSitesMock
// GetSitesMock is a mock of the SQL query to get the sites for pinging
func GetSitesMock(db *sql.DB) (database.Sites, error) {
var sites database.Sites
// Create the first site.
s1 := database.Site{Name: "Test", IsActive: true, URL: "http://www.google.com",
PingIntervalSeconds: 1, TimeoutSeconds: 1, IsSiteUp: true}
// Create the second site.
s2 := database.Site{Name: "Test 2", IsActive: true, URL: "http://www.github.com",
PingIntervalSeconds: 2, TimeoutSeconds: 2, IsSiteUp: true}
// Create the third site as not active.
s3 := database.Site{Name: "Test 3", IsActive: false, URL: "http://www.test.com",
PingIntervalSeconds: 2, TimeoutSeconds: 2}
// Contacts are deliberately set as false for SmsActive and EmailActive so as not to trigger Notifier
c1 := database.Contact{Name: "Joe Contact", EmailAddress: "[email protected]", SmsNumber: "5125551212",
SmsActive: false, EmailActive: false}
c2 := database.Contact{Name: "Jack Contact", EmailAddress: "[email protected]", SmsNumber: "5125551213",
SmsActive: false, EmailActive: false}
// Add the contacts to the sites
s1.Contacts = append(s1.Contacts, c1, c2)
s2.Contacts = append(s2.Contacts, c1)
s3.Contacts = append(s3.Contacts, c1)
sites = append(sites, s1, s2, s3)
return sites, nil
}
示例12: TestCreatePings
// TestCreatePings tests creating the ping records for a given site.
func TestCreatePings(t *testing.T) {
var err error
db, err := database.InitializeTestDB("")
defer db.Close()
if err != nil {
t.Fatal("Failed to create database:", err)
}
// First create a site to associate with the pings.
s := database.Site{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)
}
// Create a ping result
p1 := database.Ping{SiteID: s.SiteID, TimeRequest: time.Date(2015, time.November, 10, 23, 22, 22, 00, time.UTC),
Duration: 280, HTTPStatusCode: 200, SiteDown: false}
err = p1.CreatePing(db)
if err != nil {
t.Fatal("Failed to create new ping:", err)
}
// Create a second ping result
p2 := database.Ping{SiteID: s.SiteID, TimeRequest: time.Date(2015, time.November, 10, 23, 22, 20, 00, time.UTC),
Duration: 290, HTTPStatusCode: 200, SiteDown: true}
err = p2.CreatePing(db)
if err != nil {
t.Fatal("Failed to create new ping:", err)
}
//Get the saved Ping
var saved database.Site
err = saved.GetSitePings(db, s.SiteID, time.Date(2015, time.November, 10, 23, 00, 00, 00, time.UTC),
time.Date(2015, time.November, 10, 23, 59, 00, 00, time.UTC))
if err != nil {
t.Fatal("Failed to retrieve saved pings:", err)
}
// Verify the first ping was Loaded with proper attibutes and sorted last.
if !reflect.DeepEqual(p1, saved.Pings[1]) {
t.Error("First saved ping not equal to input:\n", saved.Pings[1], p1)
}
// Verify the second ping was Loaded with proper attributes and sorted first.
if !reflect.DeepEqual(p2, saved.Pings[0]) {
t.Error("Second saved ping not equal to input:\n", saved.Pings[0], p2)
}
// Verify that the site reflects the last ping time.
err = saved.GetSite(db, s.SiteID)
if err != nil {
t.Fatal("Failed to retrieve site:", err)
}
if saved.LastPing != p2.TimeRequest {
t.Error("Last Ping on site does not match input:\n", saved.LastPing, p1.TimeRequest)
}
//Get the first ping for the site.
firstping, err := s.GetFirstPing(db)
if err != nil {
t.Fatal("Failed to retrieve first ping for the site:", err)
}
if firstping != p2.TimeRequest {
t.Error("First Ping on site does not match input:\n", firstping, p2.TimeRequest)
}
// Create a third ping with conflicting times should error.
p3 := database.Ping{SiteID: s.SiteID, TimeRequest: time.Date(2015, time.November, 10, 23, 22, 20, 00, time.UTC),
Duration: 300, HTTPStatusCode: 200, SiteDown: false}
err = p3.CreatePing(db)
if err == nil {
t.Fatal("Conflicting pings should throw error.")
}
}
示例13: editPost
func (controller *sitesController) editPost(rw http.ResponseWriter, req *http.Request) (int, error) {
err := req.ParseForm()
if err != nil {
return http.StatusInternalServerError, err
}
decoder := schema.NewDecoder()
// Ignore unknown keys to prevent errors from the CSRF token.
decoder.IgnoreUnknownKeys(true)
formSite := new(viewmodels.SitesEditViewModel)
err = decoder.Decode(formSite, req.PostForm)
if err != nil {
return http.StatusInternalServerError, err
}
valErrors := validateSiteForm(formSite)
if len(valErrors) > 0 {
isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer)
var contacts database.Contacts
err = contacts.GetContacts(controller.DB)
if err != nil {
return http.StatusInternalServerError, err
}
vm := viewmodels.EditSiteViewModel(formSite, contacts, isAuthenticated, user, valErrors)
vm.CsrfField = csrf.TemplateField(req)
return http.StatusOK, controller.editTemplate.Execute(rw, vm)
}
// Get the site to edit
site := new(database.Site)
err = site.GetSite(controller.DB, formSite.SiteID)
if err != nil {
return http.StatusInternalServerError, err
}
err = viewmodels.MapSiteVMtoDB(formSite, site)
if err != nil {
return http.StatusInternalServerError, err
}
err = site.UpdateSite(controller.DB)
if err != nil {
return http.StatusInternalServerError, err
}
//Loop selected ones first and if it's not already in the site then add it.
for _, contactSelID := range formSite.SelectedContacts {
if !int64InSlice(int64(contactSelID), formSite.SiteContacts) {
err = site.AddContactToSite(controller.DB, contactSelID)
if err != nil {
return http.StatusInternalServerError, err
}
}
}
// Loop existing site contacts and if it's not in the selected items then remove it.
for _, contactSiteID := range formSite.SiteContacts {
if !int64InSlice(int64(contactSiteID), formSite.SelectedContacts) {
err = site.RemoveContactFromSite(controller.DB, contactSiteID)
if err != nil {
return http.StatusInternalServerError, err
}
}
}
// Refresh the pinger with the changes.
err = controller.pinger.UpdateSiteSettings()
if err != nil {
return http.StatusInternalServerError, err
}
http.Redirect(rw, req, "/settings", http.StatusSeeOther)
return http.StatusSeeOther, nil
}
示例14: ping
// ping does the actual pinging of the site and calls the notifications
func ping(s database.Site, db *sql.DB, requestURL URLRequester,
sendEmail notifier.EmailSender, sendSms notifier.SmsSender, wg *sync.WaitGroup, stop chan struct{}) {
defer wg.Done()
// Initialize the previous state of site to the database value. On site creation will initialize to true.
siteWasUp := s.IsSiteUp
var statusChange bool
var partialDetails string
var partialSubject string
for {
// initialize statusChange to false and only notify on change of siteWasUp status
statusChange = false
// Check for a quit signal to stop the pinging
select {
case <-stop:
log.Println("Stopping ", s.Name)
return
case <-time.After(time.Duration(s.PingIntervalSeconds) * time.Second):
// Do nothing
}
if !s.IsActive {
log.Println(s.Name, "Paused")
continue
}
bodyContent, statusCode, responseTime, err := requestURL(s.URL, s.TimeoutSeconds)
log.Println(s.Name, "Pinged")
// Setup ping information for recording.
p := database.Ping{SiteID: s.SiteID, TimeRequest: time.Now()}
if err != nil {
// Check if the error is due to the Internet not being Accessible
if _, ok := err.(InternetAccessError); ok {
log.Println(s.Name, "Unable to determine site status -", err)
continue
}
log.Println(s.Name, "Error", err)
if siteWasUp {
statusChange = true
partialSubject = "Site is Down"
partialDetails = "Site is down, Error is " + err.Error()
}
siteWasUp = false
} else if statusCode < 200 || statusCode > 299 { // Check if the status code is in the 2xx range.
log.Println(s.Name, "Error - HTTP Status Code is", statusCode)
if siteWasUp {
statusChange = true
partialSubject = "Site is Down"
partialDetails = "Site is down, HTTP Status Code is " + strconv.Itoa(statusCode) + "."
}
siteWasUp = false
} else {
siteUp := true
// if the site settings require check the content.
if siteUp && s.ContentExpected != "" && !strings.Contains(bodyContent, s.ContentExpected) {
siteUp = false
log.Println(s.Name, "Error - required body content missing: ", s.ContentExpected)
if siteWasUp {
statusChange = true
partialSubject = "Site is Down"
partialDetails = "Site is Down, required body content missing: " + s.ContentExpected + "."
}
}
if siteUp && s.ContentUnexpected != "" && strings.Contains(bodyContent, s.ContentUnexpected) {
siteUp = false
log.Println(s.Name, "Error - body content content has excluded content: ", s.ContentUnexpected)
if siteWasUp {
statusChange = true
partialSubject = "Site is Down"
partialDetails = "Site is Down, body content content has excluded content: " + s.ContentUnexpected + "."
}
}
if siteUp && !siteWasUp {
statusChange = true
partialSubject = "Site is Up"
partialDetails = fmt.Sprintf("Site is now up, response time was %v.", responseTime)
siteWasUp = true
}
siteWasUp = siteUp
}
// Save the ping details
p.Duration = int(responseTime.Nanoseconds() / 1e6)
p.HTTPStatusCode = statusCode
p.SiteDown = !siteWasUp
// Save ping to db.
err = p.CreatePing(db)
if err != nil {
log.Println("Error saving to ping to db:", err)
}
// Do the notifications if applicable
if statusChange {
// Update the site Status
err = s.UpdateSiteStatus(db, siteWasUp)
if err != nil {
log.Println("Error updating site status:", err)
}
// Do the notifications if applicable
subject := s.Name + ": " + partialSubject
details := s.Name + " at " + s.URL + ": " + partialDetails
log.Println("Will notify status change for", s.Name+":", details)
//.........这里部分代码省略.........
示例15: TestCreateAndGetMultipleSites
// TestCreateAndGetMultipleSites tests creating more than one active sites
// with contacts in the database and then retrieving them.
func TestCreateAndGetMultipleSites(t *testing.T) {
var err error
db, err := database.InitializeTestDB("")
if err != nil {
t.Fatal("Failed to create database:", err)
}
defer db.Close()
// Create the first site.
s1 := database.Site{Name: "Test", IsActive: true, URL: "http://www.google.com",
PingIntervalSeconds: 60, TimeoutSeconds: 30, ContentExpected: "Expected 1",
ContentUnexpected: "Unexpected 1"}
err = s1.CreateSite(db)
if err != nil {
t.Fatal("Failed to create first site:", err)
}
// Create the second site.
s2 := database.Site{Name: "Test 2", IsActive: true, URL: "http://www.test.com",
PingIntervalSeconds: 60, TimeoutSeconds: 30,
LastStatusChange: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
LastPing: time.Date(2009, time.November, 10, 23, 0, 0, 0, time.UTC),
ContentExpected: "Expected 2", ContentUnexpected: "Unexpected 2"}
err = s2.CreateSite(db)
if err != nil {
t.Fatal("Failed to create second site:", err)
}
// Create a third site that is marked inactive.
s3 := database.Site{Name: "Test 3", IsActive: false, URL: "http://www.test3.com",
PingIntervalSeconds: 60, TimeoutSeconds: 30, ContentExpected: "Expected 3",
ContentUnexpected: "Unexpected 3"}
err = s3.CreateSite(db)
if err != nil {
t.Fatal("Failed to create third site:", err)
}
// Create first contact
c1 := database.Contact{Name: "Joe Contact", EmailAddress: "[email protected]", SmsNumber: "5125551212",
SmsActive: false, EmailActive: false}
err = c1.CreateContact(db)
if err != nil {
t.Fatal("Failed to create new contact:", err)
}
// Associate to the first and second site ID
err = s1.AddContactToSite(db, c1.ContactID)
if err != nil {
t.Fatal("Failed to associate contact 1 with first site:", err)
}
err = s2.AddContactToSite(db, c1.ContactID)
if err != nil {
t.Fatal("Failed to associate contact 1 with second site:", err)
}
// Create second contact
c2 := database.Contact{Name: "Jack Contact", EmailAddress: "[email protected]", SmsNumber: "5125551213",
SmsActive: false, EmailActive: false}
err = c2.CreateContact(db)
if err != nil {
t.Fatal("Failed to create new contact:", err)
}
// Associate only to the first site
err = s1.AddContactToSite(db, c2.ContactID)
if err != nil {
t.Fatal("Failed to associate contact 1 with first site:", err)
}
var sites database.Sites
// Get active sites with contacts
err = sites.GetSites(db, true, true)
if err != nil {
t.Fatal("Failed to get all the sites.", err)
}
// Verify that there are only two active sites.
if len(sites) != 2 {
t.Fatal("There should only be two active sites loaded.")
}
// Verify the first site was Loaded with proper attributes.
if !database.CompareSites(s1, sites[0]) {
t.Fatal("First saved site not equal to input:\n", sites[0], s1)
}
// Verify the second site was Loaded with proper attributes.
if !database.CompareSites(s2, sites[1]) {
t.Fatal("Second saved site not equal to input:\n", sites[1], s2)
}
// Verify the first contact was Loaded with proper attributes and sorted last.
if !reflect.DeepEqual(c1, sites[0].Contacts[1]) {
t.Error("Second saved contact not equal to input:\n", sites[0].Contacts[1], c1)
}
// Verify the second contact was loaded with the proper attributes and sorted first.
if !reflect.DeepEqual(c2, sites[0].Contacts[0]) {
t.Error("First saved contact not equal to input:\n", sites[0].Contacts[0], c2)
}
// Verify the first contact was loaded to the second site.
//.........这里部分代码省略.........