func TestInit(t *testing.T) { os.Remove(dbpath) db := log.NewRelDB(dbpath) defer os.Remove(dbpath) records := []log.TimeRecord{} r1 := log.NewTimeRecord() r1.Duration = time.Duration(15) * time.Minute r1.DurationString = r1.Duration.String() r1.Project = "Project One" r1.Notes = "All my Notes" r1.Tags = append(r1.Tags, "Hello") r1.Tags = append(r1.Tags, "World") records = append(records, r1) r2 := log.NewTimeRecord() r2.Duration = time.Duration(3) * time.Hour r2.DurationString = r2.Duration.String() r2.Project = "Project Two" r2.Notes = "Other Notes" r2.Tags = append(r2.Tags, "Goodbye") r2.Tags = append(r2.Tags, "World") records = append(records, r2) err := db.SaveRecords(records) if err != nil { t.Error(err) } res := db.GetRecords() if len(res) != len(records) { t.Fail() } for _, rec := range res { t.Log(rec) } }
func Test(t *testing.T) { date, err := time.Parse("2006-01-02", "2014-10-10") if err != nil { t.Errorf("error parsing date") } begin, err := time.Parse("15:04", "11:30") if err != nil { t.Errorf("error parsing begin time") } end, err := time.Parse("15:04", "12:45") if err != nil { t.Errorf("error parsing end time") } rec := log.NewTimeRecord() rec.Begin = begin rec.SetEnd(end) rec.SetDate(date) rec.Project = "TestProj" rec.Notes = "Test Notes" rec.Tags = append(rec.Tags, "Tag1") rec.Tags = append(rec.Tags, "Tag2") if rec.Begin.Year() != 2014 { t.Errorf("%s\n", rec) } if rec.Begin.Month() != time.October { t.Errorf("%s\n", rec) } if rec.Begin.Day() != 10 { t.Errorf("%s\n", rec) } if rec.DurationString != "1h15m0s" { t.Errorf("%s\n", rec) } if rec.String() != "2014-10-10 11:30 1h15m0s (TestProj) Test Notes ##[Tag1 Tag2]##" { t.Errorf(rec.String()) } }