Ejemplo n.º 1
0
func (controller *reportsController) get(rw http.ResponseWriter, req *http.Request) (int, error) {
	// Get the YTD reports from the database
	ytdReport, err := database.GetYTDReports(controller.DB)
	if err != nil {
		return http.StatusInternalServerError, err
	}
	isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer)
	messages := controller.authorizer.Messages(rw, req)
	vm := viewmodels.GetReportViewModel(ytdReport, isAuthenticated, user, messages)
	controller.template.Execute(rw, vm)
	return http.StatusOK, nil
}
// TestReports verifies the reading of the report from the DB.
func TestReport(t *testing.T) {
	db, err := database.InitializeReportDB()
	if err != nil {
		t.Fatal("Failed to create database:", err)
	}
	defer db.Close()
	report, err := database.GetYTDReports(db)
	if err != nil {
		t.Fatal("Failed to get report:", err)
	}
	site := "Example.com"
	if report[site][0].PingsUp != 2875 {
		t.Errorf("PingsUp should be 2875, got %d", report[site][0].PingsUp)
	}
	if report[site][0].PingsDown != 0 {
		t.Errorf("PingsDown should be 0, got %d", report[site][0].PingsDown)
	}
	if math.Abs(report[site][0].AvgResponse-37.397565) > .00001 {
		t.Errorf("AvgResponse should be 37.397565, got %f", report[site][0].AvgResponse)
	}
}