Esempio n. 1
0
func TestTimerStop(t *testing.T) {
	t.Parallel()
	project := data.CreateProject("Test 3")
	timer := data.CreateTimer(project)
	if *timer.Started == 0 || *timer.Started < 0 {
		t.Error("timer Started should be greater then 0")
	}

	// timer to test actual duration stored in entry
	counter := time.After(time.Second)

	// create entry to pass into timer
	e := project.CreateEntry("Working on some stuff", true)

	// wait for second and then stop
	<-counter
	if err := timer.Stop(e); err != nil {
		t.Error(err.Error())
	}
	if time.Duration(e.GetDuration()) < time.Second {
		t.Errorf(
			"entry duration should: %v > %v",
			time.Duration(e.GetDuration()), time.Second,
		)
	}
	started, _ := e.StartedTime()
	ended, _ := e.EndedTime()
	if started.Sub(*ended) == time.Duration(e.GetDuration()) {
		t.Errorf(
			"entry duration should be correct. %v",
			e.GetDuration(),
		)
	}
	os.RemoveAll(data.DB.ProjectDirPath(project))
}
Esempio n. 2
0
func TestProjectCreation(t *testing.T) {
	t.Parallel()
	project := data.CreateProject("Test 1")
	project.Company = proto.String("Insight Methods, Inc.")
	if err := data.Save(project); err != nil {
		t.Error(err.Error())
	}
}
Esempio n. 3
0
func moveProjectOrEntry(project *data.Project) (err error) {
	newProject := data.CreateProject(newName)
	if err = data.Save(newProject); err != nil {
		return err
	}

	if theIdx < 0 {
		return moveProject(project, newProject)
	}

	return moveEntry(project, newProject)
}
Esempio n. 4
0
func TestTimerCreation(t *testing.T) {
	t.Parallel()
	project := data.CreateProject("Test 2")
	timer := data.CreateTimer(project)
	<-time.After(time.Microsecond)
	if *timer.Started == 0 || *timer.Started < 0 {
		t.Error("timer Started should be greater then 0")
	}
	if err := data.Save(timer); err != nil {
		t.Error(err.Error())
	}
	os.RemoveAll(data.DB.ProjectDirPath(project))
}
Esempio n. 5
0
File: main.go Progetto: DrGo/samay
func main() {
	parseFlags()
	project := data.CreateProject(name)
	// fmt.Println("Running...", cmd)
	fn := commands[cmd]
	if fn != nil {
		err := fn(project)
		if err != nil {
			log.Fatalln(err)
		}
	} else {
		usage()
	}
}
Esempio n. 6
0
func TestTimerLoad(t *testing.T) {
	t.Parallel()
	project := data.CreateProject("Test 4")
	timer := data.CreateTimer(project)

	<-time.After(time.Second)
	if err := data.Save(timer); err != nil {
		t.Error(err.Error())
	}

	<-time.After(10 * time.Millisecond)
	timer2 := data.GetTimer(project)
	if timer2.GetStarted() != timer.GetStarted() {
		t.Fail()
	}
	os.RemoveAll(data.DB.ProjectDirPath(project))
}